summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>1999-02-25 23:45:42 +0000
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>1999-02-25 23:45:42 +0000
commit71caadc045ef9387efaa189404bba29d083a1771 (patch)
tree5f11cf1c6b61122849435f2ab564e45e67595e64
parente3e7d1c2029a646e0edad36cc7d3ad64dcab82bd (diff)
downloadgcc-71caadc045ef9387efaa189404bba29d083a1771.tar.gz
Flow rewrite to use basic block structures and edge lists.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@25450 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog153
-rw-r--r--gcc/basic-block.h101
-rw-r--r--gcc/combine.c10
-rw-r--r--gcc/emit-rtl.c19
-rw-r--r--gcc/except.c10
-rw-r--r--gcc/flow.c2805
-rw-r--r--gcc/function.c231
-rw-r--r--gcc/function.h1
-rw-r--r--gcc/global.c41
-rw-r--r--gcc/graph.c85
-rw-r--r--gcc/haifa-sched.c37
-rw-r--r--gcc/jump.c18
-rw-r--r--gcc/local-alloc.c5
-rw-r--r--gcc/print-rtl.c10
-rw-r--r--gcc/reg-stack.c21
-rw-r--r--gcc/regclass.c7
-rw-r--r--gcc/regmove.c2
-rw-r--r--gcc/reload1.c12
-rw-r--r--gcc/resource.c2
-rw-r--r--gcc/rtl.c3
-rw-r--r--gcc/rtl.h11
-rw-r--r--gcc/sched.c2
-rw-r--r--gcc/stmt.c22
-rw-r--r--gcc/toplev.c52
-rw-r--r--gcc/unroll.c7
-rw-r--r--gcc/varray.h7
26 files changed, 2485 insertions, 1189 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index aaedc35ff7e..69d04970bb3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,156 @@
+Thu Feb 25 23:43:59 1999 Richard Henderson <rth@cygnus.com>
+
+ Flow rewrite to use basic block structures and edge lists:
+
+ * basic-block.h (x_basic_block_head, x_basic_block_end): Kill.
+ (basic_block_computed_jump_target, basic_block_live_at_start): Kill.
+ (struct edge_def): New.
+ (struct basic_block_def): New.
+ (basic_block_info): New.
+ (BLOCK_HEAD, BLOCK_END): Update.
+ (ENTRY_BLOCK_PTR, EXIT_BLOCK_PTR): New.
+ (uid_block_number): Kill.
+ (basic_block_for_insn, BLOCK_FOR_INSN): New.
+ (BLOCK_NUM): Update.
+ * flow.c (XNMALLOC): Kill.
+ (max_uid_for_flow): Kill.
+ (uid_block_number): Kill.
+ (uid_volatile): Turn into a bitmap.
+ (SET_INSN_VOLATILE): New.
+ (basic_block_info): New.
+ (entry_exit_blocks): New.
+ (x_basic_block_head, x_basic_block_end): Kill.
+ (basic_block_computed_jump_target, basic_block_live_at_start): Kill.
+ (flow_int_list_blocks, basic_block_succ, basic_block_pred): Kill.
+ (basic_block_loop_depth): Kill.
+ (basic_block_for_insn): New.
+ (find_basic_blocks): Split out initial block counting into
+ count_basic_blocks. Call functions split out of find_basic_blocks_1.
+ (count_basic_blocks): New.
+ (find_basic_blocks_1): Split out edge recognition, unreachable
+ block deletion.
+ (create_basic_block): New.
+ (compute_bb_for_insn): New.
+ (clear_edges): New.
+ (free_bb_memory): Kill.
+ (add_edge, add_edge_to_label): Kill.
+ (mark_label_ref): Kill.
+ (make_edges): Rewrite to use edge lists.
+ (make_edge, make_label_edge): New.
+ (mark_critical_edges): New.
+ (split_edge, insert_insn_on_edge): New.
+ (commit_one_edge_insertion, commit_edge_insertions): New.
+ (delete_unreachable_blocks): Rewrite to use edge lists.
+ Split out EH region manipulation into delete_eh_regions.
+ Call tidy_fallthru_edge and merge_blocks.
+ (delete_eh_regions): New.
+ (delete_note_p): New.
+ (delete_insn_chain): New.
+ (delete_block): Split out code into delete_insn_chain and
+ tidy_fallthru_edge. Update edge lists.
+ (expunge_block): New.
+ (flow_delete_insn): New?
+ (can_delete_label_p): New?
+ (merge_blocks_nomove, merge_blocks): New.
+ (tidy_fallthru_edge): New.
+ (calculate_loop_depth): New.
+ (life_analysis): Allocate and free uid_volatile.
+ (free_basic_block_vars): Update for new structures.
+ (record_volatile_insns): Use SET_INSN_VOLATILE.
+ (mark_regs_live_at_end): Tidy EXIT_IGNORE_STACK usage.
+ (mark_used_regs): Likewise.
+ (life_analysis_1): Use bb global_live_at_start, global_live_at_end,
+ local_set regsets. Use bb->aux to store new_live_at_end. Begin
+ life propagation from EXIT_BLOCK rather than last block. Clear
+ regs_ever_live after mark_regs_live_at_end.
+ (allocate_for_life_analysis): Update for new structures.
+ (propagate_block): Split out loop depth calculation to
+ calculate_loop_depth.
+ (regno_uninitialized): Use bb->global_live_at_start.
+ (regno_clobbered_at_setjmp): Likewise.
+ (dump_bb_data): Likewise.
+ (find_auto_inc): Use BLOCK_FOR_INSN instead of BLOCK_NUM.
+ (dump_flow_info): Update for new structures.
+ (dump_edge_info): New.
+ (print_rtl_with_bb): Update for new structues.
+ (compute_preds_succs): Do no work -- convert edge lists.
+ (set_block_for_insn): From corpse of old set_block_num.
+ (set_block_num): Call it.
+
+ * rtl.c (note_insn_name): Add NOTE_INSN_BASIC_BLOCK.
+ * rtl.h (rtunion_def): Add bb entry.
+ (NOTE_BASIC_BLOCK): New.
+ (NOTE_INSN_BASIC_BLOCK): New.
+
+ * varray.h (varray_data_tag): Add bb entry.
+ (VARRAY_BB_INIT, VARRAY_BB): New.
+
+ * emit-rtl.c (emit_label_before): New.
+
+ * except.c (expand_rethrow): Delete insns following the call to
+ rethrow. Put the REG_EH_RETHROW on the call.
+
+ * jump.c (returnjump_p, returnjump_p_1): New.
+
+ * expr.h (nonlocal_goto_handler_labels): New declaration.
+ * function.c (nonlocal_goto_handler_labels): Define it.
+ (push_function_context_to): Save it.
+ (pop_function_context_from): Restore it.
+ (init_function_start): Clear it.
+ (nonlocal_label_rtx_list): Kill.
+ * function.h (struct function): Add storage space for it.
+ * stmt.c (expand_nl_handler_label): Return the new label.
+ (expand_nl_goto_receivers): Collect a list of them in
+ nonlocal_goto_handler_labels.
+
+ * Makefile.in (print-rtl.o): Depend on basic-block.h.
+ (flow.o): Depend on tree.h and insn-flags.h.
+ (sched.o): Depend on tree.h and expr.h.
+
+ * function.c (thread_prologue_and_epilogue_insns): Do not
+ half-heartedly update bb structures.
+
+ * toplev.c: Add flow2 dump as -dw.
+ (rest_of_compilation): Finish .greg before flow2.
+
+ * graph.c (draw_edge): Handle class 3.
+ (print_rtl_graph_with_bb): Make abnormal edges red class 2,
+ change non-fall-thru but adjacent to green class 3. Update
+ to use new structures.
+
+ * print-rtl.c (print_rtx): Handle NOTE_INSN_BASIC_BLOCK.
+
+ * reg-stack.c (BLOCK_NUM): Convert to function. Abort if
+ block_number is -1.
+ (reg_to_stack): Initialize block_num to -1.
+
+ * combine.c (set_nonzero_bits_and_sign_copies): Update reference
+ to basic_block_live_at_start to bb->global_live_at_start.
+ (try_combine): Likewise.
+ (reg_dead_at_p): Likewise.
+ * global.c (global_conflicts): Likewise.
+ Handle stack regs on all abnormal edges, not just computed jumps.
+ (mark_elimination): Update reference to basic_block_live_at_start.
+ (build_insn_chain): Likewise.
+ * haifa-sched.c (haifa_edge): Rename from edge for conflict.
+ (is_cfg_nonregular): Look at nonlocal_goto_handler_labels instead
+ of nonlocal_label_rtx_list.
+ (check_live_1): Update reference to basic_block_live_at_start.
+ (update_live_1): Likewise.
+ (find_pre_sched_live): Likewise.
+ (find_post_sched_live): Likewise.
+ * local-alloc.c (update_equiv_regs): Likewise.
+ (block_alloc): Likewise.
+ * reload1.c (reload, reload_combine): Likewise.
+ * regmove.c (mark_flags_life_zones): Likewise.
+ * resource.c (mark_target_live_regs): Likewise.
+ * sched.c (schedule_block): Likewise.
+
+ * regclass.c (regset_release_memory): Don't free
+ basic_block_live_at_start.
+
+ * unroll.c (copy_loop_body): Don't duplicate NOTE_INSN_BASIC_BLOCK.
+
Thu Feb 25 21:32:34 1999 Jason Merrill <jason@yorick.cygnus.com>
* fixinc.wrap: Also handle struct queue in sys/stream.h.
diff --git a/gcc/basic-block.h b/gcc/basic-block.h
index d54ffe8b26c..2052b8c42ae 100644
--- a/gcc/basic-block.h
+++ b/gcc/basic-block.h
@@ -21,6 +21,7 @@ Boston, MA 02111-1307, USA. */
#include "bitmap.h"
#include "sbitmap.h"
+#include "varray.h"
typedef bitmap regset; /* Head of register set linked list. */
@@ -95,29 +96,65 @@ do { \
/* Grow any tables needed when the number of registers is calculated
or extended. For the linked list allocation, nothing needs to
be done, other than zero the statistics on the first allocation. */
-#define MAX_REGNO_REG_SET(NUM_REGS, NEW_P, RENUMBER_P)
+#define MAX_REGNO_REG_SET(NUM_REGS, NEW_P, RENUMBER_P)
-/* Number of basic blocks in the current function. */
+/* Control flow edge information. */
+typedef struct edge_def {
+ /* Links through the predecessor and successor lists. */
+ struct edge_def *pred_next, *succ_next;
-extern int n_basic_blocks;
+ /* The two blocks at the ends of the edge. */
+ struct basic_block_def *src, *dest;
+
+ /* Instructions queued on the edge. */
+ rtx insns;
+
+ /* Auxiliary info specific to a pass. */
+ void *aux;
-/* Index by basic block number, get first insn in the block. */
+ int flags; /* see EDGE_* below */
+ int probability; /* biased by REG_BR_PROB_BASE */
+} *edge;
-extern rtx *x_basic_block_head;
+#define EDGE_FALLTHRU 1
+#define EDGE_CRITICAL 2
+#define EDGE_ABNORMAL 4
+#define EDGE_ABNORMAL_CALL 8
+#define EDGE_EH 16
+#define EDGE_FAKE 32
-/* Index by basic block number, get last insn in the block. */
-extern rtx *x_basic_block_end;
+/* Basic block information indexed by block number. */
+typedef struct basic_block_def {
+ /* The first and last insns of the block. */
+ rtx head, end;
-/* Index by basic block number, determine whether the block can be reached
- through a computed jump. */
+ /* The edges into and out of the block. */
+ edge pred, succ;
-extern char *basic_block_computed_jump_target;
+ /* Liveness info. */
+ regset local_set;
+ regset global_live_at_start;
+ regset global_live_at_end;
-/* Index by basic block number, get address of regset
- describing the registers live at the start of that block. */
+ /* Auxiliary info specific to a pass. */
+ void *aux;
-extern regset *basic_block_live_at_start;
+ /* The index of this block. */
+ int index;
+ /* The loop depth of this block plus one. */
+ int loop_depth;
+} *basic_block;
+
+/* Number of basic blocks in the current function. */
+
+extern int n_basic_blocks;
+
+/* Index by basic block number, get basic block struct info. */
+
+extern varray_type basic_block_info;
+
+#define BASIC_BLOCK(N) (VARRAY_BB (basic_block_info, (N)))
/* What registers are live at the setjmp call. */
@@ -177,24 +214,38 @@ extern void free_int_list PROTO ((int_list_block **));
/* Stuff for recording basic block info. */
-#define BLOCK_HEAD(B) x_basic_block_head[(B)]
-#define BLOCK_END(B) x_basic_block_end[(B)]
+#define BLOCK_HEAD(B) (BASIC_BLOCK (B)->head)
+#define BLOCK_END(B) (BASIC_BLOCK (B)->end)
/* Special block numbers [markers] for entry and exit. */
#define ENTRY_BLOCK (-1)
#define EXIT_BLOCK (-2)
+/* Similarly, block pointers for the edge list. */
+extern struct basic_block_def entry_exit_blocks[2];
+#define ENTRY_BLOCK_PTR (&entry_exit_blocks[0])
+#define EXIT_BLOCK_PTR (&entry_exit_blocks[1])
+
/* from flow.c */
-extern void free_regset_vector PROTO ((regset *, int nelts));
-extern int *uid_block_number;
-#define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)]
+extern void free_regset_vector PROTO ((regset *, int nelts));
-extern void dump_bb_data PROTO ((FILE *, int_list_ptr *, int_list_ptr *,
- int));
-extern void free_bb_mem PROTO ((void));
+extern varray_type basic_block_for_insn;
+#define BLOCK_FOR_INSN(INSN) VARRAY_BB (basic_block_for_insn, INSN_UID (INSN))
+#define BLOCK_NUM(INSN) (BLOCK_FOR_INSN (INSN)->index + 0)
+
+extern void set_block_for_insn PROTO ((rtx, basic_block));
+
+extern void dump_bb_data PROTO ((FILE *, int_list_ptr *,
+ int_list_ptr *, int));
+extern void free_bb_mem PROTO ((void));
extern void free_basic_block_vars PROTO ((int));
-extern void compute_preds_succs PROTO ((int_list_ptr *, int_list_ptr *,
- int *, int *));
-extern void compute_dominators PROTO ((sbitmap *, sbitmap *,
- int_list_ptr *, int_list_ptr *));
+extern basic_block split_edge PROTO ((edge));
+extern void insert_insn_on_edge PROTO ((rtx, edge));
+extern void commit_edge_insertions PROTO ((void));
+
+extern void compute_preds_succs PROTO ((int_list_ptr *, int_list_ptr *,
+ int *, int *));
+extern void compute_dominators PROTO ((sbitmap *, sbitmap *,
+ int_list_ptr *,
+ int_list_ptr *));
diff --git a/gcc/combine.c b/gcc/combine.c
index 0451707a22d..549e0bf4ed2 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -744,7 +744,7 @@ set_nonzero_bits_and_sign_copies (x, set)
&& REGNO (x) >= FIRST_PSEUDO_REGISTER
/* If this register is undefined at the start of the file, we can't
say what its contents were. */
- && ! REGNO_REG_SET_P (basic_block_live_at_start[0], REGNO (x))
+ && ! REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start, REGNO (x))
&& GET_MODE_BITSIZE (GET_MODE (x)) <= HOST_BITS_PER_WIDE_INT)
{
if (set == 0 || GET_CODE (set) == CLOBBER)
@@ -2490,7 +2490,8 @@ try_combine (i3, i2, i1)
regno = REGNO (i2dest);
REG_N_SETS (regno)--;
if (REG_N_SETS (regno) == 0
- && ! REGNO_REG_SET_P (basic_block_live_at_start[0], regno))
+ && ! REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start,
+ regno))
REG_N_REFS (regno) = 0;
}
}
@@ -2512,7 +2513,8 @@ try_combine (i3, i2, i1)
{
REG_N_SETS (regno)--;
if (REG_N_SETS (regno) == 0
- && ! REGNO_REG_SET_P (basic_block_live_at_start[0], regno))
+ && ! REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start,
+ regno))
REG_N_REFS (regno) = 0;
}
}
@@ -11038,7 +11040,7 @@ reg_dead_at_p (reg, insn)
}
for (i = reg_dead_regno; i < reg_dead_endregno; i++)
- if (REGNO_REG_SET_P (basic_block_live_at_start[block], i))
+ if (REGNO_REG_SET_P (BASIC_BLOCK (block)->global_live_at_start, i))
return 0;
return 1;
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index a761c45745a..c7ff5969f2d 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -2710,7 +2710,7 @@ emit_call_insn_before (pattern, before)
}
/* Make an insn of code BARRIER
- and output it before the insn AFTER. */
+ and output it before the insn BEFORE. */
rtx
emit_barrier_before (before)
@@ -2724,6 +2724,23 @@ emit_barrier_before (before)
return insn;
}
+/* Emit the label LABEL before the insn BEFORE. */
+
+rtx
+emit_label_before (label, before)
+ rtx label, before;
+{
+ /* This can be called twice for the same label as a result of the
+ confusion that follows a syntax error! So make it harmless. */
+ if (INSN_UID (label) == 0)
+ {
+ INSN_UID (label) = cur_insn_uid++;
+ add_insn_before (label, before);
+ }
+
+ return label;
+}
+
/* Emit a note of subtype SUBTYPE before the insn BEFORE. */
rtx
diff --git a/gcc/except.c b/gcc/except.c
index ae8fea178ff..6e126fb631d 100644
--- a/gcc/except.c
+++ b/gcc/except.c
@@ -1967,11 +1967,17 @@ expand_rethrow (label)
label = last_rethrow_symbol;
emit_library_call (rethrow_libfunc, 0, VOIDmode, 1, label, Pmode);
SYMBOL_REF_USED (label) = 1;
+
+ /* Search backwards for the actual call insn. */
insn = get_last_insn ();
- val = GEN_INT (eh_region_from_symbol (label));
+ while (GET_CODE (insn) != CALL_INSN)
+ insn = PREV_INSN (insn);
+ delete_insns_since (insn);
+
/* Mark the label/symbol on the call. */
+ val = GEN_INT (eh_region_from_symbol (label));
REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EH_RETHROW, val,
- REG_NOTES (insn));
+ REG_NOTES (insn));
emit_barrier ();
}
else
diff --git a/gcc/flow.c b/gcc/flow.c
index 6b48fa6e728..5b87b396631 100644
--- a/gcc/flow.c
+++ b/gcc/flow.c
@@ -19,14 +19,13 @@ the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-/* This file contains the data flow analysis pass of the compiler.
- It computes data flow information
- which tells combine_instructions which insns to consider combining
- and controls register allocation.
+/* This file contains the data flow analysis pass of the compiler. It
+ computes data flow information which tells combine_instructions
+ which insns to consider combining and controls register allocation.
- Additional data flow information that is too bulky to record
- is generated during the analysis, and is used at that time to
- create autoincrement and autodecrement addressing.
+ Additional data flow information that is too bulky to record is
+ generated during the analysis, and is used at that time to create
+ autoincrement and autodecrement addressing.
The first step is dividing the function into basic blocks.
find_basic_blocks does this. Then life_analysis determines
@@ -34,13 +33,12 @@ Boston, MA 02111-1307, USA. */
** find_basic_blocks **
- find_basic_blocks divides the current function's rtl
- into basic blocks. It records the beginnings and ends of the
- basic blocks in the vectors basic_block_head and basic_block_end,
- and the number of blocks in n_basic_blocks.
+ find_basic_blocks divides the current function's rtl into basic
+ blocks and constructs the CFG. The blocks are recorded in the
+ basic_block_info array; the CFG exists in the edge structures
+ referenced by the blocks.
- find_basic_blocks also finds any unreachable loops
- and deletes them.
+ find_basic_blocks also finds any unreachable loops and deletes them.
** life_analysis **
@@ -51,12 +49,12 @@ Boston, MA 02111-1307, USA. */
** live-register info **
The information about where each register is live is in two parts:
- the REG_NOTES of insns, and the vector basic_block_live_at_start.
+ the REG_NOTES of insns, and the vector basic_block->global_live_at_start.
- basic_block_live_at_start has an element for each basic block,
- and the element is a bit-vector with a bit for each hard or pseudo
- register. The bit is 1 if the register is live at the beginning
- of the basic block.
+ basic_block->global_live_at_start has an element for each basic
+ block, and the element is a bit-vector with a bit for each hard or
+ pseudo register. The bit is 1 if the register is live at the
+ beginning of the basic block.
Two types of elements can be added to an insn's REG_NOTES.
A REG_DEAD note is added to an insn's REG_NOTES for any register
@@ -110,6 +108,15 @@ Boston, MA 02111-1307, USA. */
life_analysis sets current_function_sp_is_unchanging if the function
doesn't modify the stack pointer. */
+
+/* TODO:
+
+ Split out from life_analysis:
+ - local property discovery (bb->local_live, bb->local_set)
+ - global property computation
+ - log links creation
+ - pre/post modify transformation
+*/
#include "config.h"
#include "system.h"
@@ -123,12 +130,21 @@ Boston, MA 02111-1307, USA. */
#include "except.h"
#include "toplev.h"
#include "recog.h"
+#include "insn-flags.h"
#include "obstack.h"
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
-#define XNMALLOC(TYPE, COUNT) ((TYPE *) xmalloc ((COUNT) * sizeof (TYPE)))
+
+/* EXIT_IGNORE_STACK should be nonzero if, when returning from a function,
+ the stack pointer does not matter. The value is tested only in
+ functions that have frame pointers.
+ No definition is equivalent to always zero. */
+#ifndef EXIT_IGNORE_STACK
+#define EXIT_IGNORE_STACK 0
+#endif
+
/* The contents of the current function definition are allocated
in this obstack, and all are freed at the end of the function.
@@ -140,34 +156,47 @@ extern struct obstack *function_obstack;
/* List of labels that must never be deleted. */
extern rtx forced_labels;
-/* Get the basic block number of an insn.
- This info should not be expected to remain available
- after the end of life_analysis. */
-
-/* This is the limit of the allocated space in the following two arrays. */
-
-static int max_uid_for_flow;
+/* Number of basic blocks in the current function. */
-#define BLOCK_NUM(INSN) uid_block_number[INSN_UID (INSN)]
+int n_basic_blocks;
-/* This is where the BLOCK_NUM values are really stored.
- This is set up by find_basic_blocks and used there and in life_analysis,
- and then freed. */
+/* The basic block array. */
-int *uid_block_number;
+varray_type basic_block_info;
-/* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */
+/* The special entry and exit blocks. */
-#define INSN_VOLATILE(INSN) uid_volatile[INSN_UID (INSN)]
-static char *uid_volatile;
+struct basic_block_def entry_exit_blocks[2] =
+{
+ {
+ NULL, /* head */
+ NULL, /* end */
+ NULL, /* pred */
+ NULL, /* succ */
+ NULL, /* local_set */
+ NULL, /* global_live_at_start */
+ NULL, /* global_live_at_end */
+ NULL, /* aux */
+ ENTRY_BLOCK, /* index */
+ 0 /* loop_depth */
+ },
+ {
+ NULL, /* head */
+ NULL, /* end */
+ NULL, /* pred */
+ NULL, /* succ */
+ NULL, /* local_set */
+ NULL, /* global_live_at_start */
+ NULL, /* global_live_at_end */
+ NULL, /* aux */
+ EXIT_BLOCK, /* index */
+ 0 /* loop_depth */
+ }
+};
/* Nonzero if the second flow pass has completed. */
int flow2_completed;
-/* Number of basic blocks in the current function. */
-
-int n_basic_blocks;
-
/* Maximum register number used in this function, plus one. */
int max_regno;
@@ -192,28 +221,8 @@ static rtx *reg_next_use;
int regset_bytes;
int regset_size;
-/* Element N is first insn in basic block N.
- This info lasts until we finish compiling the function. */
-
-rtx *x_basic_block_head;
-
-/* Element N is last insn in basic block N.
- This info lasts until we finish compiling the function. */
-
-rtx *x_basic_block_end;
-
-/* Element N indicates whether basic block N can be reached through a
- computed jump. */
-
-char *basic_block_computed_jump_target;
-
-/* Element N is a regset describing the registers live
- at the start of basic block N.
- This info lasts until we finish compiling the function. */
-
-regset *basic_block_live_at_start;
-
/* Regset of regs live when calls to `setjmp'-like functions happen. */
+/* ??? Does this exist only for the setjmp-clobbered warning message? */
regset regs_live_at_setjmp;
@@ -223,20 +232,6 @@ regset regs_live_at_setjmp;
are another pair, etc. */
rtx regs_may_share;
-/* Pointer to head of predecessor/successor block list. */
-static int_list_block *flow_int_list_blocks;
-
-/* Element N is the list of successors of basic block N. */
-static int_list_ptr *basic_block_succ;
-
-/* Element N is the list of predecessors of basic block N. */
-static int_list_ptr *basic_block_pred;
-
-/* Element N is depth within loops of the last insn in basic block number N.
- Freed after life_analysis. */
-
-static short *basic_block_loop_depth;
-
/* Depth within loops of basic block being scanned for lifetime analysis,
plus one. This is the weight attached to references to registers. */
@@ -256,21 +251,57 @@ static rtx mem_set_list;
static HARD_REG_SET elim_reg_set;
+/* The basic block structure for every insn, indexed by uid. */
+
+varray_type basic_block_for_insn;
+
+/* The labels mentioned in non-jump rtl. Valid during find_basic_blocks. */
+/* ??? Should probably be using LABEL_NUSES instead. It would take a
+ bit of surgery to be able to use or co-opt the routines in jump. */
+
+static rtx label_value_list;
+
+/* INSN_VOLATILE (insn) is 1 if the insn refers to anything volatile. */
+
+#define INSN_VOLATILE(INSN) bitmap_bit_p (uid_volatile, INSN_UID (INSN))
+#define SET_INSN_VOLATILE(INSN) bitmap_set_bit (uid_volatile, INSN_UID (INSN))
+static bitmap uid_volatile;
+
/* Forward declarations */
-static void find_basic_blocks_1 PROTO((rtx, rtx));
-static void add_edge PROTO((int, int));
-static void add_edge_to_label PROTO((int, rtx));
-static void make_edges PROTO((int));
-static void mark_label_ref PROTO((int, rtx));
+static int count_basic_blocks PROTO((rtx));
+static rtx find_basic_blocks_1 PROTO((rtx, rtx*));
+static void create_basic_block PROTO((int, rtx, rtx, rtx));
+static void compute_bb_for_insn PROTO((varray_type, int));
+static void clear_edges PROTO((void));
+static void make_edges PROTO((rtx, rtx*));
+static void make_edge PROTO((basic_block, basic_block, int));
+static void make_label_edge PROTO((basic_block, rtx, int));
+static void mark_critical_edges PROTO((void));
+
+static void commit_one_edge_insertion PROTO((edge));
+
static void delete_unreachable_blocks PROTO((void));
-static int delete_block PROTO((int));
-static void life_analysis_1 PROTO((rtx, int));
-static void propagate_block PROTO((regset, rtx, rtx, int,
- regset, int));
+static void delete_eh_regions PROTO((void));
+static void delete_insn_chain PROTO((rtx, rtx));
+static int delete_block PROTO((basic_block));
+static void expunge_block PROTO((basic_block));
+static rtx flow_delete_insn PROTO((rtx));
+static int can_delete_label_p PROTO((rtx));
+static void merge_blocks_nomove PROTO((basic_block, basic_block));
+static int merge_blocks PROTO((edge,basic_block,basic_block));
+static void tidy_fallthru_edge PROTO((edge,basic_block,basic_block));
+static void calculate_loop_depth PROTO((rtx));
+
static int set_noop_p PROTO((rtx));
static int noop_move_p PROTO((rtx));
+static void notice_stack_pointer_modification PROTO ((rtx, rtx));
static void record_volatile_insns PROTO((rtx));
static void mark_regs_live_at_end PROTO((regset));
+static void life_analysis_1 PROTO((rtx, int));
+static void init_regset_vector PROTO ((regset *, int,
+ struct obstack *));
+static void propagate_block PROTO((regset, rtx, rtx, int,
+ regset, int));
static int insn_dead_p PROTO((rtx, regset, int, rtx));
static int libcall_dead_p PROTO((rtx, regset, rtx, rtx));
static void mark_set_regs PROTO((regset, regset, rtx,
@@ -284,13 +315,15 @@ static int try_pre_increment PROTO((rtx, rtx, HOST_WIDE_INT));
#endif
static void mark_used_regs PROTO((regset, regset, rtx, int, rtx));
void dump_flow_info PROTO((FILE *));
-static void add_pred_succ PROTO ((int, int, int_list_ptr *,
- int_list_ptr *, int *, int *));
+static void dump_edge_info PROTO((FILE *, edge, int));
+
static int_list_ptr alloc_int_list_node PROTO ((int_list_block **));
static int_list_ptr add_int_list_node PROTO ((int_list_block **,
int_list **, int));
-static void init_regset_vector PROTO ((regset *, int,
- struct obstack *));
+
+static void add_pred_succ PROTO ((int, int, int_list_ptr *,
+ int_list_ptr *, int *, int *));
+
static void count_reg_sets_1 PROTO ((rtx));
static void count_reg_sets PROTO ((rtx));
static void count_reg_references PROTO ((rtx));
@@ -298,560 +331,665 @@ static void notice_stack_pointer_modification PROTO ((rtx, rtx));
static void invalidate_mems_from_autoinc PROTO ((rtx));
/* Find basic blocks of the current function.
- F is the first insn of the function and NREGS the number of register numbers
- in use. */
+ F is the first insn of the function and NREGS the number of register
+ numbers in use. */
void
find_basic_blocks (f, nregs, file)
rtx f;
- int nregs;
- FILE *file;
+ int nregs ATTRIBUTE_UNUSED;
+ FILE *file ATTRIBUTE_UNUSED;
{
- register rtx insn;
- register int i;
- rtx nonlocal_label_list = nonlocal_label_rtx_list ();
+ rtx *bb_eh_end;
+ int max_uid;
- /* Avoid leaking memory if this is called multiple times per compiled
- function. */
- free_bb_memory ();
+ /* Flush out existing data. */
+ if (basic_block_info != NULL)
+ {
+ int i;
- /* Count the basic blocks. Also find maximum insn uid value used. */
+ clear_edges ();
- {
- rtx prev_call = 0;
- register RTX_CODE prev_code = JUMP_INSN;
- register RTX_CODE code;
- int eh_region = 0;
- int call_had_abnormal_edge = 0;
+ /* Clear bb->aux on all extant basic blocks. We'll use this as a
+ tag for reuse during create_basic_block, just in case some pass
+ copies around basic block notes improperly. */
+ for (i = 0; i < n_basic_blocks; ++i)
+ BASIC_BLOCK (i)->aux = NULL;
- for (insn = f, i = 0; insn; insn = NEXT_INSN (insn))
- {
- code = GET_CODE (insn);
-
- /* A basic block starts at label, or after something that can jump. */
- if (code == CODE_LABEL
- || (GET_RTX_CLASS (code) == 'i'
- && (prev_code == JUMP_INSN
- || (prev_code == CALL_INSN && call_had_abnormal_edge)
- || prev_code == BARRIER)))
- {
- i++;
+ VARRAY_FREE (basic_block_info);
+ }
- /* If the previous insn was a call that did not create an
- abnormal edge, we want to add a nop so that the CALL_INSN
- itself is not at basic block end. This allows us to easily
- distinguish between normal calls and those which create
- abnormal edges in the flow graph. */
+ n_basic_blocks = count_basic_blocks (f);
- if (i > 0 && !call_had_abnormal_edge && prev_call != 0)
- {
- rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
- emit_insn_after (nop, prev_call);
- }
- }
+ /* Size the basic block table. The actual structures will be allocated
+ by find_basic_blocks_1, since we want to keep the structure pointers
+ stable across calls to find_basic_blocks. */
+ /* ??? This whole issue would be much simpler if we called find_basic_blocks
+ exactly once, and thereafter we don't have a single long chain of
+ instructions at all until close to the end of compilation when we
+ actually lay them out. */
- if (code == CALL_INSN)
- {
- rtx note = find_reg_note(insn, REG_EH_REGION, NULL_RTX);
-
- /* We change the code of the CALL_INSN, so that it won't start a
- new block. */
- if (note && XINT (XEXP (note, 0), 0) == 0)
- code = INSN;
- else
- {
- prev_call = insn;
- call_had_abnormal_edge = (nonlocal_label_list != 0
- || eh_region);
- }
- }
-
- else if (code != NOTE && code != BARRIER)
- prev_call = 0;
-
- if (code != NOTE)
- prev_code = code;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
- ++eh_region;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
- --eh_region;
- }
- }
+ VARRAY_BB_INIT (basic_block_info, n_basic_blocks, "basic_block_info");
+
+ /* An array to record the active exception region at the end of each
+ basic block. It is filled in by find_basic_blocks_1 for make_edges. */
+ bb_eh_end = (rtx *) alloca (n_basic_blocks * sizeof (rtx));
- n_basic_blocks = i;
+ label_value_list = find_basic_blocks_1 (f, bb_eh_end);
- max_uid_for_flow = get_max_uid ();
+ /* Record the block to which an insn belongs. */
+ /* ??? This should be done another way, by which (perhaps) a label is
+ tagged directly with the basic block that it starts. It is used for
+ more than that currently, but IMO that is the only valid use. */
+
+ max_uid = get_max_uid ();
#ifdef AUTO_INC_DEC
/* Leave space for insns life_analysis makes in some cases for auto-inc.
These cases are rare, so we don't need too much space. */
- max_uid_for_flow += max_uid_for_flow / 10;
+ max_uid += max_uid / 10;
#endif
- /* Allocate some tables that last till end of compiling this function
- and some needed only in find_basic_blocks and life_analysis. */
+ VARRAY_BB_INIT (basic_block_for_insn, max_uid, "basic_block_for_insn");
+ compute_bb_for_insn (basic_block_for_insn, max_uid);
+
+ /* Discover the edges of our cfg. */
+
+ make_edges (label_value_list, bb_eh_end);
- x_basic_block_head = XNMALLOC (rtx, n_basic_blocks);
- x_basic_block_end = XNMALLOC (rtx, n_basic_blocks);
- basic_block_succ = XNMALLOC (int_list_ptr, n_basic_blocks);
- basic_block_pred = XNMALLOC (int_list_ptr, n_basic_blocks);
- bzero ((char *)basic_block_succ, n_basic_blocks * sizeof (int_list_ptr));
- bzero ((char *)basic_block_pred, n_basic_blocks * sizeof (int_list_ptr));
+ /* Delete unreachable blocks. */
+ /* ??? Do this conditionally, or make this another entry point? */
- basic_block_computed_jump_target = (char *) oballoc (n_basic_blocks);
- basic_block_loop_depth = XNMALLOC (short, n_basic_blocks);
- uid_block_number = XNMALLOC (int, (max_uid_for_flow + 1));
- uid_volatile = XNMALLOC (char, (max_uid_for_flow + 1));
- bzero (uid_volatile, max_uid_for_flow + 1);
+ delete_unreachable_blocks ();
- find_basic_blocks_1 (f, nonlocal_label_list);
+ /* Mark critical edges. */
+
+ mark_critical_edges ();
+
+ /* Discover the loop depth at the start of each basic block to aid
+ register allocation. */
+ calculate_loop_depth (f);
+
+ /* Kill the data we won't maintain. */
+ label_value_list = 0;
}
-/* For communication between find_basic_blocks_1 and its subroutines. */
+/* Count the basic blocks of the function. */
-/* An array of CODE_LABELs, indexed by UID for the start of the active
- EH handler for each insn in F. */
-static int *active_eh_region;
-static int *nested_eh_region;
+static int
+count_basic_blocks (f)
+ rtx f;
+{
+ register rtx insn;
+ register RTX_CODE prev_code;
+ register int count = 0;
+ int eh_region = 0;
+ int in_libcall_block = 0;
+ int call_had_abnormal_edge = 0;
+ rtx prev_call = NULL_RTX;
-/* Element N nonzero if basic block N can actually be reached. */
+ prev_code = JUMP_INSN;
+ for (insn = f; insn; insn = NEXT_INSN (insn))
+ {
+ register RTX_CODE code = GET_CODE (insn);
+
+ /* Track when we are inside in LIBCALL block. */
+ if (GET_RTX_CLASS (code) == 'i'
+ && find_reg_note (insn, REG_LIBCALL, NULL_RTX))
+ in_libcall_block = 1;
+
+ if (code == CODE_LABEL
+ || (GET_RTX_CLASS (code) == 'i'
+ && (prev_code == JUMP_INSN
+ || prev_code == BARRIER
+ || (prev_code == CALL_INSN && call_had_abnormal_edge))))
+ {
+ count++;
-static char *block_live_static;
+ /* If the previous insn was a call that did not create an
+ abnormal edge, we want to add a nop so that the CALL_INSN
+ itself is not at basic_block_end. This allows us to
+ easily distinguish between normal calls and those which
+ create abnormal edges in the flow graph. */
-/* List of label_refs to all labels whose addresses are taken
- and used as data. */
-static rtx label_value_list;
+ if (count > 0 && prev_call != 0 && !call_had_abnormal_edge)
+ {
+ rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
+ emit_insn_after (nop, prev_call);
+ }
+ }
-/* a list of non-local labels in the function. */
-static rtx nonlocal_label_list;
+ /* Record whether this call created an edge. */
+ if (code == CALL_INSN)
+ {
+ prev_call = insn;
+ call_had_abnormal_edge = 0;
+ if (nonlocal_goto_handler_labels)
+ call_had_abnormal_edge = !in_libcall_block;
+ else if (eh_region)
+ {
+ rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
+ if (!note || XINT (XEXP (note, 0), 0) != 0)
+ call_had_abnormal_edge = 1;
+ }
+ }
+ else if (code != NOTE)
+ prev_call = NULL_RTX;
+
+ if (code != NOTE)
+ prev_code = code;
+ else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
+ ++eh_region;
+ else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
+ --eh_region;
+
+ if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
+ && find_reg_note (insn, REG_RETVAL, NULL_RTX))
+ in_libcall_block = 0;
+ }
+
+ /* The rest of the compiler works a bit smoother when we don't have to
+ check for the edge case of do-nothing functions with no basic blocks. */
+ if (count == 0)
+ {
+ emit_insn (gen_rtx_USE (VOIDmode, const0_rtx));
+ count = 1;
+ }
+
+ return count;
+}
/* Find all basic blocks of the function whose first insn is F.
Store the correct data in the tables that describe the basic blocks,
set up the chains of references for each CODE_LABEL, and
delete any entire basic blocks that cannot be reached.
- NONLOCAL_LABELS is a list of non-local labels in the function.
- Blocks that are otherwise unreachable may be reachable with a non-local
- goto. */
+ NONLOCAL_LABEL_LIST is a list of non-local labels in the function. Blocks
+ that are otherwise unreachable may be reachable with a non-local goto.
-static void
-find_basic_blocks_1 (f, nonlocal_labels)
- rtx f, nonlocal_labels;
-{
- register rtx insn;
- register int i;
- register char *block_live = (char *) alloca (n_basic_blocks);
- register char *block_marked = (char *) alloca (n_basic_blocks);
- rtx note, eh_note;
- enum rtx_code prev_code, code;
- int depth;
- int call_had_abnormal_edge = 0;
+ BB_EH_END is an array in which we record the list of exception regions
+ active at the end of every basic block. */
- active_eh_region = (int *) alloca ((max_uid_for_flow + 1) * sizeof (int));
- nested_eh_region = (int *) alloca ((max_label_num () + 1) * sizeof (int));
- nonlocal_label_list = nonlocal_labels;
+static rtx
+find_basic_blocks_1 (f, bb_eh_end)
+ rtx f;
+ rtx *bb_eh_end;
+{
+ register rtx insn, next;
+ int in_libcall_block = 0;
+ int call_has_abnormal_edge = 0;
+ int i = 0;
+ rtx bb_note = NULL_RTX;
+ rtx eh_list = NULL_RTX;
+ rtx label_value_list = NULL_RTX;
+ rtx head = NULL_RTX;
+ rtx end = NULL_RTX;
+
+ /* We process the instructions in a slightly different way than we did
+ previously. This is so that we see a NOTE_BASIC_BLOCK after we have
+ closed out the previous block, so that it gets attached at the proper
+ place. Since this form should be equivalent to the previous,
+ find_basic_blocks_0 continues to use the old form as a check. */
- label_value_list = 0;
- block_live_static = block_live;
- bzero (block_live, n_basic_blocks);
- bzero (block_marked, n_basic_blocks);
- bzero (basic_block_computed_jump_target, n_basic_blocks);
- bzero ((char *) active_eh_region, (max_uid_for_flow + 1) * sizeof (int));
- bzero ((char *) nested_eh_region, (max_label_num () + 1) * sizeof (int));
- current_function_has_computed_jump = 0;
+ for (insn = f; insn; insn = next)
+ {
+ enum rtx_code code = GET_CODE (insn);
- /* Initialize with just block 0 reachable and no blocks marked. */
- if (n_basic_blocks > 0)
- block_live[0] = 1;
+ next = NEXT_INSN (insn);
- /* Initialize the ref chain of each label to 0. Record where all the
- blocks start and end and their depth in loops. For each insn, record
- the block it is in. Also mark as reachable any blocks headed by labels
- that must not be deleted. */
+ /* Track when we are inside in LIBCALL block. */
+ if (GET_RTX_CLASS (code) == 'i'
+ && find_reg_note (insn, REG_LIBCALL, NULL_RTX))
+ in_libcall_block = 1;
- for (eh_note = NULL_RTX, insn = f, i = -1, prev_code = JUMP_INSN, depth = 1;
- insn; insn = NEXT_INSN (insn))
- {
- code = GET_CODE (insn);
- if (code == NOTE)
- {
- if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
- depth++;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
- depth--;
- }
-
- /* A basic block starts at label, or after something that can jump. */
- else if (code == CODE_LABEL
- || (GET_RTX_CLASS (code) == 'i'
- && (prev_code == JUMP_INSN
- || (prev_code == CALL_INSN && call_had_abnormal_edge)
- || prev_code == BARRIER)))
+ if (code == CALL_INSN)
{
- BLOCK_HEAD (++i) = insn;
- BLOCK_END (i) = insn;
- basic_block_loop_depth[i] = depth;
-
- if (code == CODE_LABEL)
+ /* Record whether this call created an edge. */
+ call_has_abnormal_edge = 0;
+ if (nonlocal_goto_handler_labels)
+ call_has_abnormal_edge = !in_libcall_block;
+ else if (eh_list)
{
- LABEL_REFS (insn) = insn;
- /* Any label that cannot be deleted
- is considered to start a reachable block. */
- if (LABEL_PRESERVE_P (insn))
- block_live[i] = 1;
+ rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
+ if (!note || XINT (XEXP (note, 0), 0) != 0)
+ call_has_abnormal_edge = 1;
}
}
- else if (GET_RTX_CLASS (code) == 'i')
+ switch (code)
{
- BLOCK_END (i) = insn;
- basic_block_loop_depth[i] = depth;
- }
+ case NOTE:
+ {
+ int kind = NOTE_LINE_NUMBER (insn);
+
+ /* Keep a LIFO list of the currently active exception notes. */
+ if (kind == NOTE_INSN_EH_REGION_BEG)
+ eh_list = gen_rtx_INSN_LIST (VOIDmode, insn, eh_list);
+ else if (kind == NOTE_INSN_EH_REGION_END)
+ eh_list = XEXP (eh_list, 1);
+
+ /* Look for basic block notes with which to keep the
+ basic_block_info pointers stable. Unthread the note now;
+ we'll put it back at the right place in create_basic_block.
+ Or not at all if we've already found a note in this block. */
+ else if (kind == NOTE_INSN_BASIC_BLOCK)
+ {
+ if (bb_note == NULL_RTX)
+ bb_note = insn;
+ next = flow_delete_insn (insn);
+ }
- if (GET_RTX_CLASS (code) == 'i')
- {
- /* Make a list of all labels referred to other than by jumps. */
- for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
- if (REG_NOTE_KIND (note) == REG_LABEL
- && XEXP (note, 0) != eh_return_stub_label)
- label_value_list = gen_rtx_EXPR_LIST (VOIDmode, XEXP (note, 0),
- label_value_list);
- }
+ break;
+ }
- /* Keep a lifo list of the currently active exception notes. */
- if (GET_CODE (insn) == NOTE)
- {
- if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG)
+ case CODE_LABEL:
+ /* A basic block starts at a label. If we've closed one off due
+ to a barrier or some such, no need to do it again. */
+ if (head != NULL_RTX)
{
- if (eh_note)
- nested_eh_region [NOTE_BLOCK_NUMBER (insn)] =
- NOTE_BLOCK_NUMBER (XEXP (eh_note, 0));
- else
- nested_eh_region [NOTE_BLOCK_NUMBER (insn)] = 0;
- eh_note = gen_rtx_EXPR_LIST (VOIDmode,
- insn, eh_note);
+ /* While we now have edge lists with which other portions of
+ the compiler might determine a call ending a basic block
+ does not imply an abnormal edge, it will be a bit before
+ everything can be updated. So continue to emit a noop at
+ the end of such a block. */
+ if (GET_CODE (end) == CALL_INSN)
+ {
+ rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
+ end = emit_insn_after (nop, end);
+ }
+
+ bb_eh_end[i] = eh_list;
+ create_basic_block (i++, head, end, bb_note);
+ bb_note = NULL_RTX;
}
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
- eh_note = XEXP (eh_note, 1);
- }
- /* If we encounter a CALL_INSN, note which exception handler it
- might pass control to.
-
- If doing asynchronous exceptions, record the active EH handler
- for every insn, since most insns can throw. */
- else if (eh_note
- && (asynchronous_exceptions
- || (GET_CODE (insn) == CALL_INSN)))
- active_eh_region[INSN_UID (insn)] =
- NOTE_BLOCK_NUMBER (XEXP (eh_note, 0));
- BLOCK_NUM (insn) = i;
-
- /* We change the code of the CALL_INSN, so that it won't start a
- new block if it doesn't throw. */
- if (code == CALL_INSN)
- {
- rtx rnote = find_reg_note(insn, REG_EH_REGION, NULL_RTX);
- if (rnote && XINT (XEXP (rnote, 0), 0) == 0)
- code = INSN;
- }
+ head = end = insn;
+ break;
- /* Record whether this call created an edge. */
- if (code == CALL_INSN)
- call_had_abnormal_edge = (nonlocal_label_list != 0 || eh_note);
+ case JUMP_INSN:
+ /* A basic block ends at a jump. */
+ if (head == NULL_RTX)
+ head = insn;
+ else
+ {
+ /* ??? Make a special check for table jumps. The way this
+ happens is truely and amazingly gross. We are about to
+ create a basic block that contains just a code label and
+ an addr*vec jump insn. Worse, an addr_diff_vec creates
+ its own natural loop.
- if (code != NOTE)
- prev_code = code;
+ Prevent this bit of brain damage, pasting things together
+ correctly in make_edges.
- }
+ The correct solution involves emitting the table directly
+ on the tablejump instruction as a note, or JUMP_LABEL. */
- if (i + 1 != n_basic_blocks)
- abort ();
+ if (GET_CODE (PATTERN (insn)) == ADDR_VEC
+ || GET_CODE (PATTERN (insn)) == ADDR_DIFF_VEC)
+ {
+ head = end = NULL;
+ n_basic_blocks--;
+ break;
+ }
+ }
+ end = insn;
+ goto new_bb_inclusive;
- /* Now find which basic blocks can actually be reached
- and put all jump insns' LABEL_REFS onto the ref-chains
- of their target labels. */
+ case BARRIER:
+ /* A basic block ends at a barrier. It may be that an unconditional
+ jump already closed the basic block -- no need to do it again. */
+ if (head == NULL_RTX)
+ break;
- if (n_basic_blocks > 0)
- {
- int something_marked = 1;
+ /* While we now have edge lists with which other portions of the
+ compiler might determine a call ending a basic block does not
+ imply an abnormal edge, it will be a bit before everything can
+ be updated. So continue to emit a noop at the end of such a
+ block. */
+ if (GET_CODE (end) == CALL_INSN)
+ {
+ rtx nop = gen_rtx_USE (VOIDmode, const0_rtx);
+ end = emit_insn_after (nop, end);
+ }
+ goto new_bb_exclusive;
- /* Pass over all blocks, marking each block that is reachable
- and has not yet been marked.
- Keep doing this until, in one pass, no blocks have been marked.
- Then blocks_live and blocks_marked are identical and correct.
- In addition, all jumps actually reachable have been marked. */
+ case CALL_INSN:
+ /* A basic block ends at a call that can either throw or
+ do a non-local goto. */
+ if (call_has_abnormal_edge)
+ {
+ new_bb_inclusive:
+ if (head == NULL_RTX)
+ head = insn;
+ end = insn;
+
+ new_bb_exclusive:
+ bb_eh_end[i] = eh_list;
+ create_basic_block (i++, head, end, bb_note);
+ head = end = NULL_RTX;
+ bb_note = NULL_RTX;
+ break;
+ }
+ /* FALLTHRU */
- while (something_marked)
+ default:
+ if (GET_RTX_CLASS (code) == 'i')
+ {
+ if (head == NULL_RTX)
+ head = insn;
+ end = insn;
+ }
+ break;
+ }
+
+ if (GET_RTX_CLASS (code) == 'i')
{
- something_marked = 0;
- for (i = 0; i < n_basic_blocks; i++)
- if (block_live[i] && !block_marked[i])
- {
- int_list_ptr p;
+ rtx note;
- block_marked[i] = 1;
- something_marked = 1;
+ /* Make a list of all labels referred to other than by jumps
+ (which just don't have the REG_LABEL notes).
- make_edges (i);
+ Make a special exception for labels followed by an ADDR*VEC,
+ as this would be a part of the tablejump setup code.
- for (p = basic_block_succ[i]; p; p = p->next)
- block_live[INT_LIST_VAL (p)] = 1;
+ Make a special exception for the eh_return_stub_label, which
+ we know isn't part of any otherwise visible control flow. */
+
+ for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
+ if (REG_NOTE_KIND (note) == REG_LABEL)
+ {
+ rtx lab = XEXP (note, 0), next;
+
+ if (lab == eh_return_stub_label)
+ ;
+ else if ((next = next_nonnote_insn (lab)) != NULL
+ && GET_CODE (next) == JUMP_INSN
+ && (GET_CODE (PATTERN (next)) == ADDR_VEC
+ || GET_CODE (PATTERN (next)) == ADDR_DIFF_VEC))
+ ;
+ else
+ label_value_list
+ = gen_rtx_EXPR_LIST (VOIDmode, XEXP (note, 0),
+ label_value_list);
}
+
+ if (find_reg_note (insn, REG_RETVAL, NULL_RTX))
+ in_libcall_block = 0;
}
+ }
- /* This should never happen. If it does that means we've computed an
- incorrect flow graph, which can lead to aborts/crashes later in the
- compiler or incorrect code generation.
+ if (head != NULL_RTX)
+ {
+ bb_eh_end[i] = eh_list;
+ create_basic_block (i++, head, end, bb_note);
+ }
- We used to try and continue here, but that's just asking for trouble
- later during the compile or at runtime. It's easier to debug the
- problem here than later! */
- for (i = 1; i < n_basic_blocks; i++)
- if (block_live[i] && basic_block_pred[i] == 0)
- abort ();
+ if (i != n_basic_blocks)
+ abort ();
- if (! reload_completed)
- delete_unreachable_blocks ();
- }
+ return label_value_list;
}
-/* Record INSN's block number as BB. */
+/* Create a new basic block consisting of the instructions between
+ HEAD and END inclusive. Reuses the note and basic block struct
+ in BB_NOTE, if any. */
-void
-set_block_num (insn, bb)
- rtx insn;
- int bb;
+static void
+create_basic_block (index, head, end, bb_note)
+ int index;
+ rtx head, end, bb_note;
{
- if (INSN_UID (insn) >= max_uid_for_flow)
+ basic_block bb;
+
+ if (bb_note
+ && (bb = NOTE_BASIC_BLOCK (bb_note)) != NULL
+ && bb->aux == NULL)
{
- /* Add one-eighth the size so we don't keep calling xrealloc. */
- max_uid_for_flow = INSN_UID (insn) + (INSN_UID (insn) + 7) / 8;
- uid_block_number = (int *)
- xrealloc (uid_block_number, (max_uid_for_flow + 1) * sizeof (int));
+ /* If we found an existing note, thread it back onto the chain. */
+
+ if (GET_CODE (head) == CODE_LABEL)
+ add_insn_after (bb_note, head);
+ else
+ {
+ add_insn_before (bb_note, head);
+ head = bb_note;
+ }
}
- BLOCK_NUM (insn) = bb;
-}
-
-/* Subroutines of find_basic_blocks. */
+ else
+ {
+ /* Otherwise we must create a note and a basic block structure.
+ Since we allow basic block structs in rtl, give the struct
+ the same lifetime by allocating it off the function obstack
+ rather than using malloc. */
-void
-free_bb_memory ()
-{
- free_int_list (&flow_int_list_blocks);
-}
+ bb = (basic_block) obstack_alloc (function_obstack, sizeof (*bb));
+ memset (bb, 0, sizeof (*bb));
-/* Make an edge in the cfg from block PRED to block SUCC. */
-static void
-add_edge (pred, succ)
- int pred, succ;
-{
- add_int_list_node (&flow_int_list_blocks, basic_block_pred + succ, pred);
- add_int_list_node (&flow_int_list_blocks, basic_block_succ + pred, succ);
+ if (GET_CODE (head) == CODE_LABEL)
+ bb_note = emit_note_after (NOTE_INSN_BASIC_BLOCK, head);
+ else
+ {
+ bb_note = emit_note_before (NOTE_INSN_BASIC_BLOCK, head);
+ head = bb_note;
+ }
+ NOTE_BASIC_BLOCK (bb_note) = bb;
+ }
+
+ bb->head = head;
+ bb->end = end;
+ bb->index = index;
+ BASIC_BLOCK (index) = bb;
+
+ /* Tag the block so that we know it has been used when considering
+ other basic block notes. */
+ bb->aux = bb;
}
+
+/* Records the basic block struct in BB_FOR_INSN, for every instruction
+ indexed by INSN_UID. MAX is the size of the array. */
-/* Make an edge in the cfg from block PRED to the block starting with
- label LABEL. */
static void
-add_edge_to_label (pred, label)
- int pred;
- rtx label;
+compute_bb_for_insn (bb_for_insn, max)
+ varray_type bb_for_insn;
+ int max;
{
- /* If the label was never emitted, this insn is junk,
- but avoid a crash trying to refer to BLOCK_NUM (label).
- This can happen as a result of a syntax error
- and a diagnostic has already been printed. */
- if (INSN_UID (label) == 0)
- return;
+ int i;
+
+ for (i = 0; i < n_basic_blocks; ++i)
+ {
+ basic_block bb = BASIC_BLOCK (i);
+ rtx insn, end;
- add_edge (pred, BLOCK_NUM (label));
+ end = bb->end;
+ insn = bb->head;
+ while (1)
+ {
+ int uid = INSN_UID (insn);
+ if (uid < max)
+ VARRAY_BB (bb_for_insn, uid) = bb;
+ if (insn == end)
+ break;
+ insn = NEXT_INSN (insn);
+ }
+ }
}
-/* Check expression X for label references. If one is found, add an edge
- from basic block PRED to the block beginning with the label. */
+/* Free the memory associated with the edge structures. */
static void
-mark_label_ref (pred, x)
- int pred;
- rtx x;
+clear_edges ()
{
- register RTX_CODE code;
- register int i;
- register char *fmt;
+ int i;
+ edge n, e;
- code = GET_CODE (x);
- if (code == LABEL_REF)
+ for (i = 0; i < n_basic_blocks; ++i)
{
- add_edge_to_label (pred, XEXP (x, 0));
- return;
- }
+ basic_block bb = BASIC_BLOCK (i);
- fmt = GET_RTX_FORMAT (code);
- for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
- {
- if (fmt[i] == 'e')
- mark_label_ref (pred, XEXP (x, i));
- if (fmt[i] == 'E')
+ for (e = bb->succ; e ; e = n)
{
- register int j;
- for (j = 0; j < XVECLEN (x, i); j++)
- mark_label_ref (pred, XVECEXP (x, i, j));
+ n = e->succ_next;
+ free (e);
}
+
+ bb->succ = 0;
+ bb->pred = 0;
+ }
+
+ for (e = ENTRY_BLOCK_PTR->succ; e ; e = n)
+ {
+ n = e->succ_next;
+ free (e);
}
+
+ ENTRY_BLOCK_PTR->succ = 0;
+ EXIT_BLOCK_PTR->pred = 0;
}
-/* For basic block I, make edges and mark live all blocks which are reachable
- from it. */
+/* Identify the edges between basic blocks.
+
+ NONLOCAL_LABEL_LIST is a list of non-local labels in the function. Blocks
+ that are otherwise unreachable may be reachable with a non-local goto.
+
+ BB_EH_END is an array indexed by basic block number in which we record
+ the list of exception regions active at the end of the basic block. */
+
static void
-make_edges (i)
- int i;
+make_edges (label_value_list, bb_eh_end)
+ rtx label_value_list;
+ rtx *bb_eh_end;
{
- rtx insn, x;
- rtx pending_eh_region = NULL_RTX;
+ int i;
- /* See if control drops into the next block. */
- if (i + 1 < n_basic_blocks)
+ /* Assume no computed jump; revise as we create edges. */
+ current_function_has_computed_jump = 0;
+
+ /* By nature of the way these get numbered, block 0 is always the entry. */
+ make_edge (ENTRY_BLOCK_PTR, BASIC_BLOCK (0), EDGE_FALLTHRU);
+
+ for (i = 0; i < n_basic_blocks; ++i)
{
- for (insn = PREV_INSN (BLOCK_HEAD (i + 1));
- insn && GET_CODE (insn) == NOTE; insn = PREV_INSN (insn))
- ;
+ basic_block bb = BASIC_BLOCK (i);
+ rtx insn, x, eh_list;
+ enum rtx_code code;
- if (insn && GET_CODE (insn) != BARRIER)
- add_edge (i, i + 1);
- }
+ /* If we have asynchronous exceptions, scan the notes for all exception
+ regions active in the block. In the normal case, we only need the
+ one active at the end of the block, which is bb_eh_end[i]. */
- insn = BLOCK_END (i);
- if (GET_CODE (insn) == JUMP_INSN)
- mark_label_ref (i, PATTERN (insn));
-
- /* If we have any forced labels, mark them as potentially reachable from
- this block. */
- for (x = forced_labels; x; x = XEXP (x, 1))
- if (! LABEL_REF_NONLOCAL_P (x))
- add_edge_to_label (i, XEXP (x, 0));
-
- /* Now scan the insns for this block, we may need to make edges for some of
- them to various non-obvious locations (exception handlers, nonlocal
- labels, etc). */
- for (insn = BLOCK_HEAD (i);
- insn != NEXT_INSN (BLOCK_END (i));
- insn = NEXT_INSN (insn))
- {
- if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
+ eh_list = bb_eh_end[i];
+ if (asynchronous_exceptions)
{
- rtx note;
- /* References to labels in non-jumping insns have REG_LABEL notes
- attached to them.
-
- This can happen for computed gotos; we don't care about them
- here since the values are also on the label_value_list and will
- be marked live if we find a live computed goto.
-
- This can also happen when we take the address of a label to pass
- as an argument to __throw. Note throw only uses the value to
- determine what handler should be called -- ie the label is not
- used as a jump target, it just marks regions in the code.
-
- In theory we should be able to ignore the REG_LABEL notes, but
- we have to make sure that the label and associated insns aren't
- marked dead, so we make the block in question live and create an
- edge from this insn to the label. This is not strictly correct,
- but it is close enough for now.
-
- See below for code that handles the eh_stub label specially. */
- for (note = REG_NOTES (insn);
- note;
- note = XEXP (note, 1))
+ for (insn = bb->end; insn != bb->head; insn = PREV_INSN (insn))
{
- if (REG_NOTE_KIND (note) == REG_LABEL
- && XEXP (note, 0) != eh_return_stub_label)
- add_edge_to_label (i, XEXP (note, 0));
+ if (GET_CODE (insn) == NOTE
+ && NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
+ eh_list = gen_rtx_INSN_LIST (VOIDmode, insn, eh_list);
}
+ }
- /* If this is a computed jump, then mark it as reaching everything
- on the label_value_list and forced_labels list. */
- if (computed_jump_p (insn))
+ /* Now examine the last instruction of the block, and discover the
+ ways we can leave the block. */
+
+ insn = bb->end;
+ code = GET_CODE (insn);
+
+ /* A branch. */
+ if (code == JUMP_INSN)
+ {
+ rtx tmp;
+
+ /* ??? Recognize a tablejump and do the right thing. */
+ if ((tmp = JUMP_LABEL (insn)) != NULL_RTX
+ && (tmp = NEXT_INSN (tmp)) != NULL_RTX
+ && GET_CODE (tmp) == JUMP_INSN
+ && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
+ || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
+ {
+ rtvec vec;
+ int j;
+
+ if (GET_CODE (PATTERN (tmp)) == ADDR_VEC)
+ vec = XVEC (PATTERN (tmp), 0);
+ else
+ vec = XVEC (PATTERN (tmp), 1);
+
+ for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
+ make_label_edge (bb, XEXP (RTVEC_ELT (vec, j), 0), 0);
+ }
+
+ /* If this is a computed jump, then mark it as reaching
+ everything on the label_value_list and forced_labels list. */
+ else if (computed_jump_p (insn))
{
current_function_has_computed_jump = 1;
- for (x = label_value_list; x; x = XEXP (x, 1))
- {
- int b = BLOCK_NUM (XEXP (x, 0));
- basic_block_computed_jump_target[b] = 1;
- add_edge (i, b);
- }
+ for (x = label_value_list; x; x = XEXP (x, 1))
+ make_label_edge (bb, XEXP (x, 0), EDGE_ABNORMAL);
+
for (x = forced_labels; x; x = XEXP (x, 1))
- {
- int b = BLOCK_NUM (XEXP (x, 0));
- basic_block_computed_jump_target[b] = 1;
- add_edge (i, b);
- }
+ make_label_edge (bb, XEXP (x, 0), EDGE_ABNORMAL);
}
- /* If this is a call with an EH_RETHROW note, then we
- know its a rethrow call, and we know exactly where
- this call can end up going. */
- else if (GET_CODE (insn) == CALL_INSN
- && (note = find_reg_note (insn, REG_EH_RETHROW, NULL_RTX)))
- {
- int region = XINT (XEXP (note, 0), 0);
- /* if nested region is not 0, we know for sure it has been
- processed. If it is zero, we dont know whether its an
- outer region, or hasn't been seen yet, so defer it */
- if (nested_eh_region[region] != 0)
- {
- /* start with the first region OUTSIDE the one specified
- in the rethrow parameter. (since a rethrow behaves
- as if a handler in the region didn't handle the
- exception, so the handlers for the next outer region
- are going to get a shot at it.*/
- for ( region = nested_eh_region[region]; region;
- region = nested_eh_region[region])
- {
- handler_info *ptr = get_first_handler (region);
- for ( ; ptr ; ptr = ptr->next)
- add_edge_to_label (i, ptr->handler_label);
- }
- }
- else
- {
- /* Push this region onto a list, and after we've done the
- whole procedure, we'll process everything on the list */
- pending_eh_region = gen_rtx_EXPR_LIST (VOIDmode, insn,
- pending_eh_region);
- }
- }
-
- /* If this is a CALL_INSN, then mark it as reaching the active EH
- handler for this CALL_INSN. If we're handling asynchronous
- exceptions mark every insn as reaching the active EH handler.
-
- Also mark the CALL_INSN as reaching any nonlocal goto sites. */
- else if (asynchronous_exceptions
- || (GET_CODE (insn) == CALL_INSN
- && ! find_reg_note (insn, REG_RETVAL, NULL_RTX)))
+ /* Returns create an exit out. */
+ else if (returnjump_p (insn))
+ make_edge (bb, EXIT_BLOCK_PTR, 0);
+
+ /* Otherwise, we have a plain conditional or unconditional jump. */
+ else
{
- int region = active_eh_region[INSN_UID (insn)];
- note = find_reg_note(insn, REG_EH_REGION, NULL_RTX);
+ if (! JUMP_LABEL (insn))
+ abort ();
+ make_label_edge (bb, JUMP_LABEL (insn), 0);
+ }
+ }
+
+ /* If this is a CALL_INSN, then mark it as reaching the active EH
+ handler for this CALL_INSN. If we're handling asynchronous
+ exceptions then any insn can reach any of the active handlers.
- /* Override region if we see a REG_EH_REGION note. */
- if (note)
- region = XINT (XEXP (note, 0), 0);
+ Also mark the CALL_INSN as reaching any nonlocal goto handler. */
- if (region)
+ else if (code == CALL_INSN || asynchronous_exceptions)
+ {
+ int is_call = (code == CALL_INSN ? EDGE_ABNORMAL_CALL : 0);
+ handler_info *ptr;
+
+ /* Use REG_EH_RETHROW and REG_EH_REGION if available. */
+ /* ??? REG_EH_REGION is not generated presently. Is it
+ inteded that there be multiple notes for the regions?
+ or is my eh_list collection redundant with handler linking? */
+
+ x = find_reg_note (insn, REG_EH_RETHROW, 0);
+ if (!x)
+ x = find_reg_note (insn, REG_EH_REGION, 0);
+ if (x)
+ {
+ if (XINT (XEXP (x, 0), 0) != 0)
{
- handler_info *ptr;
- region = active_eh_region[INSN_UID (insn)];
- for ( ; region; region = nested_eh_region[region])
+ ptr = get_first_handler (XINT (XEXP (x, 0), 0));
+ while (ptr)
{
- ptr = get_first_handler (region);
- for ( ; ptr ; ptr = ptr->next)
- add_edge_to_label (i, ptr->handler_label);
+ make_label_edge (bb, ptr->handler_label,
+ EDGE_ABNORMAL | EDGE_EH | is_call);
+ ptr = ptr->next;
}
}
- if (! asynchronous_exceptions)
+ }
+ else
+ {
+ for (x = eh_list; x; x = XEXP (x, 1))
{
- for (x = nonlocal_label_list; x; x = XEXP (x, 1))
- add_edge_to_label (i, XEXP (x, 0));
+ ptr = get_first_handler (NOTE_BLOCK_NUMBER (XEXP (x, 0)));
+ while (ptr)
+ {
+ make_label_edge (bb, ptr->handler_label,
+ EDGE_ABNORMAL | EDGE_EH | is_call);
+ ptr = ptr->next;
+ }
}
+ }
+
+ if (code == CALL_INSN && nonlocal_goto_handler_labels)
+ {
/* ??? This could be made smarter: in some cases it's possible
to tell that certain calls will not do a nonlocal goto.
@@ -859,147 +997,636 @@ make_edges (i)
gotos do not have their addresses taken, then only calls to
those functions or to other nested functions that use them
could possibly do nonlocal gotos. */
+
+ for (x = nonlocal_goto_handler_labels; x ; x = XEXP (x, 1))
+ make_label_edge (bb, XEXP (x, 0),
+ EDGE_ABNORMAL | EDGE_ABNORMAL_CALL);
}
}
- }
- while (pending_eh_region != NULL_RTX)
- {
- rtx insn = XEXP (pending_eh_region, 0);
- rtx note = find_reg_note (insn, REG_EH_RETHROW, NULL_RTX);
- int region = XINT (XEXP (note, 0), 0);
- /* start with the first region OUTSIDE the one specified
- in the rethrow parameter */
- for ( region = nested_eh_region[region]; region;
- region = nested_eh_region[region])
- {
- handler_info *ptr = get_first_handler (region);
- for ( ; ptr ; ptr = ptr->next)
- add_edge_to_label (BLOCK_NUM (insn), ptr->handler_label);
- }
- pending_eh_region = XEXP (pending_eh_region, 1);
+ /* We know something about the structure of the function __throw in
+ libgcc2.c. It is the only function that ever contains eh_stub
+ labels. It modifies its return address so that the last block
+ returns to one of the eh_stub labels within it. So we have to
+ make additional edges in the flow graph. */
+ if (i + 1 == n_basic_blocks && eh_return_stub_label != 0)
+ make_label_edge (bb, eh_return_stub_label, EDGE_EH);
+
+ /* Find out if we can drop through to the next block. */
+ insn = next_nonnote_insn (insn);
+ if (!insn)
+ make_edge (bb, EXIT_BLOCK_PTR, EDGE_FALLTHRU);
+ else if (i + 1 < n_basic_blocks)
+ {
+ rtx tmp = BLOCK_HEAD (i + 1);
+ if (GET_CODE (tmp) == NOTE)
+ tmp = next_nonnote_insn (tmp);
+ if (insn == tmp)
+ make_edge (bb, BASIC_BLOCK (i + 1), EDGE_FALLTHRU);
+ }
}
-
- /* We know something about the structure of the function __throw in
- libgcc2.c. It is the only function that ever contains eh_stub labels.
- It modifies its return address so that the last block returns to one of
- the eh_stub labels within it. So we have to make additional edges in
- the flow graph. */
- if (i + 1 == n_basic_blocks && eh_return_stub_label != 0)
- add_edge_to_label (i, eh_return_stub_label);
}
-/* Now delete the code for any basic blocks that can't be reached.
- They can occur because jump_optimize does not recognize unreachable loops
- as unreachable. */
+/* Create an edge between two basic blocks. FLAGS are auxiliary information
+ about the edge that is accumulated between calls. */
+
static void
-delete_unreachable_blocks ()
+make_edge (src, dst, flags)
+ basic_block src, dst;
+ int flags;
{
- int deleted_handler = 0;
- int deleted = 0;
- int i, j;
- rtx insn;
- int *block_num_map = XNMALLOC (int, n_basic_blocks);
+ edge e;
- for (i = n_basic_blocks - 1; i >= 0; i--)
- if (! block_live_static[i])
- deleted_handler |= delete_block (i);
+ /* Make sure we don't add duplicate edges. */
- for (i = 0; i < n_basic_blocks; i++)
- if (block_live_static[i])
- block_num_map[i] = i - deleted;
- else
+ for (e = src->succ; e ; e = e->succ_next)
+ if (e->dest == dst)
{
- deleted++;
- block_num_map[i] = -1;
+ e->flags |= flags;
+ return;
}
- /* Eliminate all traces of the deleted blocks by renumbering the remaining
- ones. */
- for (i = j = 0; i < n_basic_blocks; i++)
- {
- int_list_ptr p;
+ e = (edge) xcalloc (1, sizeof (*e));
- if (block_num_map[i] == -1)
- continue;
+ e->succ_next = src->succ;
+ e->pred_next = dst->pred;
+ e->src = src;
+ e->dest = dst;
+ e->flags = flags;
- for (p = basic_block_pred[i]; p; p = p->next)
- INT_LIST_VAL (p) = block_num_map[INT_LIST_VAL (p)];
- for (p = basic_block_succ[i]; p; p = p->next)
- INT_LIST_VAL (p) = block_num_map[INT_LIST_VAL (p)];
+ src->succ = e;
+ dst->pred = e;
+}
+
+/* Create an edge from a basic block to a label. */
+
+static void
+make_label_edge (src, label, flags)
+ basic_block src;
+ rtx label;
+ int flags;
+{
+ if (GET_CODE (label) != CODE_LABEL)
+ abort ();
+
+ /* If the label was never emitted, this insn is junk, but avoid a
+ crash trying to refer to BLOCK_FOR_INSN (label). This can happen
+ as a result of a syntax error and a diagnostic has already been
+ printed. */
+
+ if (INSN_UID (label) == 0)
+ return;
+
+ make_edge (src, BLOCK_FOR_INSN (label), flags);
+}
+
+/* Identify critical edges and set the bits appropriately. */
+static void
+mark_critical_edges ()
+{
+ int i, n = n_basic_blocks;
+ basic_block bb;
+
+ /* We begin with the entry block. This is not terribly important now,
+ but could be if a front end (Fortran) implemented alternate entry
+ points. */
+ bb = ENTRY_BLOCK_PTR;
+ i = -1;
+
+ while (1)
+ {
+ edge e;
- if (i != j)
+ /* (1) Critical edges must have a source with multiple successors. */
+ if (bb->succ && bb->succ->succ_next)
{
- rtx tmp = BLOCK_HEAD (i);
- for (;;)
+ for (e = bb->succ; e ; e = e->succ_next)
{
- BLOCK_NUM (tmp) = j;
- if (tmp == BLOCK_END (i))
- break;
- tmp = NEXT_INSN (tmp);
+ /* (2) Critical edges must have a destination with multiple
+ predecessors. Note that we know there is at least one
+ predecessor -- the edge we followed to get here. */
+ if (e->dest->pred->pred_next)
+ e->flags |= EDGE_CRITICAL;
+ else
+ e->flags &= ~EDGE_CRITICAL;
}
- BLOCK_HEAD (j) = BLOCK_HEAD (i);
- BLOCK_END (j) = BLOCK_END (i);
- basic_block_pred[j] = basic_block_pred[i];
- basic_block_succ[j] = basic_block_succ[i];
- basic_block_loop_depth[j] = basic_block_loop_depth[i];
- basic_block_computed_jump_target[j]
- = basic_block_computed_jump_target[i];
}
- j++;
+ else
+ {
+ for (e = bb->succ; e ; e = e->succ_next)
+ e->flags &= ~EDGE_CRITICAL;
+ }
+
+ if (++i >= n)
+ break;
+ bb = BASIC_BLOCK (i);
}
- n_basic_blocks -= deleted;
- free (block_num_map);
+}
+
+/* Split a (typically critical) edge. Return the new block.
+ Abort on abnormal edges.
- /* If we deleted an exception handler, we may have EH region
- begin/end blocks to remove as well. */
- if (deleted_handler)
- for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
- if (GET_CODE (insn) == NOTE)
+ ??? The code generally expects to be called on critical edges.
+ The case of a block ending in an unconditional jump to a
+ block with multiple predecessors is not handled optimally. */
+
+basic_block
+split_edge (edge_in)
+ edge edge_in;
+{
+ basic_block old_pred, bb, old_succ;
+ edge edge_out;
+ rtx bb_note;
+ int i;
+
+ /* Abnormal edges cannot be split. */
+ if ((edge_in->flags & EDGE_ABNORMAL) != 0)
+ abort ();
+
+ old_pred = edge_in->src;
+ old_succ = edge_in->dest;
+
+ /* Remove the existing edge from the destination's pred list. */
+ {
+ edge *pp;
+ for (pp = &old_succ->pred; *pp != edge_in; pp = &(*pp)->pred_next)
+ continue;
+ *pp = edge_in->pred_next;
+ }
+
+ /* Create the new structures. */
+ bb = (basic_block) obstack_alloc (function_obstack, sizeof (*bb));
+ edge_out = (edge) xcalloc (1, sizeof (*edge_out));
+
+ memset (bb, 0, sizeof (*bb));
+ bb->local_set = OBSTACK_ALLOC_REG_SET (function_obstack);
+ bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (function_obstack);
+ bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (function_obstack);
+
+ /* ??? This info is likely going to be out of date very soon. */
+ CLEAR_REG_SET (bb->local_set);
+ if (old_succ->global_live_at_start)
+ {
+ COPY_REG_SET (bb->global_live_at_start, old_succ->global_live_at_start);
+ COPY_REG_SET (bb->global_live_at_end, old_succ->global_live_at_start);
+ }
+ else
+ {
+ CLEAR_REG_SET (bb->global_live_at_start);
+ CLEAR_REG_SET (bb->global_live_at_end);
+ }
+
+ /* Wire them up. */
+ bb->pred = edge_in;
+ bb->succ = edge_out;
+ edge_in->dest = bb;
+ edge_out->src = bb;
+ edge_out->dest = old_succ;
+
+ /* Tricky case -- if there existed a fallthru into the successor
+ (and we're not it) we must add a new unconditional jump around
+ the new block we're actually interested in.
+
+ Further, if that edge is critical, this means a second new basic
+ block must be created to hold it. In order to simplify correct
+ insn placement, do this before we touch the existing basic block
+ ordering for the block we were really wanting. */
+ if ((edge_in->flags & EDGE_FALLTHRU) == 0)
+ {
+ edge e;
+ for (e = old_succ->pred; e ; e = e->pred_next)
+ if (e->flags & EDGE_FALLTHRU)
+ break;
+
+ if (e)
{
- if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG ||
- NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
+ basic_block jump_block;
+ rtx pos;
+
+ if ((e->flags & EDGE_CRITICAL) == 0)
{
- int num = CODE_LABEL_NUMBER (insn);
- /* A NULL handler indicates a region is no longer needed,
- unless its the target of a rethrow. */
- if (get_first_handler (num) == NULL && !rethrow_used (num))
- {
- NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (insn) = 0;
- }
+ /* Non critical -- we can simply add a jump to the end
+ of the existing predecessor. */
+ jump_block = e->src;
+ pos = jump_block->end;
+ }
+ else
+ {
+ /* We need a new block to hold the jump. The simplest
+ way to do the bulk of the work here is to recursively
+ call ourselves. */
+ jump_block = split_edge (e);
+ e = jump_block->succ;
+ pos = jump_block->head;
}
+
+ /* Now add the jump insn... */
+ pos = emit_jump_insn_after (gen_jump (old_succ->head), pos);
+ jump_block->end = pos;
+ emit_barrier_after (pos);
+
+ /* ... and clear fallthru on the outgoing edge. */
+ e->flags &= ~EDGE_FALLTHRU;
+
+ /* Continue splitting the interesting edge. */
}
+ }
+
+ /* Place the new block just in front of the successor. */
+ VARRAY_GROW (basic_block_info, ++n_basic_blocks);
+ for (i = n_basic_blocks - 1; i > old_succ->index; --i)
+ {
+ basic_block tmp = BASIC_BLOCK (i - 1);
+ BASIC_BLOCK (i) = tmp;
+ tmp->index = i;
+ }
+ BASIC_BLOCK (i) = bb;
+ bb->index = i;
+
+ /* Create the basic block note. */
+ bb_note = emit_note_before (NOTE_INSN_BASIC_BLOCK, old_succ->head);
+ NOTE_BASIC_BLOCK (bb_note) = bb;
+ bb->head = bb->end = bb_note;
+
+ /* Not quite simple -- for non-fallthru edges, we must adjust the
+ predecessor's jump instruction to target our new block. */
+ if ((edge_in->flags & EDGE_FALLTHRU) == 0)
+ {
+ rtx tmp, insn = old_pred->end;
+ rtx old_label = old_succ->head;
+ rtx new_label = gen_label_rtx ();
+
+ if (GET_CODE (insn) != JUMP_INSN)
+ abort ();
+
+ /* ??? Recognize a tablejump and adjust all matching cases. */
+ if ((tmp = JUMP_LABEL (insn)) != NULL_RTX
+ && (tmp = NEXT_INSN (tmp)) != NULL_RTX
+ && GET_CODE (tmp) == JUMP_INSN
+ && (GET_CODE (PATTERN (tmp)) == ADDR_VEC
+ || GET_CODE (PATTERN (tmp)) == ADDR_DIFF_VEC))
+ {
+ rtvec vec;
+ int j;
+
+ if (GET_CODE (PATTERN (tmp)) == ADDR_VEC)
+ vec = XVEC (PATTERN (tmp), 0);
+ else
+ vec = XVEC (PATTERN (tmp), 1);
+
+ for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
+ if (XEXP (RTVEC_ELT (vec, j), 0) == old_label)
+ {
+ RTVEC_ELT (vec, j) = gen_rtx_LABEL_REF (VOIDmode, new_label);
+ --LABEL_NUSES (old_label);
+ ++LABEL_NUSES (new_label);
+ }
+ }
+ else
+ {
+ /* This would have indicated an abnormal edge. */
+ if (computed_jump_p (insn))
+ abort ();
+
+ /* A return instruction can't be redirected. */
+ if (returnjump_p (insn))
+ abort ();
+
+ /* If the insn doesn't go where we think, we're confused. */
+ if (JUMP_LABEL (insn) != old_label)
+ abort ();
+
+ redirect_jump (insn, new_label);
+ }
+
+ emit_label_before (new_label, bb_note);
+ bb->head = new_label;
+ }
+
+ /* In all cases, the new block falls through to the successor. */
+ edge_out->flags = EDGE_FALLTHRU;
+
+ return bb;
}
-/* Delete the insns in a (non-live) block. We physically delete every
- non-note insn except the start and end (so BLOCK_HEAD/END needn't
- be updated), we turn the latter into NOTE_INSN_DELETED notes.
+/* Queue instructions for insertion on an edge between two basic blocks.
+ The new instructions and basic blocks (if any) will not appear in the
+ CFG until commit_edge_insertions is called. */
- We use to "delete" the insns by turning them into notes, but we may be
- deleting lots of insns that subsequent passes would otherwise have to
- process. Secondly, lots of deleted blocks in a row can really slow down
- propagate_block since it will otherwise process insn-turned-notes multiple
- times when it looks for loop begin/end notes.
+void
+insert_insn_on_edge (pattern, e)
+ rtx pattern;
+ edge e;
+{
+ /* We cannot insert instructions on an abnormal critical edge.
+ It will be easier to find the culprit if we die now. */
+ if ((e->flags & (EDGE_ABNORMAL|EDGE_CRITICAL))
+ == (EDGE_ABNORMAL|EDGE_CRITICAL))
+ abort ();
+
+ if (e->insns == NULL_RTX)
+ start_sequence ();
+ else
+ push_to_sequence (e->insns);
+
+ emit_insn (pattern);
+
+ e->insns = get_insns ();
+ end_sequence();
+}
+
+/* Update the CFG for the instructions queued on edge E. */
+
+static void
+commit_one_edge_insertion (e)
+ edge e;
+{
+ rtx before = NULL_RTX, after = NULL_RTX, tmp;
+ basic_block bb;
+
+ /* Figure out where to put these things. If the destination has
+ one predecessor, insert there. Except for the exit block. */
+ if (e->dest->pred->pred_next == NULL
+ && e->dest != EXIT_BLOCK_PTR)
+ {
+ bb = e->dest;
+
+ /* Get the location correct wrt a code label, and "nice" wrt
+ a basic block note, and before everything else. */
+ tmp = bb->head;
+ if (GET_CODE (tmp) == CODE_LABEL)
+ tmp = NEXT_INSN (tmp);
+ if (GET_CODE (tmp) == NOTE
+ && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BASIC_BLOCK)
+ tmp = NEXT_INSN (tmp);
+ if (tmp == bb->head)
+ before = tmp;
+ else
+ after = PREV_INSN (tmp);
+ }
+
+ /* If the source has one successor and the edge is not abnormal,
+ insert there. Except for the entry block. */
+ else if ((e->flags & EDGE_ABNORMAL) == 0
+ && e->src->succ->succ_next == NULL
+ && e->src != ENTRY_BLOCK_PTR)
+ {
+ bb = e->src;
+ if (GET_CODE (bb->end) == JUMP_INSN)
+ {
+ /* ??? Is it possible to wind up with non-simple jumps? Perhaps
+ a jump with delay slots already filled? */
+ if (! simplejump_p (bb->end))
+ abort ();
+
+ before = bb->end;
+ }
+ else
+ {
+ /* We'd better be fallthru, or we've lost track of what's what. */
+ if ((e->flags & EDGE_FALLTHRU) == 0)
+ abort ();
+
+ after = bb->end;
+ }
+ }
+
+ /* Otherwise we must split the edge. */
+ else
+ {
+ bb = split_edge (e);
+ after = bb->end;
+ }
+
+ /* Now that we've found the spot, do the insertion. */
+ tmp = e->insns;
+ e->insns = NULL_RTX;
+ if (before)
+ {
+ emit_insns_before (tmp, before);
+ if (before == bb->head)
+ bb->head = before;
+ }
+ else
+ {
+ tmp = emit_insns_after (tmp, after);
+ if (after == bb->end)
+ bb->end = tmp;
+ }
+}
+
+/* Update the CFG for all queued instructions. */
+
+void
+commit_edge_insertions ()
+{
+ int i;
+ basic_block bb;
+
+ i = -1;
+ bb = ENTRY_BLOCK_PTR;
+ while (1)
+ {
+ edge e, next;
+
+ for (e = bb->succ; e ; e = next)
+ {
+ next = e->succ_next;
+ if (e->insns)
+ commit_one_edge_insertion (e);
+ }
+
+ if (++i >= n_basic_blocks)
+ break;
+ bb = BASIC_BLOCK (i);
+ }
+}
+
+/* Delete all unreachable basic blocks. */
+
+static void
+delete_unreachable_blocks ()
+{
+ basic_block *worklist, *tos;
+ int deleted_handler;
+ edge e;
+ int i, n;
+
+ n = n_basic_blocks;
+ tos = worklist = (basic_block *) alloca (sizeof (basic_block) * n);
+
+ /* Use basic_block->aux as a marker. Clear them all. */
+
+ for (i = 0; i < n; ++i)
+ BASIC_BLOCK (i)->aux = NULL;
+
+ /* Add our starting points to the worklist. Almost always there will
+ be only one. It isn't inconcievable that we might one day directly
+ support Fortran alternate entry points. */
+
+ for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
+ *tos++ = e->dest;
+
+ /* Iterate: find everything reachable from what we've already seen. */
+
+ while (tos != worklist)
+ {
+ basic_block b = *--tos;
+
+ /* Mark the block with a handy non-null value. */
+ b->aux = b;
+
+ for (e = b->succ; e ; e = e->succ_next)
+ if (!e->dest->aux)
+ *tos++ = e->dest;
+ }
+
+ /* Delete all unreachable basic blocks. Count down so that we don't
+ interfere with the block renumbering that happens in delete_block. */
+
+ deleted_handler = 0;
+
+ for (i = n - 1; i >= 0; --i)
+ {
+ basic_block b = BASIC_BLOCK (i);
+
+ if (b->aux != NULL)
+ /* This block was found. Tidy up the mark. */
+ b->aux = NULL;
+ else
+ deleted_handler |= delete_block (b);
+ }
+
+ /* Fix up edges that now fall through, or rather should now fall through
+ but previously required a jump around now deleted blocks. Simplify
+ the search by only examining blocks numerically adjacent, since this
+ is how find_basic_blocks created them. */
+
+ for (i = 1; i < n_basic_blocks; ++i)
+ {
+ basic_block b = BASIC_BLOCK (i - 1);
+ basic_block c = BASIC_BLOCK (i);
+ edge s;
+
+ /* We only need care for simple unconditional jumps, which implies
+ a single successor. */
+ if ((s = b->succ) != NULL
+ && s->succ_next == NULL
+ && s->dest == c
+ && ! (s->flags & EDGE_FALLTHRU))
+ tidy_fallthru_edge (s, b, c);
+ }
+
+ /* Attempt to merge blocks as made possible by edge removal. If a block
+ has only one successor, and the successor has only one predecessor,
+ they may be combined. */
+
+ for (i = 0; i < n_basic_blocks; )
+ {
+ basic_block c, b = BASIC_BLOCK (i);
+ edge s;
+
+ /* A loop because chains of blocks might be combineable. */
+ while ((s = b->succ) != NULL
+ && s->succ_next == NULL
+ && (c = s->dest) != EXIT_BLOCK_PTR
+ && c->pred->pred_next == NULL
+ && merge_blocks (s, b, c))
+ continue;
+
+ /* Don't get confused by the index shift caused by deleting blocks. */
+ i = b->index + 1;
+ }
+
+ /* If we deleted an exception handler, we may have EH region begin/end
+ blocks to remove as well. */
+ if (deleted_handler)
+ delete_eh_regions ();
+}
+
+/* Find EH regions for which there is no longer a handler, and delete them. */
+
+static void
+delete_eh_regions ()
+{
+ rtx insn;
+
+ for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
+ if (GET_CODE (insn) == NOTE)
+ {
+ if ((NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG) ||
+ (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END))
+ {
+ int num = CODE_LABEL_NUMBER (insn);
+ /* A NULL handler indicates a region is no longer needed */
+ if (get_first_handler (num) == NULL)
+ {
+ NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
+ NOTE_SOURCE_FILE (insn) = 0;
+ }
+ }
+ }
+}
+
+/* Return true if NOTE is not one of the ones that must be kept paired,
+ so that we may simply delete them. */
+
+static int
+delete_note_p (note)
+ rtx note;
+{
+ return (NOTE_LINE_NUMBER (note) == NOTE_INSN_DELETED
+ || NOTE_LINE_NUMBER (note) == NOTE_INSN_BASIC_BLOCK);
+}
+
+/* Unlink a chain of insns between START and FINISH, leaving notes
+ that must be paired. */
+
+static void
+delete_insn_chain (start, finish)
+ rtx start, finish;
+{
+ /* Unchain the insns one by one. It would be quicker to delete all
+ of these with a single unchaining, rather than one at a time, but
+ we need to keep the NOTE's. */
+
+ rtx next;
+
+ while (1)
+ {
+ next = NEXT_INSN (start);
+ if (GET_CODE (start) != NOTE || delete_note_p (start))
+ next = flow_delete_insn (start);
+
+ if (start == finish)
+ break;
+ start = next;
+ }
+}
+
+/* Delete the insns in a (non-live) block. We physically delete every
+ non-deleted-note insn, and update the flow graph appropriately.
Return nonzero if we deleted an exception handler. */
+
+/* ??? Preserving all such notes strikes me as wrong. It would be nice
+ to post-process the stream to remove empty blocks, loops, ranges, etc. */
+
static int
-delete_block (i)
- int i;
+delete_block (b)
+ basic_block b;
{
int deleted_handler = 0;
- rtx insn;
- rtx kept_head = 0;
- rtx kept_tail = 0;
+ rtx insn, end;
- /* If the head of this block is a CODE_LABEL, then it might
- be the label for an exception handler which can't be
- reached.
+ /* If the head of this block is a CODE_LABEL, then it might be the
+ label for an exception handler which can't be reached.
- We need to remove the label from the exception_handler_label
- list and remove the associated NOTE_EH_REGION_BEG and
- NOTE_EH_REGION_END notes. */
- insn = BLOCK_HEAD (i);
+ We need to remove the label from the exception_handler_label list
+ and remove the associated NOTE_EH_REGION_BEG and NOTE_EH_REGION_END
+ notes. */
+
+ insn = b->head;
if (GET_CODE (insn) == CODE_LABEL)
{
rtx x, *prev = &exception_handler_labels;
@@ -1008,8 +1635,7 @@ delete_block (i)
{
if (XEXP (x, 0) == insn)
{
- /* Found a match, splice this label out of the
- EH label list. */
+ /* Found a match, splice this label out of the EH label list. */
*prev = XEXP (x, 1);
XEXP (x, 1) = NULL_RTX;
XEXP (x, 0) = NULL_RTX;
@@ -1021,99 +1647,336 @@ delete_block (i)
}
prev = &XEXP (x, 1);
}
+
+ /* This label may be referenced by code solely for its value, or
+ referenced by static data, or something. We have determined
+ that it is not reachable, but cannot delete the label itself.
+ Save code space and continue to delete the balance of the block,
+ along with properly updating the cfg. */
+ if (!can_delete_label_p (insn))
+ {
+ /* If we've only got one of these, skip the whole deleting
+ insns thing. */
+ if (insn == b->end)
+ goto no_delete_insns;
+ insn = NEXT_INSN (insn);
+ }
}
- /* Walk the insns of the block, building a chain of NOTEs that need to be
- kept. */
- insn = BLOCK_HEAD (i);
- for (;;)
+ /* Selectively unlink the insn chain. Include any BARRIER that may
+ follow the basic block. */
+ end = next_nonnote_insn (b->end);
+ if (!end || GET_CODE (end) != BARRIER)
+ end = b->end;
+ delete_insn_chain (insn, end);
+
+no_delete_insns:
+
+ /* Remove the edges into and out of this block. Note that there may
+ indeed be edges in, if we are removing an unreachable loop. */
+ {
+ edge e, next, *q;
+
+ for (e = b->pred; e ; e = next)
+ {
+ for (q = &e->src->succ; *q != e; q = &(*q)->succ_next)
+ continue;
+ *q = e->succ_next;
+ next = e->pred_next;
+ free (e);
+ }
+ for (e = b->succ; e ; e = next)
+ {
+ for (q = &e->dest->pred; *q != e; q = &(*q)->pred_next)
+ continue;
+ *q = e->pred_next;
+ next = e->succ_next;
+ free (e);
+ }
+
+ b->pred = NULL;
+ b->succ = NULL;
+ }
+
+ /* Remove the basic block from the array, and compact behind it. */
+ expunge_block (b);
+
+ return deleted_handler;
+}
+
+/* Remove block B from the basic block array and compact behind it. */
+
+static void
+expunge_block (b)
+ basic_block b;
+{
+ int i, n = n_basic_blocks;
+
+ for (i = b->index; i + 1 < n; ++i)
{
- if (GET_CODE (insn) == BARRIER)
- abort ();
- else if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
+ basic_block x = BASIC_BLOCK (i + 1);
+ BASIC_BLOCK (i) = x;
+ x->index = i;
+ }
+
+ basic_block_info->num_elements--;
+ n_basic_blocks--;
+}
+
+/* Delete INSN by patching it out. Return the next insn. */
+
+static rtx
+flow_delete_insn (insn)
+ rtx insn;
+{
+ rtx prev = PREV_INSN (insn);
+ rtx next = NEXT_INSN (insn);
+
+ PREV_INSN (insn) = NULL_RTX;
+ NEXT_INSN (insn) = NULL_RTX;
+
+ if (prev)
+ NEXT_INSN (prev) = next;
+ if (next)
+ PREV_INSN (next) = prev;
+ else
+ set_last_insn (prev);
+
+ /* If deleting a jump, decrement the use count of the label. Deleting
+ the label itself should happen in the normal course of block merging. */
+ if (GET_CODE (insn) == JUMP_INSN && JUMP_LABEL (insn))
+ LABEL_NUSES (JUMP_LABEL (insn))--;
+
+ return next;
+}
+
+/* True if a given label can be deleted. */
+
+static int
+can_delete_label_p (label)
+ rtx label;
+{
+ rtx x;
+
+ if (LABEL_PRESERVE_P (label))
+ return 0;
+
+ for (x = forced_labels; x ; x = XEXP (x, 1))
+ if (label == XEXP (x, 0))
+ return 0;
+ for (x = label_value_list; x ; x = XEXP (x, 1))
+ if (label == XEXP (x, 0))
+ return 0;
+ for (x = exception_handler_labels; x ; x = XEXP (x, 1))
+ if (label == XEXP (x, 0))
+ return 0;
+
+ return 1;
+}
+
+/* Blocks A and B are to be merged into a single block. The insns
+ are already contiguous, hence `nomove'. */
+
+static void
+merge_blocks_nomove (a, b)
+ basic_block a, b;
+{
+ edge e;
+ rtx insn;
+ int done = 0;
+
+ /* If there was a jump out of A, delete it. */
+ if (GET_CODE (a->end) == JUMP_INSN)
+ {
+ /* If the jump was the only insn in A, turn the jump into a deleted
+ note, since we may yet not be able to merge the blocks. */
+ if (a->end == a->head)
{
- if (kept_head == 0)
- kept_head = kept_tail = insn;
- else
- {
- NEXT_INSN (kept_tail) = insn;
- PREV_INSN (insn) = kept_tail;
- kept_tail = insn;
- }
+ PUT_CODE (a->head, NOTE);
+ NOTE_LINE_NUMBER (a->head) = NOTE_INSN_DELETED;
+ NOTE_SOURCE_FILE (a->head) = 0;
+ }
+ else
+ {
+ rtx tmp = a->end;
+ a->end = prev_nonnote_insn (tmp);
+ flow_delete_insn (tmp);
}
- if (insn == BLOCK_END (i))
- break;
- insn = NEXT_INSN (insn);
}
- insn = NEXT_INSN (insn);
- /* BARRIERs are between basic blocks, not part of one.
- Delete a BARRIER if the preceding jump is deleted.
- We cannot alter a BARRIER into a NOTE
- because it is too short; but we can really delete
- it because it is not part of a basic block. */
- if (insn != 0 && GET_CODE (insn) == BARRIER)
- insn = NEXT_INSN (insn);
+ /* By definition, there should only be one successor of A, and that is
+ B. Free that edge struct. */
+ free (a->succ);
- /* Now unchain all of the block, and put the chain of kept notes in its
- place. */
- if (kept_head == 0)
+ /* Adjust the edges out of B for the new owner. */
+ for (e = b->succ; e ; e = e->succ_next)
+ e->src = a;
+ a->succ = b->succ;
+
+ /* If there was a CODE_LABEL beginning B, delete it. */
+ insn = b->head;
+ if (GET_CODE (insn) == CODE_LABEL)
{
- NEXT_INSN (PREV_INSN (BLOCK_HEAD (i))) = insn;
- if (insn != 0)
- PREV_INSN (insn) = PREV_INSN (BLOCK_HEAD (i));
- else
- set_last_insn (PREV_INSN (BLOCK_HEAD(i)));
+ /* Detect basic blocks with nothing but a label. This can happen
+ in particular at the end of a function. */
+ if (insn == b->end)
+ done = 1;
+ insn = flow_delete_insn (insn);
}
- else
+
+ /* Delete the basic block note. */
+ if (GET_CODE (insn) == NOTE
+ && NOTE_LINE_NUMBER (insn) == NOTE_INSN_BASIC_BLOCK)
{
- NEXT_INSN (PREV_INSN (BLOCK_HEAD (i))) = kept_head;
- if (insn != 0)
- PREV_INSN (insn) = kept_tail;
+ if (insn == b->end)
+ done = 1;
+ insn = flow_delete_insn (insn);
+ }
- PREV_INSN (kept_head) = PREV_INSN (BLOCK_HEAD (i));
- NEXT_INSN (kept_tail) = insn;
+ /* Reassociate the insns of B with A. */
+ if (!done)
+ {
+ BLOCK_FOR_INSN (insn) = a;
+ while (insn != b->end)
+ {
+ insn = NEXT_INSN (insn);
+ BLOCK_FOR_INSN (insn) = a;
+ }
+ a->end = insn;
+ }
+
+ /* Compact the basic block array. */
+ expunge_block (b);
+}
- /* This must happen after NEXT_INSN (kept_tail) has been reinitialized
- since set_last_insn will abort if it detects a non-NULL NEXT_INSN
- field in its argument. */
- if (insn == NULL_RTX)
- set_last_insn (kept_tail);
+/* Attempt to merge basic blocks that are potentially non-adjacent.
+ Return true iff the attempt succeeded. */
+
+static int
+merge_blocks (e, b, c)
+ edge e;
+ basic_block b, c;
+{
+ /* If B has a fallthru edge to C, no need to move anything. */
+ if (!(e->flags & EDGE_FALLTHRU))
+ {
+ /* ??? From here on out we must make sure to not munge nesting
+ of exception regions and lexical blocks. Need to think about
+ these cases before this gets implemented. */
+ return 0;
+
+ /* If C has an outgoing fallthru, and B does not have an incoming
+ fallthru, move B before C. The later clause is somewhat arbitrary,
+ but avoids modifying blocks other than the two we've been given. */
+
+ /* Otherwise, move C after B. If C had a fallthru, which doesn't
+ happen to be the physical successor to B, insert an unconditional
+ branch. If C already ended with a conditional branch, the new
+ jump must go in a new basic block D. */
+ }
+
+ /* If a label still appears somewhere, we cannot delete the label, which
+ means we cannot merge the blocks. We have still won a tad by tidying
+ the interface between the two blocks. */
+ if (GET_CODE (c->head) == CODE_LABEL
+ && ! can_delete_label_p (c->head))
+ {
+ tidy_fallthru_edge (e, b, c);
+ return 0;
}
- /* Each time we delete some basic blocks,
- see if there is a jump around them that is
- being turned into a no-op. If so, delete it. */
+ merge_blocks_nomove (b, c);
+ return 1;
+}
+
+/* The given edge should potentially a fallthru edge. If that is in
+ fact true, delete the unconditional jump and barriers that are in
+ the way. */
+
+static void
+tidy_fallthru_edge (e, b, c)
+ edge e;
+ basic_block b, c;
+{
+ rtx p, q, h;
- if (block_live_static[i - 1])
+ /* ??? In a late-running flow pass, other folks may have deleted basic
+ blocks by nopping out blocks, leaving multiple BARRIERs between here
+ and the target label. They ought to be chastized and fixed.
+
+ In the mean time, search for the last barrier in a sequence of
+ barriers and notes. */
+
+ q = NEXT_INSN (b->end);
+ do
{
- register int j;
- for (j = i + 1; j < n_basic_blocks; j++)
- if (block_live_static[j])
- {
- rtx label;
- insn = BLOCK_END (i - 1);
- if (GET_CODE (insn) == JUMP_INSN
- /* An unconditional jump is the only possibility
- we must check for, since a conditional one
- would make these blocks live. */
- && simplejump_p (insn)
- && (label = XEXP (SET_SRC (PATTERN (insn)), 0), 1)
- && INSN_UID (label) != 0
- && BLOCK_NUM (label) == j)
- {
- PUT_CODE (insn, NOTE);
- NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
- NOTE_SOURCE_FILE (insn) = 0;
- if (GET_CODE (NEXT_INSN (insn)) != BARRIER)
- abort ();
- delete_insn (NEXT_INSN (insn));
- }
- break;
- }
+ p = q;
+ q = next_nonnote_insn (q);
}
+ while (GET_CODE (q) == BARRIER);
- return deleted_handler;
+ /* Assert that we now actually do fall through. */
+ h = c->head;
+ if (GET_CODE (h) == NOTE)
+ h = next_nonnote_insn (h);
+ if (q != h)
+ return;
+
+ /* Remove what will soon cease being the jump insn from the source block.
+ If block B consisted only of this single jump, turn it into a deleted
+ note. */
+ q = b->end;
+ if (GET_CODE (q) == JUMP_INSN)
+ {
+ if (b->head == q)
+ {
+ PUT_CODE (q, NOTE);
+ NOTE_LINE_NUMBER (q) = NOTE_INSN_DELETED;
+ NOTE_SOURCE_FILE (q) = 0;
+ }
+ else
+ b->end = q = PREV_INSN (q);
+ }
+
+ /* Selectively unlink the sequence. */
+ delete_insn_chain (NEXT_INSN (q), p);
+
+ e->flags |= EDGE_FALLTHRU;
+}
+
+/* Discover and record the loop depth at the head of each basic block. */
+
+static void
+calculate_loop_depth (insns)
+ rtx insns;
+{
+ basic_block bb;
+ rtx insn;
+ int i = 0, depth = 1;
+
+ bb = BASIC_BLOCK (i);
+ for (insn = insns; insn ; insn = NEXT_INSN (insn))
+ {
+ if (insn == bb->head)
+ {
+ bb->loop_depth = depth;
+ if (++i >= n_basic_blocks)
+ break;
+ bb = BASIC_BLOCK (i);
+ }
+
+ if (GET_CODE (insn) == NOTE)
+ {
+ if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
+ depth++;
+ else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
+ depth--;
+
+ /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error. */
+ if (depth == 0)
+ abort ();
+ }
+ }
}
/* Perform data flow analysis.
@@ -1143,6 +2006,9 @@ life_analysis (f, nregs, file)
SET_HARD_REG_BIT (elim_reg_set, FRAME_POINTER_REGNUM);
#endif
+ /* Allocate a bitmap to be filled in by record_volatile_insns. */
+ uid_volatile = BITMAP_ALLOCA ();
+
/* We want alias analysis information for local dead store elimination. */
init_alias_analysis ();
life_analysis_1 (f, nregs);
@@ -1151,40 +2017,29 @@ life_analysis (f, nregs, file)
if (file)
dump_flow_info (file);
+ BITMAP_FREE (uid_volatile);
free_basic_block_vars (1);
}
/* Free the variables allocated by find_basic_blocks.
- KEEP_HEAD_END_P is non-zero if BLOCK_HEAD and BLOCK_END
- are not to be freed. */
+ KEEP_HEAD_END_P is non-zero if basic_block_info is not to be freed. */
void
free_basic_block_vars (keep_head_end_p)
int keep_head_end_p;
{
- if (basic_block_loop_depth)
+ if (basic_block_for_insn)
{
- free (basic_block_loop_depth);
- basic_block_loop_depth = 0;
- }
- if (uid_block_number)
- {
- free (uid_block_number);
- uid_block_number = 0;
- }
- if (uid_volatile)
- {
- free (uid_volatile);
- uid_volatile = 0;
+ VARRAY_FREE (basic_block_for_insn);
+ basic_block_for_insn = NULL;
}
- if (! keep_head_end_p && x_basic_block_head)
+ if (! keep_head_end_p)
{
- free (x_basic_block_head);
- x_basic_block_head = 0;
- free (x_basic_block_end);
- x_basic_block_end = 0;
+ clear_edges ();
+ VARRAY_FREE (basic_block_info);
+ n_basic_blocks = 0;
}
}
@@ -1277,12 +2132,12 @@ record_volatile_insns (f)
{
enum rtx_code code1 = GET_CODE (insn);
if (code1 == CALL_INSN)
- INSN_VOLATILE (insn) = 1;
+ SET_INSN_VOLATILE (insn);
else if (code1 == INSN || code1 == JUMP_INSN)
{
if (GET_CODE (PATTERN (insn)) != USE
&& volatile_refs_p (PATTERN (insn)))
- INSN_VOLATILE (insn) = 1;
+ SET_INSN_VOLATILE (insn);
/* A SET that makes space on the stack cannot be dead.
(Such SETs occur only for allocating variable-size data,
@@ -1298,7 +2153,7 @@ record_volatile_insns (f)
&& GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
#endif
&& XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx)
- INSN_VOLATILE (insn) = 1;
+ SET_INSN_VOLATILE (insn);
/* Delete (in effect) any obvious no-op moves. */
else if (noop_move_p (insn))
@@ -1324,18 +2179,18 @@ mark_regs_live_at_end (set)
{
int i;
-#ifdef EXIT_IGNORE_STACK
+ /* If exiting needs the right stack value, consider the stack pointer
+ live at the end of the function. */
if (! EXIT_IGNORE_STACK
|| (! FRAME_POINTER_REQUIRED
&& ! current_function_calls_alloca
&& flag_omit_frame_pointer)
|| current_function_sp_is_unchanging)
-#endif
- /* If exiting needs the right stack value,
- consider the stack pointer live at the end of the function. */
- SET_REGNO_REG_SET (set, STACK_POINTER_REGNUM);
+ {
+ SET_REGNO_REG_SET (set, STACK_POINTER_REGNUM);
+ }
- /* Mark the frame pointer is needed at the end of the function. If
+ /* Mark the frame pointer if needed at the end of the function. If
we end up eliminating it, it will be removed from the live list
of each basic block by reload. */
@@ -1345,8 +2200,7 @@ mark_regs_live_at_end (set)
SET_REGNO_REG_SET (set, HARD_FRAME_POINTER_REGNUM);
#endif
-
- /* Mark all global registers and all registers used by the epilogue
+ /* Mark all global registers, and all registers used by the epilogue
as being live at the end of the function since they may be
referenced by our caller. */
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
@@ -1356,6 +2210,8 @@ mark_regs_live_at_end (set)
#endif
)
SET_REGNO_REG_SET (set, i);
+
+ /* ??? Mark function return value here rather than as uses. */
}
/* Determine which registers are live at the start of each
@@ -1372,22 +2228,9 @@ life_analysis_1 (f, nregs)
{
int first_pass;
int changed;
- /* For each basic block, a bitmask of regs
- live on exit from the block. */
- regset *basic_block_live_at_end;
- /* For each basic block, a bitmask of regs
- live on entry to a successor-block of this block.
- If this does not match basic_block_live_at_end,
- that must be updated, and the block must be rescanned. */
- regset *basic_block_new_live_at_end;
- /* For each basic block, a bitmask of regs
- whose liveness at the end of the basic block
- can make a difference in which regs are live on entry to the block.
- These are the regs that are set within the basic block,
- possibly excluding those that are used after they are set. */
- regset *basic_block_significant;
register int i;
char save_regs_ever_live[FIRST_PSEUDO_REGISTER];
+ regset *new_live_at_end;
struct obstack flow_obstack;
@@ -1395,46 +2238,26 @@ life_analysis_1 (f, nregs)
max_regno = nregs;
- /* The post-reload life analysis have (on a global basis) the same registers
- live as was computed by reload itself.
-
- Otherwise elimination offsets and such may be incorrect.
-
- Reload will make some registers as live even though they do not appear
- in the rtl. */
- if (reload_completed)
- bcopy (regs_ever_live, save_regs_ever_live, (sizeof (regs_ever_live)));
-
- bzero (regs_ever_live, sizeof regs_ever_live);
-
/* Allocate and zero out many data structures
that will record the data from lifetime analysis. */
allocate_for_life_analysis ();
reg_next_use = (rtx *) alloca (nregs * sizeof (rtx));
- bzero ((char *) reg_next_use, nregs * sizeof (rtx));
+ memset (reg_next_use, 0, nregs * sizeof (rtx));
- /* Set up several regset-vectors used internally within this function.
+ /* Set up regset-vectors used internally within this function.
Their meanings are documented above, with their declarations. */
- basic_block_live_at_end
- = (regset *) alloca (n_basic_blocks * sizeof (regset));
+ new_live_at_end = (regset *) alloca ((n_basic_blocks + 1) * sizeof (regset));
+ init_regset_vector (new_live_at_end, n_basic_blocks + 1, &flow_obstack);
- /* Don't use alloca since that leads to a crash rather than an error message
- if there isn't enough space.
- Don't use oballoc since we may need to allocate other things during
- this function on the temporary obstack. */
- init_regset_vector (basic_block_live_at_end, n_basic_blocks, &flow_obstack);
+ /* Stick these vectors into the AUX field of the basic block, so that
+ we don't have to keep going through the index. */
- basic_block_new_live_at_end
- = (regset *) alloca (n_basic_blocks * sizeof (regset));
- init_regset_vector (basic_block_new_live_at_end, n_basic_blocks,
- &flow_obstack);
-
- basic_block_significant
- = (regset *) alloca (n_basic_blocks * sizeof (regset));
- init_regset_vector (basic_block_significant, n_basic_blocks, &flow_obstack);
+ for (i = 0; i < n_basic_blocks; ++i)
+ BASIC_BLOCK (i)->aux = new_live_at_end[i];
+ ENTRY_BLOCK_PTR->aux = new_live_at_end[i];
/* Assume that the stack pointer is unchanging if alloca hasn't been used.
This will be cleared by record_volatile_insns if it encounters an insn
@@ -1445,11 +2268,31 @@ life_analysis_1 (f, nregs)
if (n_basic_blocks > 0)
{
- mark_regs_live_at_end (basic_block_live_at_end[n_basic_blocks - 1]);
- COPY_REG_SET (basic_block_new_live_at_end[n_basic_blocks - 1],
- basic_block_live_at_end[n_basic_blocks - 1]);
+ regset theend;
+ register edge e;
+
+ theend = EXIT_BLOCK_PTR->global_live_at_start;
+ mark_regs_live_at_end (theend);
+
+ /* Propogate this exit data to each of EXIT's predecessors. */
+ for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
+ {
+ COPY_REG_SET (e->src->global_live_at_end, theend);
+ COPY_REG_SET ((regset) e->src->aux, theend);
+ }
}
+ /* The post-reload life analysis have (on a global basis) the same registers
+ live as was computed by reload itself.
+
+ Otherwise elimination offsets and such may be incorrect.
+
+ Reload will make some registers as live even though they do not appear
+ in the rtl. */
+ if (reload_completed)
+ memcpy (save_regs_ever_live, regs_ever_live, sizeof (regs_ever_live));
+ memset (regs_ever_live, 0, sizeof regs_ever_live);
+
/* Propagate life info through the basic blocks
around the graph of basic blocks.
@@ -1467,6 +2310,7 @@ life_analysis_1 (f, nregs)
changed = 0;
for (i = n_basic_blocks - 1; i >= 0; i--)
{
+ basic_block bb = BASIC_BLOCK (i);
int consider = first_pass;
int must_rescan = first_pass;
register int j;
@@ -1483,11 +2327,10 @@ life_analysis_1 (f, nregs)
is one of the significant regs of this basic block). */
EXECUTE_IF_AND_COMPL_IN_REG_SET
- (basic_block_new_live_at_end[i],
- basic_block_live_at_end[i], 0, j,
+ ((regset) bb->aux, bb->global_live_at_end, 0, j,
{
consider = 1;
- if (REGNO_REG_SET_P (basic_block_significant[i], j))
+ if (REGNO_REG_SET_P (bb->local_set, j))
{
must_rescan = 1;
goto done;
@@ -1507,41 +2350,35 @@ life_analysis_1 (f, nregs)
/* No complete rescan needed;
just record those variables newly known live at end
as live at start as well. */
- IOR_AND_COMPL_REG_SET (basic_block_live_at_start[i],
- basic_block_new_live_at_end[i],
- basic_block_live_at_end[i]);
+ IOR_AND_COMPL_REG_SET (bb->global_live_at_start,
+ (regset) bb->aux,
+ bb->global_live_at_end);
- IOR_AND_COMPL_REG_SET (basic_block_live_at_end[i],
- basic_block_new_live_at_end[i],
- basic_block_live_at_end[i]);
+ IOR_AND_COMPL_REG_SET (bb->global_live_at_end,
+ (regset) bb->aux,
+ bb->global_live_at_end);
}
else
{
/* Update the basic_block_live_at_start
by propagation backwards through the block. */
- COPY_REG_SET (basic_block_live_at_end[i],
- basic_block_new_live_at_end[i]);
- COPY_REG_SET (basic_block_live_at_start[i],
- basic_block_live_at_end[i]);
- propagate_block (basic_block_live_at_start[i],
- BLOCK_HEAD (i), BLOCK_END (i), 0,
- first_pass ? basic_block_significant[i]
- : (regset) 0,
+ COPY_REG_SET (bb->global_live_at_end, (regset) bb->aux);
+ COPY_REG_SET (bb->global_live_at_start,
+ bb->global_live_at_end);
+ propagate_block (bb->global_live_at_start,
+ bb->head, bb->end, 0,
+ first_pass ? bb->local_set : (regset) 0,
i);
}
+ /* Update the new_live_at_end's of the block's predecessors. */
{
- int_list_ptr p;
+ register edge e;
- /* Update the basic_block_new_live_at_end's of
- all the blocks that reach this one. */
- for (p = basic_block_pred[i]; p; p = p->next)
- {
- register int from_block = INT_LIST_VAL (p);
- IOR_REG_SET (basic_block_new_live_at_end[from_block],
- basic_block_live_at_start[i]);
- }
+ for (e = bb->pred; e ; e = e->pred_next)
+ IOR_REG_SET ((regset) e->src->aux, bb->global_live_at_start);
}
+
#ifdef USE_C_ALLOCA
alloca (0);
#endif
@@ -1555,57 +2392,36 @@ life_analysis_1 (f, nregs)
one basic block. */
if (n_basic_blocks > 0)
- EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[0],
+ EXECUTE_IF_SET_IN_REG_SET (BASIC_BLOCK (0)->global_live_at_start,
FIRST_PSEUDO_REGISTER, i,
{
REG_BASIC_BLOCK (i) = REG_BLOCK_GLOBAL;
});
- /* Now the life information is accurate.
- Make one more pass over each basic block
- to delete dead stores, create autoincrement addressing
- and record how many times each register is used, is set, or dies.
-
- To save time, we operate directly in basic_block_live_at_end[i],
- thus destroying it (in fact, converting it into a copy of
- basic_block_live_at_start[i]). This is ok now because
- basic_block_live_at_end[i] is no longer used past this point. */
+ /* Now the life information is accurate. Make one more pass over each
+ basic block to delete dead stores, create autoincrement addressing
+ and record how many times each register is used, is set, or dies. */
for (i = 0; i < n_basic_blocks; i++)
{
- propagate_block (basic_block_live_at_end[i],
- BLOCK_HEAD (i), BLOCK_END (i), 1,
- (regset) 0, i);
+ basic_block bb = BASIC_BLOCK (i);
+
+ /* We start with global_live_at_end to determine which stores are
+ dead. This process is destructive, and we wish to preserve the
+ contents of global_live_at_end for posterity. Fortunately,
+ new_live_at_end, due to the way we converged on a solution,
+ contains a duplicate of global_live_at_end that we can kill. */
+ propagate_block ((regset) bb->aux, bb->head, bb->end, 1, (regset) 0, i);
+
#ifdef USE_C_ALLOCA
alloca (0);
#endif
}
-#if 0
- /* Something live during a setjmp should not be put in a register
- on certain machines which restore regs from stack frames
- rather than from the jmpbuf.
- But we don't need to do this for the user's variables, since
- ANSI says only volatile variables need this. */
-#ifdef LONGJMP_RESTORE_FROM_STACK
- EXECUTE_IF_SET_IN_REG_SET (regs_live_at_setjmp,
- FIRST_PSEUDO_REGISTER, i,
- {
- if (regno_reg_rtx[i] != 0
- && ! REG_USERVAR_P (regno_reg_rtx[i]))
- {
- REG_LIVE_LENGTH (i) = -1;
- REG_BASIC_BLOCK (i) = -1;
- }
- });
-#endif
-#endif
-
- /* We have a problem with any pseudoreg that
- lives across the setjmp. ANSI says that if a
- user variable does not change in value
- between the setjmp and the longjmp, then the longjmp preserves it.
- This includes longjmp from a place where the pseudo appears dead.
+ /* We have a problem with any pseudoreg that lives across the setjmp.
+ ANSI says that if a user variable does not change in value between
+ the setjmp and the longjmp, then the longjmp preserves it. This
+ includes longjmp from a place where the pseudo appears dead.
(In principle, the value still exists if it is in scope.)
If the pseudo goes in a hard reg, some other value may occupy
that hard reg where this pseudo is dead, thus clobbering the pseudo.
@@ -1622,16 +2438,14 @@ life_analysis_1 (f, nregs)
/* Restore regs_ever_live that was provided by reload. */
if (reload_completed)
- bcopy (save_regs_ever_live, regs_ever_live, (sizeof (regs_ever_live)));
-
- free_regset_vector (basic_block_live_at_end, n_basic_blocks);
- free_regset_vector (basic_block_new_live_at_end, n_basic_blocks);
- free_regset_vector (basic_block_significant, n_basic_blocks);
- basic_block_live_at_end = (regset *)0;
- basic_block_new_live_at_end = (regset *)0;
- basic_block_significant = (regset *)0;
+ memcpy (regs_ever_live, save_regs_ever_live, sizeof (regs_ever_live));
+ free_regset_vector (new_live_at_end, n_basic_blocks);
obstack_free (&flow_obstack, NULL_PTR);
+
+ for (i = 0; i < n_basic_blocks; ++i)
+ BASIC_BLOCK (i)->aux = NULL;
+ ENTRY_BLOCK_PTR->aux = NULL;
}
/* Subroutines of life analysis. */
@@ -1655,10 +2469,19 @@ allocate_for_life_analysis ()
for (i = 0; i < max_regno; i++)
REG_N_SETS (i) = 0;
- basic_block_live_at_start
- = (regset *) oballoc (n_basic_blocks * sizeof (regset));
- init_regset_vector (basic_block_live_at_start, n_basic_blocks,
- function_obstack);
+ for (i = 0; i < n_basic_blocks; i++)
+ {
+ basic_block bb = BASIC_BLOCK (i);
+
+ bb->local_set = OBSTACK_ALLOC_REG_SET (function_obstack);
+ bb->global_live_at_start = OBSTACK_ALLOC_REG_SET (function_obstack);
+ bb->global_live_at_end = OBSTACK_ALLOC_REG_SET (function_obstack);
+ }
+
+ ENTRY_BLOCK_PTR->global_live_at_end
+ = OBSTACK_ALLOC_REG_SET (function_obstack);
+ EXIT_BLOCK_PTR->global_live_at_start
+ = OBSTACK_ALLOC_REG_SET (function_obstack);
regs_live_at_setjmp = OBSTACK_ALLOC_REG_SET (function_obstack);
CLEAR_REG_SET (regs_live_at_setjmp);
@@ -1730,10 +2553,11 @@ propagate_block (old, first, last, final, significant, bnum)
regset live;
regset dead;
- /* The loop depth may change in the middle of a basic block. Since we
- scan from end to beginning, we start with the depth at the end of the
- current basic block, and adjust as we pass ends and starts of loops. */
- loop_depth = basic_block_loop_depth[bnum];
+ /* Find the loop depth for this block. Ignore loop level changes in the
+ middle of the basic block -- for register allocation purposes, the
+ important uses will be in the blocks wholely contained within the loop
+ not in the loop pre-header or post-trailer. */
+ loop_depth = BASIC_BLOCK (bnum)->loop_depth;
dead = ALLOCA_REG_SET ();
live = ALLOCA_REG_SET ();
@@ -1741,19 +2565,6 @@ propagate_block (old, first, last, final, significant, bnum)
cc0_live = 0;
mem_set_list = NULL_RTX;
- /* Include any notes at the end of the block in the scan.
- This is in case the block ends with a call to setjmp. */
-
- while (NEXT_INSN (last) != 0 && GET_CODE (NEXT_INSN (last)) == NOTE)
- {
- /* Look for loop boundaries, we are going forward here. */
- last = NEXT_INSN (last);
- if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_BEG)
- loop_depth++;
- else if (NOTE_LINE_NUMBER (last) == NOTE_INSN_LOOP_END)
- loop_depth--;
- }
-
if (final)
{
register int i;
@@ -1774,18 +2585,6 @@ propagate_block (old, first, last, final, significant, bnum)
if (GET_CODE (insn) == NOTE)
{
- /* Look for loop boundaries, remembering that we are going
- backwards. */
- if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
- loop_depth++;
- else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
- loop_depth--;
-
- /* If we have LOOP_DEPTH == 0, there has been a bookkeeping error.
- Abort now rather than setting register status incorrectly. */
- if (loop_depth == 0)
- abort ();
-
/* If this is a call to `setjmp' et al,
warn if any non-volatile datum is live. */
@@ -2207,7 +3006,7 @@ regno_uninitialized (regno)
|| FUNCTION_ARG_REGNO_P (regno))))
return 0;
- return REGNO_REG_SET_P (basic_block_live_at_start[0], regno);
+ return REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start, regno);
}
/* 1 if register REGNO was alive at a place where `setjmp' was called
@@ -2222,7 +3021,7 @@ regno_clobbered_at_setjmp (regno)
return 0;
return ((REG_N_SETS (regno) > 1
- || REGNO_REG_SET_P (basic_block_live_at_start[0], regno))
+ || REGNO_REG_SET_P (BASIC_BLOCK (0)->global_live_at_start, regno))
&& REGNO_REG_SET_P (regs_live_at_setjmp, regno));
}
@@ -2611,21 +3410,16 @@ find_auto_inc (needed, x, insn)
Change it to q = p, ...*q..., q = q+size.
Then fall into the usual case. */
rtx insns, temp;
+ basic_block bb;
start_sequence ();
emit_move_insn (q, addr);
insns = get_insns ();
end_sequence ();
- /* If anything in INSNS have UID's that don't fit within the
- extra space we allocate earlier, we can't make this auto-inc.
- This should never happen. */
+ bb = BLOCK_FOR_INSN (insn);
for (temp = insns; temp; temp = NEXT_INSN (temp))
- {
- if (INSN_UID (temp) > max_uid_for_flow)
- return;
- BLOCK_NUM (temp) = BLOCK_NUM (insn);
- }
+ set_block_for_insn (temp, bb);
/* If we can't make the auto-inc, or can't make the
replacement into Y, exit. There's no point in making
@@ -2643,8 +3437,8 @@ find_auto_inc (needed, x, insn)
new insn(s) and do the updates. */
emit_insns_before (insns, insn);
- if (BLOCK_HEAD (BLOCK_NUM (insn)) == insn)
- BLOCK_HEAD (BLOCK_NUM (insn)) = insns;
+ if (BLOCK_FOR_INSN (insn)->head == insn)
+ BLOCK_FOR_INSN (insn)->head = insns;
/* INCR will become a NOTE and INSN won't contain a
use of ADDR. If a use of ADDR was just placed in
@@ -3046,14 +3840,11 @@ mark_used_regs (needed, live, x, final, insn)
/* If exiting needs the right stack value, consider this insn as
using the stack pointer. In any event, consider it as using
all global registers and all registers used by return. */
-
-#ifdef EXIT_IGNORE_STACK
if (! EXIT_IGNORE_STACK
|| (! FRAME_POINTER_REQUIRED
&& ! current_function_calls_alloca
&& flag_omit_frame_pointer)
|| current_function_sp_is_unchanging)
-#endif
SET_REGNO_REG_SET (live, STACK_POINTER_REGNUM);
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
@@ -3293,7 +4084,6 @@ dump_flow_info (file)
static char *reg_class_names[] = REG_CLASS_NAMES;
fprintf (file, "%d registers.\n", max_regno);
-
for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
if (REG_N_REFS (i))
{
@@ -3332,8 +4122,91 @@ dump_flow_info (file)
fprintf (file, "; pointer");
fprintf (file, ".\n");
}
+
fprintf (file, "\n%d basic blocks.\n", n_basic_blocks);
- dump_bb_data (file, basic_block_pred, basic_block_succ, 1);
+ for (i = 0; i < n_basic_blocks; i++)
+ {
+ register basic_block bb = BASIC_BLOCK (i);
+ register int regno;
+ register edge e;
+
+ fprintf (file, "\nBasic block %d: first insn %d, last %d.\n",
+ i, INSN_UID (bb->head), INSN_UID (bb->end));
+
+ fprintf (file, "Predecessors: ");
+ for (e = bb->pred; e ; e = e->pred_next)
+ dump_edge_info (file, e, 0);
+
+ fprintf (file, "\nSuccessors: ");
+ for (e = bb->succ; e ; e = e->succ_next)
+ dump_edge_info (file, e, 1);
+
+ fprintf (file, "\nRegisters live at start:");
+ if (bb->global_live_at_start)
+ {
+ for (regno = 0; regno < max_regno; regno++)
+ if (REGNO_REG_SET_P (bb->global_live_at_start, regno))
+ fprintf (file, " %d", regno);
+ }
+ else
+ fprintf (file, " n/a");
+
+ fprintf (file, "\nRegisters live at end:");
+ if (bb->global_live_at_end)
+ {
+ for (regno = 0; regno < max_regno; regno++)
+ if (REGNO_REG_SET_P (bb->global_live_at_end, regno))
+ fprintf (file, " %d", regno);
+ }
+ else
+ fprintf (file, " n/a");
+
+ putc('\n', file);
+ }
+
+ putc('\n', file);
+}
+
+static void
+dump_edge_info (file, e, do_succ)
+ FILE *file;
+ edge e;
+ int do_succ;
+{
+ basic_block side = (do_succ ? e->dest : e->src);
+
+ if (side == ENTRY_BLOCK_PTR)
+ fputs (" ENTRY", file);
+ else if (side == EXIT_BLOCK_PTR)
+ fputs (" EXIT", file);
+ else
+ fprintf (file, " %d", side->index);
+
+ if (e->flags)
+ {
+ static char * bitnames[] = {
+ "fallthru", "crit", "ab", "abcall", "eh", "fake"
+ };
+ int comma = 0;
+ int i, flags = e->flags;
+
+ fputc (' ', file);
+ fputc ('(', file);
+ for (i = 0; flags; i++)
+ if (flags & (1 << i))
+ {
+ flags &= ~(1 << i);
+
+ if (comma)
+ fputc (',', file);
+ if (i < (int)(sizeof (bitnames) / sizeof (*bitnames)))
+ fputs (bitnames[i], file);
+ else
+ fprintf (file, "%d", i);
+ comma = 1;
+ }
+ fputc (')', file);
+ }
}
@@ -3349,34 +4222,35 @@ print_rtl_with_bb (outf, rtx_first)
if (rtx_first == 0)
fprintf (outf, "(nil)\n");
-
else
{
- int i, bb;
+ int i;
enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB };
int max_uid = get_max_uid ();
- int *start = (int *) alloca (max_uid * sizeof (int));
- int *end = (int *) alloca (max_uid * sizeof (int));
+ basic_block *start = alloca (max_uid * sizeof (basic_block));
+ basic_block *end = alloca (max_uid * sizeof (basic_block));
enum bb_state *in_bb_p = (enum bb_state *)
alloca (max_uid * sizeof (enum bb_state));
- for (i = 0; i < max_uid; i++)
- {
- start[i] = end[i] = -1;
- in_bb_p[i] = NOT_IN_BB;
- }
+ memset (start, 0, max_uid * sizeof (basic_block));
+ memset (end, 0, max_uid * sizeof (basic_block));
+ memset (in_bb_p, 0, max_uid * sizeof (enum bb_state));
- for (i = n_basic_blocks-1; i >= 0; i--)
+ for (i = n_basic_blocks - 1; i >= 0; i--)
{
+ basic_block bb = BASIC_BLOCK (i);
rtx x;
- start[INSN_UID (BLOCK_HEAD (i))] = i;
- end[INSN_UID (BLOCK_END (i))] = i;
- for (x = BLOCK_HEAD (i); x != NULL_RTX; x = NEXT_INSN (x))
+
+ start[INSN_UID (bb->head)] = bb;
+ end[INSN_UID (bb->end)] = bb;
+ for (x = bb->head; x != NULL_RTX; x = NEXT_INSN (x))
{
- in_bb_p[ INSN_UID(x)]
- = (in_bb_p[ INSN_UID(x)] == NOT_IN_BB)
- ? IN_ONE_BB : IN_MULTIPLE_BB;
- if (x == BLOCK_END (i))
+ enum bb_state state = IN_MULTIPLE_BB;
+ if (in_bb_p[INSN_UID(x)] == NOT_IN_BB)
+ state = IN_ONE_BB;
+ in_bb_p[INSN_UID(x)] = state;
+
+ if (x == bb->end)
break;
}
}
@@ -3384,13 +4258,14 @@ print_rtl_with_bb (outf, rtx_first)
for (tmp_rtx = rtx_first; NULL != tmp_rtx; tmp_rtx = NEXT_INSN (tmp_rtx))
{
int did_output;
+ basic_block bb;
- if ((bb = start[INSN_UID (tmp_rtx)]) >= 0)
+ if ((bb = start[INSN_UID (tmp_rtx)]) != NULL)
{
fprintf (outf, ";; Start of basic block %d, registers live:",
- bb);
+ bb->index);
- EXECUTE_IF_SET_IN_REG_SET (basic_block_live_at_start[bb], 0, i,
+ EXECUTE_IF_SET_IN_REG_SET (bb->global_live_at_start, 0, i,
{
fprintf (outf, " %d", i);
if (i < FIRST_PSEUDO_REGISTER)
@@ -3405,13 +4280,13 @@ print_rtl_with_bb (outf, rtx_first)
&& GET_CODE (tmp_rtx) != BARRIER
&& ! obey_regdecls)
fprintf (outf, ";; Insn is not within a basic block\n");
- else if (in_bb_p[ INSN_UID(tmp_rtx)] == IN_MULTIPLE_BB)
+ else if (in_bb_p[INSN_UID(tmp_rtx)] == IN_MULTIPLE_BB)
fprintf (outf, ";; Insn is in multiple basic blocks\n");
did_output = print_rtl_single (outf, tmp_rtx);
- if ((bb = end[INSN_UID (tmp_rtx)]) >= 0)
- fprintf (outf, ";; End of basic block %d\n", bb);
+ if ((bb = end[INSN_UID (tmp_rtx)]) != NULL)
+ fprintf (outf, ";; End of basic block %d\n", bb->index);
if (did_output)
putc ('\n', outf);
@@ -3509,7 +4384,8 @@ add_pred_succ (pred_bb, succ_bb, s_preds, s_succs, num_preds, num_succs)
}
}
-/* Compute the predecessors and successors for each block. */
+/* Convert edge lists into pred/succ lists for backward compatibility. */
+
void
compute_preds_succs (s_preds, s_succs, num_preds, num_succs)
int_list_ptr *s_preds;
@@ -3517,38 +4393,26 @@ compute_preds_succs (s_preds, s_succs, num_preds, num_succs)
int *num_preds;
int *num_succs;
{
- int bb;
+ int i, n = n_basic_blocks;
+ edge e;
- bzero ((char *) s_preds, n_basic_blocks * sizeof (int_list_ptr));
- bzero ((char *) s_succs, n_basic_blocks * sizeof (int_list_ptr));
- bzero ((char *) num_preds, n_basic_blocks * sizeof (int));
- bzero ((char *) num_succs, n_basic_blocks * sizeof (int));
+ memset (s_preds, 0, n_basic_blocks * sizeof (int_list_ptr));
+ memset (s_succs, 0, n_basic_blocks * sizeof (int_list_ptr));
+ memset (num_preds, 0, n_basic_blocks * sizeof (int));
+ memset (num_succs, 0, n_basic_blocks * sizeof (int));
- /* It's somewhat stupid to simply copy the information. The passes
- which use this function ought to be changed to refer directly to
- basic_block_succ and its relatives. */
- for (bb = 0; bb < n_basic_blocks; bb++)
+ for (i = 0; i < n; ++i)
{
- rtx jump = BLOCK_END (bb);
- enum rtx_code code = GET_CODE (jump);
- int_list_ptr p;
-
- for (p = basic_block_succ[bb]; p; p = p->next)
- add_pred_succ (bb, INT_LIST_VAL (p), s_preds, s_succs, num_preds,
- num_succs);
-
- /* If this is a RETURN insn or a conditional jump in the last
- basic block, or a non-jump insn in the last basic block, then
- this block reaches the exit block. */
- if ((code == JUMP_INSN && GET_CODE (PATTERN (jump)) == RETURN)
- || (((code == JUMP_INSN
- && condjump_p (jump) && !simplejump_p (jump))
- || code != JUMP_INSN)
- && bb == n_basic_blocks - 1))
- add_pred_succ (bb, EXIT_BLOCK, s_preds, s_succs, num_preds, num_succs);
+ basic_block bb = BASIC_BLOCK (i);
+
+ for (e = bb->succ; e ; e = e->succ_next)
+ add_pred_succ (i, e->dest->index, s_preds, s_succs,
+ num_preds, num_succs);
}
- add_pred_succ (ENTRY_BLOCK, 0, s_preds, s_succs, num_preds, num_succs);
+ for (e = ENTRY_BLOCK_PTR->succ; e ; e = e->succ_next)
+ add_pred_succ (ENTRY_BLOCK, e->dest->index, s_preds, s_succs,
+ num_preds, num_succs);
}
void
@@ -3590,7 +4454,7 @@ dump_bb_data (file, preds, succs, live_info)
int regno;
fprintf (file, "\nRegisters live at start:");
for (regno = 0; regno < max_regno; regno++)
- if (REGNO_REG_SET_P (basic_block_live_at_start[bb], regno))
+ if (REGNO_REG_SET_P (BASIC_BLOCK (bb)->global_live_at_start, regno))
fprintf (file, " %d", regno);
fprintf (file, "\n");
}
@@ -3626,8 +4490,8 @@ compute_dominators (dominators, post_dominators, s_preds, s_succs)
sbitmap_zero (dominators[0]);
SET_BIT (dominators[0], 0);
- sbitmap_zero (post_dominators[n_basic_blocks-1]);
- SET_BIT (post_dominators[n_basic_blocks-1], 0);
+ sbitmap_zero (post_dominators[n_basic_blocks - 1]);
+ SET_BIT (post_dominators[n_basic_blocks - 1], 0);
passes = 0;
changed = 1;
@@ -3947,3 +4811,34 @@ recompute_reg_usage (f, loop_step)
}
}
}
+
+/* Record INSN's block as BB. */
+
+void
+set_block_for_insn (insn, bb)
+ rtx insn;
+ basic_block bb;
+{
+ size_t uid = INSN_UID (insn);
+ if (uid >= basic_block_for_insn->num_elements)
+ {
+ int new_size;
+
+ /* Add one-eighth the size so we don't keep calling xrealloc. */
+ new_size = uid + (uid + 7) / 8;
+
+ VARRAY_GROW (basic_block_for_insn, new_size);
+ }
+ VARRAY_BB (basic_block_for_insn, uid) = bb;
+}
+
+/* Record INSN's block number as BB. */
+/* ??? This has got to go. */
+
+void
+set_block_num (insn, bb)
+ rtx insn;
+ int bb;
+{
+ set_block_for_insn (insn, BASIC_BLOCK (bb));
+}
diff --git a/gcc/function.c b/gcc/function.c
index 75b47bd1b49..79ca24deffa 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -262,6 +262,11 @@ tree nonlocal_labels;
rtx nonlocal_goto_handler_slots;
+/* List (chain of EXPR_LIST) of labels heading the current handlers for
+ nonlocal gotos. */
+
+rtx nonlocal_goto_handler_labels;
+
/* RTX for stack slot that holds the stack pointer value to restore
for a nonlocal goto.
Zero when function does not have nonlocal labels. */
@@ -559,6 +564,7 @@ push_function_context_to (context)
p->outgoing_args_size = current_function_outgoing_args_size;
p->return_rtx = current_function_return_rtx;
p->nonlocal_goto_handler_slots = nonlocal_goto_handler_slots;
+ p->nonlocal_goto_handler_labels = nonlocal_goto_handler_labels;
p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
p->nonlocal_labels = nonlocal_labels;
p->cleanup_label = cleanup_label;
@@ -644,6 +650,7 @@ pop_function_context_from (context)
current_function_outgoing_args_size = p->outgoing_args_size;
current_function_return_rtx = p->return_rtx;
nonlocal_goto_handler_slots = p->nonlocal_goto_handler_slots;
+ nonlocal_goto_handler_labels = p->nonlocal_goto_handler_labels;
nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
nonlocal_labels = p->nonlocal_labels;
cleanup_label = p->cleanup_label;
@@ -3852,21 +3859,6 @@ delete_handlers ()
}
}
}
-
-/* Return a list (chain of EXPR_LIST nodes) for the nonlocal labels
- of the current function. */
-
-rtx
-nonlocal_label_rtx_list ()
-{
- tree t;
- rtx x = 0;
-
- for (t = nonlocal_labels; t; t = TREE_CHAIN (t))
- x = gen_rtx_EXPR_LIST (VOIDmode, label_rtx (TREE_VALUE (t)), x);
-
- return x;
-}
/* Output a USE for any register use in RTL.
This is used with -noreg to mark the extent of lifespan
@@ -5644,6 +5636,7 @@ init_function_start (subr, filename, line)
/* No labels have been declared for nonlocal use. */
nonlocal_labels = 0;
+ nonlocal_goto_handler_labels = 0;
/* No function calls so far in this function. */
function_call_count = 0;
@@ -6438,100 +6431,172 @@ contains (insn, vec)
void
thread_prologue_and_epilogue_insns (f)
- rtx f ATTRIBUTE_UNUSED;
+ rtx f;
{
+ int insertted = 0;
+
+ prologue = 0;
#ifdef HAVE_prologue
if (HAVE_prologue)
{
- rtx head, seq;
-
- /* The first insn (a NOTE_INSN_DELETED) is followed by zero or more
- prologue insns and a NOTE_INSN_PROLOGUE_END. */
- emit_note_after (NOTE_INSN_PROLOGUE_END, f);
- seq = gen_prologue ();
- head = emit_insn_after (seq, f);
+ rtx seq;
- /* Include the new prologue insns in the first block. Ignore them
- if they form a basic block unto themselves. */
- if (x_basic_block_head && n_basic_blocks
- && GET_CODE (BLOCK_HEAD (0)) != CODE_LABEL)
- BLOCK_HEAD (0) = NEXT_INSN (f);
+ start_sequence ();
+ seq = gen_prologue();
+ emit_insn (seq);
/* Retain a map of the prologue insns. */
- prologue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : head);
+ if (GET_CODE (seq) != SEQUENCE)
+ seq = get_insns ();
+ prologue = record_insns (seq);
+
+ emit_note (NULL, NOTE_INSN_PROLOGUE_END);
+ seq = gen_sequence ();
+ end_sequence ();
+
+ /* If optimization is off, and perhaps in an empty function,
+ the entry block will have no successors. */
+ if (ENTRY_BLOCK_PTR->succ)
+ {
+ /* Can't deal with multiple successsors of the entry block. */
+ if (ENTRY_BLOCK_PTR->succ->succ_next)
+ abort ();
+
+ insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ);
+ insertted = 1;
+ }
+ else
+ emit_insn_after (seq, f);
}
- else
#endif
- prologue = 0;
+ epilogue = 0;
#ifdef HAVE_epilogue
if (HAVE_epilogue)
{
- rtx insn = get_last_insn ();
- rtx prev = prev_nonnote_insn (insn);
+ edge e;
+ basic_block bb = 0;
+ rtx tail = get_last_insn ();
+
+ /* ??? This is gastly. If function returns were not done via uses,
+ but via mark_regs_live_at_end, we could use insert_insn_on_edge
+ and all of this uglyness would go away. */
- /* If we end with a BARRIER, we don't need an epilogue. */
- if (! (prev && GET_CODE (prev) == BARRIER))
+ switch (optimize)
{
- rtx tail, seq, tem;
- rtx first_use = 0;
- rtx last_use = 0;
-
- /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
- epilogue insns, the USE insns at the end of a function,
- the jump insn that returns, and then a BARRIER. */
-
- /* Move the USE insns at the end of a function onto a list. */
- while (prev
- && GET_CODE (prev) == INSN
- && GET_CODE (PATTERN (prev)) == USE)
- {
- tem = prev;
+ default:
+ /* If the exit block has no non-fake predecessors, we don't
+ need an epilogue. Furthermore, only pay attention to the
+ fallthru predecessors; if (conditional) return insns were
+ generated, by definition we do not need to emit epilogue
+ insns. */
+
+ for (e = EXIT_BLOCK_PTR->pred; e ; e = e->pred_next)
+ if ((e->flags & EDGE_FAKE) == 0
+ && (e->flags & EDGE_FALLTHRU) != 0)
+ break;
+ if (e == NULL)
+ break;
+
+ /* We can't handle multiple epilogues -- if one is needed,
+ we won't be able to place it multiple times.
+
+ ??? Fix epilogue expanders to not assume they are the
+ last thing done compiling the function. Either that
+ or copy_rtx each insn.
+
+ ??? Blah, it's not a simple expression to assert that
+ we've exactly one fallthru exit edge. */
+
+ bb = e->src;
+ tail = bb->end;
+
+ /* ??? If the last insn of the basic block is a jump, then we
+ are creating a new basic block. Wimp out and leave these
+ insns outside any block. */
+ if (GET_CODE (tail) == JUMP_INSN)
+ bb = 0;
+
+ /* FALLTHRU */
+ case 0:
+ {
+ rtx prev, seq, first_use;
+
+ /* Move the USE insns at the end of a function onto a list. */
+ prev = tail;
+ if (GET_CODE (prev) == BARRIER
+ || GET_CODE (prev) == NOTE)
prev = prev_nonnote_insn (prev);
- NEXT_INSN (PREV_INSN (tem)) = NEXT_INSN (tem);
- PREV_INSN (NEXT_INSN (tem)) = PREV_INSN (tem);
- if (first_use)
- {
- NEXT_INSN (tem) = first_use;
- PREV_INSN (first_use) = tem;
- }
- first_use = tem;
- if (!last_use)
- last_use = tem;
- }
+ first_use = 0;
+ if (prev
+ && GET_CODE (prev) == INSN
+ && GET_CODE (PATTERN (prev)) == USE)
+ {
+ /* If the end of the block is the use, grab hold of something
+ else so that we emit barriers etc in the right place. */
+ if (prev == tail)
+ {
+ do
+ tail = PREV_INSN (tail);
+ while (GET_CODE (tail) == INSN
+ && GET_CODE (PATTERN (tail)) == USE);
+ }
- emit_barrier_after (insn);
+ do
+ {
+ rtx use = prev;
+ prev = prev_nonnote_insn (prev);
+
+ remove_insn (use);
+ if (first_use)
+ {
+ NEXT_INSN (use) = first_use;
+ PREV_INSN (first_use) = use;
+ }
+ else
+ NEXT_INSN (use) = NULL_RTX;
+ first_use = use;
+ }
+ while (prev
+ && GET_CODE (prev) == INSN
+ && GET_CODE (PATTERN (prev)) == USE);
+ }
- seq = gen_epilogue ();
- tail = emit_jump_insn_after (seq, insn);
+ /* The last basic block ends with a NOTE_INSN_EPILOGUE_BEG, the
+ epilogue insns, the USE insns at the end of a function,
+ the jump insn that returns, and then a BARRIER. */
- /* Insert the USE insns immediately before the return insn, which
- must be the first instruction before the final barrier. */
- if (first_use)
- {
- tem = prev_nonnote_insn (get_last_insn ());
- NEXT_INSN (PREV_INSN (tem)) = first_use;
- PREV_INSN (first_use) = PREV_INSN (tem);
- PREV_INSN (tem) = last_use;
- NEXT_INSN (last_use) = tem;
- }
+ if (GET_CODE (tail) != BARRIER)
+ {
+ prev = next_nonnote_insn (tail);
+ if (!prev || GET_CODE (prev) != BARRIER)
+ emit_barrier_after (tail);
+ }
- emit_note_after (NOTE_INSN_EPILOGUE_BEG, insn);
+ seq = gen_epilogue ();
+ prev = tail;
+ tail = emit_jump_insn_after (seq, tail);
- /* Include the new epilogue insns in the last block. Ignore
- them if they form a basic block unto themselves. */
- if (x_basic_block_end && n_basic_blocks
- && GET_CODE (BLOCK_END (n_basic_blocks - 1)) != JUMP_INSN)
- BLOCK_END (n_basic_blocks - 1) = tail;
+ /* Insert the USE insns immediately before the return insn, which
+ must be the last instruction emitted in the sequence. */
+ if (first_use)
+ emit_insns_before (first_use, tail);
+ emit_note_after (NOTE_INSN_EPILOGUE_BEG, prev);
- /* Retain a map of the epilogue insns. */
- epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
- return;
+ /* Update the tail of the basic block. */
+ if (bb)
+ bb->end = tail;
+
+ /* Retain a map of the epilogue insns. */
+ epilogue = record_insns (GET_CODE (seq) == SEQUENCE ? seq : tail);
+ }
}
}
#endif
- epilogue = 0;
+
+ if (insertted)
+ commit_edge_insertions ();
}
/* Reposition the prologue-end and epilogue-begin notes after instruction
diff --git a/gcc/function.h b/gcc/function.h
index 2a3e8238226..878de9e950e 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -83,6 +83,7 @@ struct function
int has_computed_jump;
int is_thunk;
rtx nonlocal_goto_handler_slots;
+ rtx nonlocal_goto_handler_labels;
rtx nonlocal_goto_stack_level;
tree nonlocal_labels;
int args_size;
diff --git a/gcc/global.c b/gcc/global.c
index f9b712f9282..9649b6e2725 100644
--- a/gcc/global.c
+++ b/gcc/global.c
@@ -648,7 +648,7 @@ global_conflicts ()
are explicitly marked in basic_block_live_at_start. */
{
- register regset old = basic_block_live_at_start[b];
+ register regset old = BASIC_BLOCK (b)->global_live_at_start;
int ax = 0;
REG_SET_TO_HARD_REG_SET (hard_regs_live, old);
@@ -671,12 +671,22 @@ global_conflicts ()
record_conflicts (block_start_allocnos, ax);
#ifdef STACK_REGS
- /* Pseudos can't go in stack regs at the start of a basic block
- that can be reached through a computed goto, since reg-stack
- can't handle computed gotos. */
- if (basic_block_computed_jump_target[b])
- for (ax = FIRST_STACK_REG; ax <= LAST_STACK_REG; ax++)
- record_one_conflict (ax);
+ {
+ /* Pseudos can't go in stack regs at the start of a basic block
+ that can be reached through a computed goto, since reg-stack
+ can't handle computed gotos. */
+ /* ??? Seems more likely that reg-stack can't handle any abnormal
+ edges, critical or not, computed goto or otherwise. */
+
+ edge e;
+ for (e = BASIC_BLOCK (b)->pred; e ; e = e->pred_next)
+ if (e->flags & EDGE_ABNORMAL)
+ break;
+
+ if (e != NULL)
+ for (ax = FIRST_STACK_REG; ax <= LAST_STACK_REG; ax++)
+ record_one_conflict (ax);
+ }
#endif
}
@@ -1598,11 +1608,14 @@ mark_elimination (from, to)
int i;
for (i = 0; i < n_basic_blocks; i++)
- if (REGNO_REG_SET_P (basic_block_live_at_start[i], from))
- {
- CLEAR_REGNO_REG_SET (basic_block_live_at_start[i], from);
- SET_REGNO_REG_SET (basic_block_live_at_start[i], to);
- }
+ {
+ register regset r = BASIC_BLOCK (i)->global_live_at_start;
+ if (REGNO_REG_SET_P (r, from))
+ {
+ CLEAR_REGNO_REG_SET (r, from);
+ SET_REGNO_REG_SET (r, to);
+ }
+ }
}
/* Used for communication between the following functions. Holds the
@@ -1672,13 +1685,13 @@ build_insn_chain (first)
int i;
CLEAR_REG_SET (live_relevant_regs);
for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
- if (REGNO_REG_SET_P (basic_block_live_at_start[b], i)
+ if (REGNO_REG_SET_P (BASIC_BLOCK (b)->global_live_at_start, i)
&& ! TEST_HARD_REG_BIT (eliminable_regset, i))
SET_REGNO_REG_SET (live_relevant_regs, i);
for (; i < max_regno; i++)
if (reg_renumber[i] >= 0
- && REGNO_REG_SET_P (basic_block_live_at_start[b], i))
+ && REGNO_REG_SET_P (BASIC_BLOCK (b)->global_live_at_start, i))
SET_REGNO_REG_SET (live_relevant_regs, i);
}
diff --git a/gcc/graph.c b/gcc/graph.c
index fefd175f57f..95149449964 100644
--- a/gcc/graph.c
+++ b/gcc/graph.c
@@ -160,7 +160,8 @@ darkgrey\n shape: ellipse" : "white",
"repeated_line_number",
"range_start",
"range_end",
- "live"
+ "live",
+ "basic_block"
};
fprintf (fp, " %s",
@@ -191,14 +192,21 @@ draw_edge (fp, from, to, bb_edge, class)
int bb_edge;
int class;
{
+ char * color;
switch (graph_dump_format)
{
case vcg:
+ color = "";
+ if (class == 2)
+ color = "color: red ";
+ else if (bb_edge)
+ color = "color: blue ";
+ else if (class == 3)
+ color = "color: green ";
fprintf (fp,
"edge: { sourcename: \"%s.%d\" targetname: \"%s.%d\" %s",
current_function_name, from,
- current_function_name, to,
- bb_edge ? "color: blue " : class ? "color: red " : "");
+ current_function_name, to, color);
if (class)
fprintf (fp, "class: %d ", class);
fputs ("}\n", fp);
@@ -253,8 +261,8 @@ print_rtl_graph_with_bb (base, suffix, rtx_first)
char *buf = (char *) alloca (namelen + suffixlen + extlen);
FILE *fp;
- /* Regenerate the basic block information. */
- find_basic_blocks (rtx_first, max_reg_num (), NULL);
+ if (basic_block_info == NULL)
+ return;
memcpy (buf, base, namelen);
memcpy (buf + namelen, suffix, suffixlen);
@@ -268,20 +276,14 @@ print_rtl_graph_with_bb (base, suffix, rtx_first)
fprintf (fp, "(nil)\n");
else
{
- int i, bb;
+ int i;
enum bb_state { NOT_IN_BB, IN_ONE_BB, IN_MULTIPLE_BB };
int max_uid = get_max_uid ();
int *start = (int *) alloca (max_uid * sizeof (int));
int *end = (int *) alloca (max_uid * sizeof (int));
enum bb_state *in_bb_p = (enum bb_state *)
alloca (max_uid * sizeof (enum bb_state));
- /* Element I is a list of I's predecessors/successors. */
- int_list_ptr *s_preds;
- int_list_ptr *s_succs;
- /* Element I is the number of predecessors/successors of basic
- block I. */
- int *num_preds;
- int *num_succs;
+ basic_block bb;
for (i = 0; i < max_uid; ++i)
{
@@ -292,28 +294,19 @@ print_rtl_graph_with_bb (base, suffix, rtx_first)
for (i = n_basic_blocks - 1; i >= 0; --i)
{
rtx x;
- start[INSN_UID (BLOCK_HEAD (i))] = i;
- end[INSN_UID (BLOCK_END (i))] = i;
- for (x = BLOCK_HEAD (i); x != NULL_RTX; x = NEXT_INSN (x))
+ bb = BASIC_BLOCK (i);
+ start[INSN_UID (bb->head)] = i;
+ end[INSN_UID (bb->end)] = i;
+ for (x = bb->head; x != NULL_RTX; x = NEXT_INSN (x))
{
in_bb_p[INSN_UID (x)]
= (in_bb_p[INSN_UID (x)] == NOT_IN_BB)
? IN_ONE_BB : IN_MULTIPLE_BB;
- if (x == BLOCK_END (i))
+ if (x == bb->end)
break;
}
}
- /* Get the information about the basic blocks predecessors and
- successors. */
- s_preds = (int_list_ptr *) alloca (n_basic_blocks
- * sizeof (int_list_ptr));
- s_succs = (int_list_ptr *) alloca (n_basic_blocks
- * sizeof (int_list_ptr));
- num_preds = (int *) alloca (n_basic_blocks * sizeof (int));
- num_succs = (int *) alloca (n_basic_blocks * sizeof (int));
- compute_preds_succs (s_preds, s_succs, num_preds, num_succs);
-
/* Tell print-rtl that we want graph output. */
dump_for_graph = 1;
@@ -336,12 +329,12 @@ print_rtl_graph_with_bb (base, suffix, rtx_first)
continue;
}
- if ((bb = start[INSN_UID (tmp_rtx)]) >= 0)
+ if ((i = start[INSN_UID (tmp_rtx)]) >= 0)
{
/* We start a subgraph for each basic block. */
- start_bb (fp, bb);
+ start_bb (fp, i);
- if (bb == 0)
+ if (i == 0)
draw_edge (fp, 0, INSN_UID (tmp_rtx), 1, 0);
}
@@ -349,40 +342,40 @@ print_rtl_graph_with_bb (base, suffix, rtx_first)
did_output = node_data (fp, tmp_rtx);
next_insn = next_nonnote_insn (tmp_rtx);
- if ((bb = end[INSN_UID (tmp_rtx)]) >= 0)
+ if ((i = end[INSN_UID (tmp_rtx)]) >= 0)
{
- int_list_ptr p;
+ edge e;
+
+ bb = BASIC_BLOCK (i);
/* End of the basic block. */
end_bb (fp, bb);
/* Now specify the edges to all the successors of this
basic block. */
- for (p = s_succs[bb]; p != NULL; p = p->next)
+ for (e = bb->succ; e ; e = e->succ_next)
{
- int bb_succ = INT_LIST_VAL (p);
-
- if (bb_succ >= 0)
+ if (e->dest != EXIT_BLOCK_PTR)
{
- rtx block_head = BLOCK_HEAD (bb_succ);
+ rtx block_head = e->dest->head;
draw_edge (fp, INSN_UID (tmp_rtx),
INSN_UID (block_head),
- next_insn != block_head, 0);
+ next_insn != block_head,
+ (e->flags & EDGE_ABNORMAL ? 2 : 0));
- if (BLOCK_HEAD (bb_succ) == next_insn)
+ if (block_head == next_insn)
edge_printed = 1;
}
- else if (bb_succ == EXIT_BLOCK)
+ else
{
draw_edge (fp, INSN_UID (tmp_rtx), 999999,
- next_insn != 0, 0);
+ next_insn != 0,
+ (e->flags & EDGE_ABNORMAL ? 2 : 0));
if (next_insn == 0)
edge_printed = 1;
}
- else
- abort ();
}
}
@@ -395,8 +388,8 @@ print_rtl_graph_with_bb (base, suffix, rtx_first)
next_insn ? INSN_UID (next_insn) : 999999, 0, 0);
else
{
- /* We draw the remaining edges in class 2. We have
- to skip oevr the barrier since these nodes are
+ /* We draw the remaining edges in class 3. We have
+ to skip over the barrier since these nodes are
not printed at all. */
do
next_insn = NEXT_INSN (next_insn);
@@ -405,7 +398,7 @@ print_rtl_graph_with_bb (base, suffix, rtx_first)
|| GET_CODE (next_insn) == BARRIER));
draw_edge (fp, XINT (tmp_rtx, 0),
- next_insn ? INSN_UID (next_insn) : 999999, 0, 2);
+ next_insn ? INSN_UID (next_insn) : 999999, 0, 3);
}
}
}
diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index af9161fb5be..e9052b5f12b 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -472,8 +472,8 @@ typedef struct
int next_in;
int next_out;
}
-edge;
-static edge *edge_table;
+haifa_edge;
+static haifa_edge *edge_table;
#define NEXT_IN(edge) (edge_table[edge].next_in)
#define NEXT_OUT(edge) (edge_table[edge].next_out)
@@ -1082,7 +1082,7 @@ is_cfg_nonregular ()
/* If we have a label that could be the target of a nonlocal goto, then
the cfg is not well structured. */
- if (nonlocal_label_rtx_list () != NULL)
+ if (nonlocal_goto_handler_labels)
return 1;
/* If we have any forced labels, then the cfg is not well structured. */
@@ -1169,8 +1169,8 @@ build_control_flow (s_preds, s_succs, num_preds, num_succs)
bzero ((char *) in_edges, n_basic_blocks * sizeof (int));
bzero ((char *) out_edges, n_basic_blocks * sizeof (int));
- edge_table = (edge *) xmalloc ((nr_edges) * sizeof (edge));
- bzero ((char *) edge_table, ((nr_edges) * sizeof (edge)));
+ edge_table = (haifa_edge *) xmalloc ((nr_edges) * sizeof (haifa_edge));
+ bzero ((char *) edge_table, ((nr_edges) * sizeof (haifa_edge)));
nr_edges = 0;
for (i = 0; i < n_basic_blocks; i++)
@@ -2153,7 +2153,8 @@ check_live_1 (src, x)
{
int b = candidate_table[src].split_bbs.first_member[i];
- if (REGNO_REG_SET_P (basic_block_live_at_start[b], regno + j))
+ if (REGNO_REG_SET_P (BASIC_BLOCK (b)->global_live_at_start,
+ regno + j))
{
return 0;
}
@@ -2167,7 +2168,7 @@ check_live_1 (src, x)
{
int b = candidate_table[src].split_bbs.first_member[i];
- if (REGNO_REG_SET_P (basic_block_live_at_start[b], regno))
+ if (REGNO_REG_SET_P (BASIC_BLOCK (b)->global_live_at_start, regno))
{
return 0;
}
@@ -2227,7 +2228,8 @@ update_live_1 (src, x)
{
int b = candidate_table[src].update_bbs.first_member[i];
- SET_REGNO_REG_SET (basic_block_live_at_start[b], regno + j);
+ SET_REGNO_REG_SET (BASIC_BLOCK (b)->global_live_at_start,
+ regno + j);
}
}
}
@@ -2237,7 +2239,7 @@ update_live_1 (src, x)
{
int b = candidate_table[src].update_bbs.first_member[i];
- SET_REGNO_REG_SET (basic_block_live_at_start[b], regno);
+ SET_REGNO_REG_SET (BASIC_BLOCK (b)->global_live_at_start, regno);
}
}
}
@@ -5135,7 +5137,7 @@ finish_sometimes_live (regs_sometimes_live, sometimes_max)
/* functions for computation of registers live/usage info */
-/* It is assumed that prior to scheduling basic_block_live_at_start (b)
+/* It is assumed that prior to scheduling BASIC_BLOCK (b)->global_live_at_start
contains the registers that are alive at the entry to b.
Two passes follow: The first pass is performed before the scheduling
@@ -5165,7 +5167,7 @@ find_pre_sched_live (bb)
int b = BB_TO_BLOCK (bb);
get_block_head_tail (bb, &head, &tail);
- COPY_REG_SET (bb_live_regs, basic_block_live_at_start[b]);
+ COPY_REG_SET (bb_live_regs, BASIC_BLOCK (b)->global_live_at_start);
next_tail = NEXT_INSN (tail);
for (insn = head; insn != next_tail; insn = NEXT_INSN (insn))
@@ -5303,7 +5305,8 @@ find_post_sched_live (bb)
int b_succ;
b_succ = TO_BLOCK (e);
- IOR_REG_SET (bb_live_regs, basic_block_live_at_start[b_succ]);
+ IOR_REG_SET (bb_live_regs,
+ BASIC_BLOCK (b_succ)->global_live_at_start);
e = NEXT_OUT (e);
}
while (e != first_edge);
@@ -5325,7 +5328,7 @@ find_post_sched_live (bb)
&& (GET_RTX_CLASS (GET_CODE (tail)) != 'i'))
{
if (current_nr_blocks > 1)
- COPY_REG_SET (basic_block_live_at_start[b], bb_live_regs);
+ COPY_REG_SET (BASIC_BLOCK (b)->global_live_at_start, bb_live_regs);
return;
}
@@ -5448,9 +5451,9 @@ find_post_sched_live (bb)
finish_sometimes_live (regs_sometimes_live, sometimes_max);
- /* In interblock scheduling, basic_block_live_at_start may have changed. */
+ /* In interblock scheduling, global_live_at_start may have changed. */
if (current_nr_blocks > 1)
- COPY_REG_SET (basic_block_live_at_start[b], bb_live_regs);
+ COPY_REG_SET (BASIC_BLOCK (b)->global_live_at_start, bb_live_regs);
FREE_REG_SET (old_live_regs);
@@ -5522,7 +5525,7 @@ update_reg_usage ()
pseudos which are live in more than one block.
This is because combine might have made an optimization which
- invalidated basic_block_live_at_start and reg_n_calls_crossed,
+ invalidated global_live_at_start and reg_n_calls_crossed,
but it does not update them. If we update reg_n_calls_crossed
here, the two variables are now inconsistent, and this might
confuse the caller-save code into saving a register that doesn't
@@ -8530,7 +8533,7 @@ schedule_insns (dump_file)
/* The scheduler runs after flow; therefore, we can't blindly call
back into find_basic_blocks since doing so could invalidate the
- info in basic_block_live_at_start.
+ info in global_live_at_start.
Consider a block consisting entirely of dead stores; after life
analysis it would be a block of NOTE_INSN_DELETED notes. If
diff --git a/gcc/jump.c b/gcc/jump.c
index 09f036c1547..7d25a97d3c5 100644
--- a/gcc/jump.c
+++ b/gcc/jump.c
@@ -3429,6 +3429,24 @@ condjump_label (insn)
return NULL_RTX;
}
+/* Return true if INSN is a (possibly conditional) return insn. */
+
+static int
+returnjump_p_1 (loc, data)
+ rtx *loc;
+ void *data ATTRIBUTE_UNUSED;
+{
+ rtx x = *loc;
+ return GET_CODE (x) == RETURN;
+}
+
+int
+returnjump_p (insn)
+ rtx insn;
+{
+ return for_each_rtx (&PATTERN (insn), returnjump_p_1, NULL);
+}
+
#ifdef HAVE_cc0
/* Return 1 if X is an RTX that does nothing but set the condition codes
diff --git a/gcc/local-alloc.c b/gcc/local-alloc.c
index 127023daae4..ea97f33f5b5 100644
--- a/gcc/local-alloc.c
+++ b/gcc/local-alloc.c
@@ -966,7 +966,8 @@ update_equiv_regs ()
BLOCK_HEAD (block) = PREV_INSN (insn);
for (l = 0; l < n_basic_blocks; l++)
- CLEAR_REGNO_REG_SET (basic_block_live_at_start[l], regno);
+ CLEAR_REGNO_REG_SET (BASIC_BLOCK (l)->global_live_at_start,
+ regno);
}
}
}
@@ -1039,7 +1040,7 @@ block_alloc (b)
/* Initialize table of hardware registers currently live. */
- REG_SET_TO_HARD_REG_SET (regs_live, basic_block_live_at_start[b]);
+ REG_SET_TO_HARD_REG_SET (regs_live, BASIC_BLOCK (b)->global_live_at_start);
/* This loop scans the instructions of the basic block
and assigns quantities to registers.
diff --git a/gcc/print-rtl.c b/gcc/print-rtl.c
index d3e829ad847..e72a77bf5e9 100644
--- a/gcc/print-rtl.c
+++ b/gcc/print-rtl.c
@@ -22,9 +22,9 @@ Boston, MA 02111-1307, USA. */
#include "config.h"
#include "system.h"
#include "rtl.h"
-#include "bitmap.h"
#include "real.h"
#include "flags.h"
+#include "basic-block.h"
/* How to print out a register name.
@@ -170,6 +170,14 @@ print_rtx (in_rtx)
break;
}
+ if (i == 3 && GET_CODE (in_rtx) == NOTE
+ && NOTE_LINE_NUMBER (in_rtx) == NOTE_INSN_BASIC_BLOCK)
+ {
+ basic_block bb = NOTE_BASIC_BLOCK (in_rtx);
+ fprintf (outfile, " [bb %d]", bb->index);
+ break;
+ }
+
if (XSTR (in_rtx, i) == 0)
fputs (dump_for_graph ? " \\\"\\\"" : " \"\"", outfile);
else
diff --git a/gcc/reg-stack.c b/gcc/reg-stack.c
index a0f48fa1e56..203e1af6007 100644
--- a/gcc/reg-stack.c
+++ b/gcc/reg-stack.c
@@ -229,9 +229,23 @@ static rtx
/* Get the basic block number of an insn. See note at block_number
definition are validity of this information. */
-#define BLOCK_NUM(INSN) \
- ((INSN_UID (INSN) > max_uid) \
- ? (abort() , -1) : block_number[INSN_UID (INSN)])
+static int BLOCK_NUM PROTO((rtx));
+
+#ifdef __GNUC__
+__inline__
+#endif
+static int
+BLOCK_NUM(insn)
+ rtx insn;
+{
+ int tmp = INSN_UID (insn);
+ if (tmp > max_uid)
+ abort ();
+ tmp = block_number[tmp];
+ if (tmp < 0)
+ abort ();
+ return tmp;
+}
extern rtx forced_labels;
@@ -502,6 +516,7 @@ reg_to_stack (first, file)
bzero ((char *) block_out_reg_set, blocks * sizeof (HARD_REG_SET));
block_number = (int *) alloca ((max_uid + 1) * sizeof (int));
+ memset (block_number, -1, (max_uid + 1) * sizeof (int));
find_blocks (first);
stack_reg_life_analysis (first, &stackentry);
diff --git a/gcc/regclass.c b/gcc/regclass.c
index 57be1182864..1b6ec9a4b6a 100644
--- a/gcc/regclass.c
+++ b/gcc/regclass.c
@@ -2208,12 +2208,5 @@ reg_classes_intersect_p (c1, c2)
void
regset_release_memory ()
{
- if (basic_block_live_at_start)
- {
- free_regset_vector (basic_block_live_at_start, n_basic_blocks);
- basic_block_live_at_start = 0;
- }
-
- FREE_REG_SET (regs_live_at_setjmp);
bitmap_release_memory ();
}
diff --git a/gcc/regmove.c b/gcc/regmove.c
index 674f1c8100a..8cc913a52c2 100644
--- a/gcc/regmove.c
+++ b/gcc/regmove.c
@@ -267,7 +267,7 @@ mark_flags_life_zones (flags)
{
int i;
for (i = 0; i < flags_nregs; ++i)
- live |= REGNO_REG_SET_P (basic_block_live_at_start[block],
+ live |= REGNO_REG_SET_P (BASIC_BLOCK (block)->global_live_at_start,
flags_regno + i);
}
#endif
diff --git a/gcc/reload1.c b/gcc/reload1.c
index bfa25021ba4..a9bed7a9b02 100644
--- a/gcc/reload1.c
+++ b/gcc/reload1.c
@@ -538,9 +538,9 @@ compute_use_by_pseudos (to, from)
if (r < 0)
{
/* reload_combine uses the information from
- basic_block_live_at_start, which might still contain registers
- that have not actually been allocated since they have an
- equivalence. */
+ BASIC_BLOCK->global_live_at_start, which might still
+ contain registers that have not actually been allocated
+ since they have an equivalence. */
if (! reload_completed)
abort ();
}
@@ -1060,7 +1060,7 @@ reload (first, global, dumpfile)
if (! frame_pointer_needed)
for (i = 0; i < n_basic_blocks; i++)
- CLEAR_REGNO_REG_SET (basic_block_live_at_start[i],
+ CLEAR_REGNO_REG_SET (BASIC_BLOCK (i)->global_live_at_start,
HARD_FRAME_POINTER_REGNUM);
/* Come here (with failure set nonzero) if we can't get enough spill regs
@@ -9494,8 +9494,8 @@ reload_combine ()
{
HARD_REG_SET live;
- REG_SET_TO_HARD_REG_SET (live, basic_block_live_at_start[i]);
- compute_use_by_pseudos (&live, basic_block_live_at_start[i]);
+ REG_SET_TO_HARD_REG_SET (live, BASIC_BLOCK (i)->global_live_at_start);
+ compute_use_by_pseudos (&live, BASIC_BLOCK (i)->global_live_at_start);
COPY_HARD_REG_SET (LABEL_LIVE (insn), live);
IOR_HARD_REG_SET (ever_live_at_start, live);
}
diff --git a/gcc/resource.c b/gcc/resource.c
index c76e253fe10..9f702a536cd 100644
--- a/gcc/resource.c
+++ b/gcc/resource.c
@@ -875,7 +875,7 @@ mark_target_live_regs (insns, target, res)
TARGET. Otherwise, we must assume everything is live. */
if (b != -1)
{
- regset regs_live = basic_block_live_at_start[b];
+ regset regs_live = BASIC_BLOCK (b)->global_live_at_start;
int j;
int regno;
rtx start_insn, stop_insn;
diff --git a/gcc/rtl.c b/gcc/rtl.c
index b4d870d8cc3..801018e17fe 100644
--- a/gcc/rtl.c
+++ b/gcc/rtl.c
@@ -184,7 +184,8 @@ char *note_insn_name[] = { 0 , "NOTE_INSN_DELETED",
"NOTE_INSN_DELETED_LABEL", "NOTE_INSN_FUNCTION_BEG",
"NOTE_INSN_EH_REGION_BEG", "NOTE_INSN_EH_REGION_END",
"NOTE_REPEATED_LINE_NUMBER", "NOTE_INSN_RANGE_START",
- "NOTE_INSN_RANGE_END", "NOTE_INSN_LIVE" };
+ "NOTE_INSN_RANGE_END", "NOTE_INSN_LIVE",
+ "NOTE_INSN_BASIC_BLOCK" };
char *reg_note_name[] = { "", "REG_DEAD", "REG_INC", "REG_EQUIV", "REG_WAS_0",
"REG_EQUAL", "REG_RETVAL", "REG_LIBCALL",
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 3d51c88ad1e..bee3f052c3d 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -91,6 +91,7 @@ typedef union rtunion_def
addr_diff_vec_flags rt_addr_diff_vec_flags;
struct bitmap_head_def *rtbit;
union tree_node *rttree;
+ struct basic_block_def *bb;
} rtunion;
/* RTL expression ("rtx"). */
@@ -404,6 +405,7 @@ extern char *reg_note_name[];
#define NOTE_BLOCK_NUMBER(INSN) ((INSN)->fld[3].rtint)
#define NOTE_RANGE_INFO(INSN) ((INSN)->fld[3].rtx)
#define NOTE_LIVE_INFO(INSN) ((INSN)->fld[3].rtx)
+#define NOTE_BASIC_BLOCK(INSN) ((INSN)->fld[3].bb)
/* If the NOTE_BLOCK_NUMBER field gets a -1, it means create a new
block node for a live range block. */
@@ -469,6 +471,8 @@ extern char *reg_note_name[];
#define NOTE_INSN_RANGE_END -18
/* Record which registers are currently live. */
#define NOTE_INSN_LIVE -19
+/* Record the struct for the following basic block. */
+#define NOTE_INSN_BASIC_BLOCK -20
#if 0 /* These are not used, and I don't know what they were for. --rms. */
#define NOTE_DECL_NAME(INSN) ((INSN)->fld[3].rtstr)
@@ -932,6 +936,7 @@ extern rtx emit_insn_before PROTO((rtx, rtx));
extern rtx emit_jump_insn_before PROTO((rtx, rtx));
extern rtx emit_call_insn_before PROTO((rtx, rtx));
extern rtx emit_barrier_before PROTO((rtx));
+extern rtx emit_label_before PROTO((rtx, rtx));
extern rtx emit_note_before PROTO((int, rtx));
extern rtx emit_insn_after PROTO((rtx, rtx));
extern rtx emit_jump_insn_after PROTO((rtx, rtx));
@@ -982,7 +987,6 @@ extern rtx simplify_unary_operation PROTO((enum rtx_code, enum machine_mode, rtx
extern rtx simplify_binary_operation PROTO((enum rtx_code, enum machine_mode, rtx, rtx));
extern rtx simplify_ternary_operation PROTO((enum rtx_code, enum machine_mode, enum machine_mode, rtx, rtx, rtx));
extern rtx simplify_relational_operation PROTO((enum rtx_code, enum machine_mode, rtx, rtx));
-extern rtx nonlocal_label_rtx_list PROTO((void));
extern rtx gen_move_insn PROTO((rtx, rtx));
extern rtx gen_jump PROTO((rtx));
extern rtx gen_beq PROTO((rtx));
@@ -1300,6 +1304,7 @@ extern int comparison_dominates_p PROTO ((enum rtx_code, enum rtx_code));
extern int condjump_p PROTO ((rtx));
extern rtx condjump_label PROTO ((rtx));
extern int simplejump_p PROTO ((rtx));
+extern int returnjump_p PROTO ((rtx));
extern int sets_cc0_p PROTO ((rtx));
extern int invert_jump PROTO ((rtx, rtx));
extern int rtx_renumbered_equal_p PROTO ((rtx, rtx));
@@ -1415,6 +1420,10 @@ extern void expand_null_return PROTO((void));
extern void emit_jump PROTO ((rtx));
extern int preserve_subexpressions_p PROTO ((void));
+/* List (chain of EXPR_LIST) of labels heading the current handlers for
+ nonlocal gotos. */
+extern rtx nonlocal_goto_handler_labels;
+
/* In expr.c */
extern void init_expr_once PROTO ((void));
extern void move_by_pieces PROTO ((rtx, rtx, int, int));
diff --git a/gcc/sched.c b/gcc/sched.c
index a8bcaf7437c..1bcc779786f 100644
--- a/gcc/sched.c
+++ b/gcc/sched.c
@@ -2879,7 +2879,7 @@ schedule_block (b, file)
if (reload_completed == 0)
{
- COPY_REG_SET (bb_live_regs, basic_block_live_at_start[b]);
+ COPY_REG_SET (bb_live_regs, BASIC_BLOCK (b)->global_live_at_start);
CLEAR_REG_SET (bb_dead_regs);
if (b == 0)
diff --git a/gcc/stmt.c b/gcc/stmt.c
index 26ac0247332..385920847cc 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -428,7 +428,7 @@ static int using_eh_for_cleanups_p = 0;
static int n_occurrences PROTO((int, char *));
static void expand_goto_internal PROTO((tree, rtx, rtx));
static int expand_fixup PROTO((tree, rtx, rtx));
-static void expand_nl_handler_label PROTO((rtx, rtx));
+static rtx expand_nl_handler_label PROTO((rtx, rtx));
static void expand_nl_goto_receiver PROTO((void));
static void expand_nl_goto_receivers PROTO((struct nesting *));
static void fixup_gotos PROTO((struct nesting *, rtx, tree,
@@ -3169,7 +3169,7 @@ remember_end_note (block)
/* Emit a handler label for a nonlocal goto handler.
Also emit code to store the handler label in SLOT before BEFORE_INSN. */
-static void
+static rtx
expand_nl_handler_label (slot, before_insn)
rtx slot, before_insn;
{
@@ -3186,6 +3186,8 @@ expand_nl_handler_label (slot, before_insn)
emit_insns_before (insns, before_insn);
emit_label (handler_label);
+
+ return handler_label;
}
/* Emit code to restore vital registers at the beginning of a nonlocal goto
@@ -3260,6 +3262,7 @@ expand_nl_goto_receivers (thisblock)
tree link;
rtx afterward = gen_label_rtx ();
rtx insns, slot;
+ rtx label_list;
int any_invalid;
/* Record the handler address in the stack slot for that purpose,
@@ -3283,14 +3286,18 @@ expand_nl_goto_receivers (thisblock)
/* Make a separate handler for each label. */
link = nonlocal_labels;
slot = nonlocal_goto_handler_slots;
+ label_list = NULL_RTX;
for (; link; link = TREE_CHAIN (link), slot = XEXP (slot, 1))
/* Skip any labels we shouldn't be able to jump to from here,
we generate one special handler for all of them below which just calls
abort. */
if (! DECL_TOO_LATE (TREE_VALUE (link)))
{
- expand_nl_handler_label (XEXP (slot, 0),
- thisblock->data.block.first_insn);
+ rtx lab;
+ lab = expand_nl_handler_label (XEXP (slot, 0),
+ thisblock->data.block.first_insn);
+ label_list = gen_rtx_EXPR_LIST (VOIDmode, lab, label_list);
+
expand_nl_goto_receiver ();
/* Jump to the "real" nonlocal label. */
@@ -3305,8 +3312,10 @@ expand_nl_goto_receivers (thisblock)
for (; link; link = TREE_CHAIN (link), slot = XEXP (slot, 1))
if (DECL_TOO_LATE (TREE_VALUE (link)))
{
- expand_nl_handler_label (XEXP (slot, 0),
- thisblock->data.block.first_insn);
+ rtx lab;
+ lab = expand_nl_handler_label (XEXP (slot, 0),
+ thisblock->data.block.first_insn);
+ label_list = gen_rtx_EXPR_LIST (VOIDmode, lab, label_list);
any_invalid = 1;
}
@@ -3318,6 +3327,7 @@ expand_nl_goto_receivers (thisblock)
emit_barrier ();
}
+ nonlocal_goto_handler_labels = label_list;
emit_label (afterward);
}
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 90b9bca0bcc..252bd90e668 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -292,6 +292,7 @@ int regmove_dump = 0;
int sched_dump = 0;
int local_reg_dump = 0;
int global_reg_dump = 0;
+int flow2_dump = 0;
int sched2_dump = 0;
int jump2_opt_dump = 0;
#ifdef DELAY_SLOTS
@@ -1286,6 +1287,7 @@ int regmove_time;
int sched_time;
int local_alloc_time;
int global_alloc_time;
+int flow2_time;
int sched2_time;
#ifdef DELAY_SLOTS
int dbr_sched_time;
@@ -2642,6 +2644,7 @@ compile_file (name)
sched_time = 0;
local_alloc_time = 0;
global_alloc_time = 0;
+ flow2_time = 0;
sched2_time = 0;
#ifdef DELAY_SLOTS
dbr_sched_time = 0;
@@ -2759,6 +2762,12 @@ compile_file (name)
if (graph_dump_format != no_graph)
clean_graph_dump_file (dump_base_name, ".greg");
}
+ if (flow2_dump)
+ {
+ clean_dump_file (".flow2");
+ if (graph_dump_format != no_graph)
+ clean_graph_dump_file (dump_base_name, ".flow2");
+ }
if (sched2_dump)
{
clean_dump_file (".sched2");
@@ -3303,6 +3312,8 @@ compile_file (name)
finish_graph_dump_file (dump_base_name, ".lreg");
if (global_reg_dump)
finish_graph_dump_file (dump_base_name, ".greg");
+ if (flow_dump)
+ finish_graph_dump_file (dump_base_name, ".flow2");
if (sched2_dump)
finish_graph_dump_file (dump_base_name, ".sched2");
if (jump2_opt_dump)
@@ -3346,6 +3357,7 @@ compile_file (name)
print_time ("sched", sched_time);
print_time ("local-alloc", local_alloc_time);
print_time ("global-alloc", global_alloc_time);
+ print_time ("flow2", flow2_time);
print_time ("sched2", sched2_time);
#ifdef DELAY_SLOTS
print_time ("dbranch", dbr_sched_time);
@@ -4079,14 +4091,27 @@ rest_of_compilation (decl)
}
}
+ if (global_reg_dump)
+ {
+ TIMEVAR (dump_time, dump_global_regs (rtl_dump_file));
+ close_dump_file (print_rtl_with_bb, insns);
+ if (graph_dump_format != no_graph)
+ print_rtl_graph_with_bb (dump_base_name, ".greg", insns);
+ }
+
/* Re-create the death notes which were deleted during reload. */
+ if (flow2_dump)
+ open_dump_file (".flow2", decl_printable_name (decl, 2));
+
if (optimize)
- TIMEVAR
- (flow_time,
- {
- find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
- life_analysis (insns, max_reg_num (), rtl_dump_file);
- });
+ {
+ TIMEVAR
+ (flow2_time,
+ {
+ find_basic_blocks (insns, max_reg_num (), rtl_dump_file);
+ life_analysis (insns, max_reg_num (), rtl_dump_file);
+ });
+ }
flow2_completed = 1;
@@ -4097,13 +4122,13 @@ rest_of_compilation (decl)
thread_prologue_and_epilogue_insns (insns);
- if (global_reg_dump)
+ if (flow2_dump)
{
- TIMEVAR (dump_time, dump_global_regs (rtl_dump_file));
close_dump_file (print_rtl_with_bb, insns);
if (graph_dump_format != no_graph)
- print_rtl_graph_with_bb (dump_base_name, ".greg", insns);
+ print_rtl_graph_with_bb (dump_base_name, ".flow2", insns);
}
+
if (optimize > 0 && flag_schedule_insns_after_reload)
{
if (sched2_dump)
@@ -4227,6 +4252,9 @@ rest_of_compilation (decl)
if (! quiet_flag)
fflush (asm_out_file);
+ /* Release all memory allocated by flow. */
+ free_basic_block_vars (0);
+
/* Release all memory held by regsets now */
regset_release_memory ();
});
@@ -4258,7 +4286,7 @@ rest_of_compilation (decl)
exit_rest_of_compilation:
- free_bb_memory ();
+ free_bb_mem ();
/* In case the function was not output,
don't leave any temporary anonymous types
@@ -4770,6 +4798,7 @@ main (argc, argv)
dbr_sched_dump = 1;
#endif
flow_dump = 1;
+ flow2_dump = 1;
global_reg_dump = 1;
jump_opt_dump = 1;
addressof_dump = 1;
@@ -4864,6 +4893,9 @@ main (argc, argv)
case 'v':
graph_dump_format = vcg;
break;
+ case 'w':
+ flow2_dump = 1;
+ break;
case 'y':
set_yydebug (1);
break;
diff --git a/gcc/unroll.c b/gcc/unroll.c
index 7953416a3d5..28c3e7b7cc3 100644
--- a/gcc/unroll.c
+++ b/gcc/unroll.c
@@ -2129,8 +2129,12 @@ copy_loop_body (copy_start, copy_end, map, exit_label, last_iteration,
case NOTE:
/* VTOP notes are valid only before the loop exit test. If placed
anywhere else, loop may generate bad code. */
+ /* BASIC_BLOCK notes exist to stabilize basic block structures with
+ the associated rtl. We do not want to share the structure in
+ this new block. */
if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
+ && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK
&& (NOTE_LINE_NUMBER (insn) != NOTE_INSN_LOOP_VTOP
|| (last_iteration && unroll_type != UNROLL_COMPLETELY)))
copy = emit_note (NOTE_SOURCE_FILE (insn),
@@ -2175,7 +2179,8 @@ copy_loop_body (copy_start, copy_end, map, exit_label, last_iteration,
for (insn = copy_notes_from; insn != loop_end; insn = NEXT_INSN (insn))
{
if (GET_CODE (insn) == NOTE
- && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
+ && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
+ && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK)
emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
}
}
diff --git a/gcc/varray.h b/gcc/varray.h
index 5905773d190..7d4f6972f26 100644
--- a/gcc/varray.h
+++ b/gcc/varray.h
@@ -75,6 +75,7 @@ typedef union varray_data_tag {
struct sched_info_tag *sched[1];
struct reg_info_def *reg[1];
struct const_equiv_data const_equiv[1];
+ struct basic_block_def *bb[1];
} varray_data;
/* Virtual array of pointers header. */
@@ -146,6 +147,9 @@ extern varray_type varray_init PROTO ((size_t, size_t, const char *));
#define VARRAY_CONST_EQUIV_INIT(va, num, name) \
va = varray_init (num, sizeof (struct const_equiv_data), name)
+#define VARRAY_BB_INIT(va, num, name) \
+ va = varray_init (num, sizeof (struct basic_block_def *), name)
+
/* Free up memory allocated by the virtual array, but do not free any of the
elements involved. */
#define VARRAY_FREE(vp) \
@@ -189,6 +193,7 @@ extern varray_type varray_grow PROTO((varray_type, size_t));
#define VARRAY_BITMAP(VA, N) ((VA)->data.bitmap[ VARRAY_CHECK (VA, N) ])
#define VARRAY_SCHED(VA, N) ((VA)->data.sched[ VARRAY_CHECK (VA, N) ])
#define VARRAY_REG(VA, N) ((VA)->data.reg[ VARRAY_CHECK (VA, N) ])
-#define VARRAY_CONST_EQUIV(VA, N) ((VA)->data.const_equiv[ VARRAY_CHECK (VA, N) ])
+#define VARRAY_CONST_EQUIV(VA, N) ((VA)->data.const_equiv[VARRAY_CHECK (VA, N)])
+#define VARRAY_BB(VA, N) ((VA)->data.bb[ VARRAY_CHECK (VA, N) ])
#endif /* _VARRAY_H_ */