* tree.c (make_node): Set TREE_SIDE_EFFECTS for expressions that
[official-gcc.git] / gcc / basic-block.h
blob881085b0d07a6c35659607862aa4066da094a8d2
1 /* Define control and data flow tables, and regsets.
2 Copyright (C) 1987, 1997, 1998, 1999 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include "bitmap.h"
23 #include "sbitmap.h"
24 #include "varray.h"
26 typedef bitmap regset; /* Head of register set linked list. */
28 /* Clear a register set by freeing up the linked list. */
29 #define CLEAR_REG_SET(HEAD) bitmap_clear (HEAD)
31 /* Copy a register set to another register set. */
32 #define COPY_REG_SET(TO, FROM) bitmap_copy (TO, FROM)
34 /* `and' a register set with a second register set. */
35 #define AND_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_AND)
37 /* `and' the complement of a register set with a register set. */
38 #define AND_COMPL_REG_SET(TO, FROM) \
39 bitmap_operation (TO, TO, FROM, BITMAP_AND_COMPL)
41 /* Inclusive or a register set with a second register set. */
42 #define IOR_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_IOR)
44 /* Or into TO the register set FROM1 `and'ed with the complement of FROM2. */
45 #define IOR_AND_COMPL_REG_SET(TO, FROM1, FROM2) \
46 bitmap_ior_and_compl (TO, FROM1, FROM2)
48 /* Clear a single register in a register set. */
49 #define CLEAR_REGNO_REG_SET(HEAD, REG) bitmap_clear_bit (HEAD, REG)
51 /* Set a single register in a register set. */
52 #define SET_REGNO_REG_SET(HEAD, REG) bitmap_set_bit (HEAD, REG)
54 /* Return true if a register is set in a register set. */
55 #define REGNO_REG_SET_P(TO, REG) bitmap_bit_p (TO, REG)
57 /* Copy the hard registers in a register set to the hard register set. */
58 #define REG_SET_TO_HARD_REG_SET(TO, FROM) \
59 do { \
60 int i_; \
61 CLEAR_HARD_REG_SET (TO); \
62 for (i_ = 0; i_ < FIRST_PSEUDO_REGISTER; i_++) \
63 if (REGNO_REG_SET_P (FROM, i_)) \
64 SET_HARD_REG_BIT (TO, i_); \
65 } while (0)
67 /* Loop over all registers in REGSET, starting with MIN, setting REGNUM to the
68 register number and executing CODE for all registers that are set. */
69 #define EXECUTE_IF_SET_IN_REG_SET(REGSET, MIN, REGNUM, CODE) \
70 EXECUTE_IF_SET_IN_BITMAP (REGSET, MIN, REGNUM, CODE)
72 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
73 REGNUM to the register number and executing CODE for all registers that are
74 set in the first regset and not set in the second. */
75 #define EXECUTE_IF_AND_COMPL_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
76 EXECUTE_IF_AND_COMPL_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
78 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
79 REGNUM to the register number and executing CODE for all registers that are
80 set in both regsets. */
81 #define EXECUTE_IF_AND_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
82 EXECUTE_IF_AND_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
84 /* Allocate a register set with oballoc. */
85 #define OBSTACK_ALLOC_REG_SET(OBSTACK) BITMAP_OBSTACK_ALLOC (OBSTACK)
87 /* Allocate a register set with alloca. */
88 #define ALLOCA_REG_SET() BITMAP_ALLOCA ()
90 /* Do any cleanup needed on a regset when it is no longer used. */
91 #define FREE_REG_SET(REGSET) BITMAP_FREE(REGSET)
93 /* Do any one-time initializations needed for regsets. */
94 #define INIT_ONCE_REG_SET() BITMAP_INIT_ONCE ()
96 /* Grow any tables needed when the number of registers is calculated
97 or extended. For the linked list allocation, nothing needs to
98 be done, other than zero the statistics on the first allocation. */
99 #define MAX_REGNO_REG_SET(NUM_REGS, NEW_P, RENUMBER_P)
101 /* Control flow edge information. */
102 typedef struct edge_def {
103 /* Links through the predecessor and successor lists. */
104 struct edge_def *pred_next, *succ_next;
106 /* The two blocks at the ends of the edge. */
107 struct basic_block_def *src, *dest;
109 /* Instructions queued on the edge. */
110 rtx insns;
112 /* Auxiliary info specific to a pass. */
113 void *aux;
115 int flags; /* see EDGE_* below */
116 int probability; /* biased by REG_BR_PROB_BASE */
117 } *edge;
119 #define EDGE_FALLTHRU 1
120 #define EDGE_CRITICAL 2
121 #define EDGE_ABNORMAL 4
122 #define EDGE_ABNORMAL_CALL 8
123 #define EDGE_EH 16
124 #define EDGE_FAKE 32
127 /* Basic block information indexed by block number. */
128 typedef struct basic_block_def {
129 /* The first and last insns of the block. */
130 rtx head, end;
132 /* The edges into and out of the block. */
133 edge pred, succ;
135 /* Liveness info. */
136 regset local_set;
137 regset global_live_at_start;
138 regset global_live_at_end;
140 /* Auxiliary info specific to a pass. */
141 void *aux;
143 /* The index of this block. */
144 int index;
145 /* The loop depth of this block plus one. */
146 int loop_depth;
148 /* The active eh region before head and after end. */
149 int eh_beg, eh_end;
150 } *basic_block;
152 /* Number of basic blocks in the current function. */
154 extern int n_basic_blocks;
156 /* Index by basic block number, get basic block struct info. */
158 extern varray_type basic_block_info;
160 #define BASIC_BLOCK(N) (VARRAY_BB (basic_block_info, (N)))
162 /* What registers are live at the setjmp call. */
164 extern regset regs_live_at_setjmp;
166 /* Indexed by n, gives number of basic block that (REG n) is used in.
167 If the value is REG_BLOCK_GLOBAL (-2),
168 it means (REG n) is used in more than one basic block.
169 REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
170 This information remains valid for the rest of the compilation
171 of the current function; it is used to control register allocation. */
173 #define REG_BLOCK_UNKNOWN -1
174 #define REG_BLOCK_GLOBAL -2
176 #define REG_BASIC_BLOCK(N) (VARRAY_REG (reg_n_info, N)->basic_block)
178 /* List of integers.
179 These are used for storing things like predecessors, etc.
181 This scheme isn't very space efficient, especially on 64 bit machines.
182 The interface is designed so that the implementation can be replaced with
183 something more efficient if desirable. */
185 typedef struct int_list {
186 struct int_list *next;
187 int val;
188 } int_list;
190 typedef int_list *int_list_ptr;
192 /* Integer list elements are allocated in blocks to reduce the frequency
193 of calls to malloc and to reduce the associated space overhead. */
195 typedef struct int_list_block {
196 struct int_list_block *next;
197 int nodes_left;
198 #define INT_LIST_NODES_IN_BLK 500
199 struct int_list nodes[INT_LIST_NODES_IN_BLK];
200 } int_list_block;
202 /* Given a pointer to the list, return pointer to first element. */
203 #define INT_LIST_FIRST(il) (il)
205 /* Given a pointer to a list element, return pointer to next element. */
206 #define INT_LIST_NEXT(p) ((p)->next)
208 /* Return non-zero if P points to the end of the list. */
209 #define INT_LIST_END(p) ((p) == NULL)
211 /* Return element pointed to by P. */
212 #define INT_LIST_VAL(p) ((p)->val)
214 #define INT_LIST_SET_VAL(p, new_val) ((p)->val = (new_val))
216 extern void free_int_list PROTO ((int_list_block **));
218 /* Stuff for recording basic block info. */
220 #define BLOCK_HEAD(B) (BASIC_BLOCK (B)->head)
221 #define BLOCK_END(B) (BASIC_BLOCK (B)->end)
223 /* Special block numbers [markers] for entry and exit. */
224 #define ENTRY_BLOCK (-1)
225 #define EXIT_BLOCK (-2)
227 /* Similarly, block pointers for the edge list. */
228 extern struct basic_block_def entry_exit_blocks[2];
229 #define ENTRY_BLOCK_PTR (&entry_exit_blocks[0])
230 #define EXIT_BLOCK_PTR (&entry_exit_blocks[1])
232 /* from flow.c */
233 extern void free_regset_vector PROTO ((regset *, int nelts));
235 extern varray_type basic_block_for_insn;
236 #define BLOCK_FOR_INSN(INSN) VARRAY_BB (basic_block_for_insn, INSN_UID (INSN))
237 #define BLOCK_NUM(INSN) (BLOCK_FOR_INSN (INSN)->index + 0)
239 extern void compute_bb_for_insn PROTO ((int));
240 extern void set_block_for_insn PROTO ((rtx, basic_block));
242 extern void dump_bb_data PROTO ((FILE *, int_list_ptr *,
243 int_list_ptr *, int));
244 extern void free_bb_mem PROTO ((void));
245 extern void free_basic_block_vars PROTO ((int));
247 extern basic_block split_edge PROTO ((edge));
248 extern void insert_insn_on_edge PROTO ((rtx, edge));
249 extern void commit_edge_insertions PROTO ((void));
250 extern void remove_fake_edges PROTO ((void));
251 extern void add_noreturn_fake_exit_edges PROTO ((void));
253 /* This structure maintains an edge list vector. */
254 struct edge_list
256 int num_blocks;
257 int num_edges;
258 edge *index_to_edge;
261 /* This is the value which indicates no edge is present. */
262 #define EDGE_INDEX_NO_EDGE -1
264 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
265 if there is no edge between the 2 basic blocks. */
266 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
268 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
269 block which is either the pred or succ end of the indexed edge. */
270 #define INDEX_EDGE_PRED_BB(el, index) ((el)->index_to_edge[(index)]->src)
271 #define INDEX_EDGE_SUCC_BB(el, index) ((el)->index_to_edge[(index)]->dest)
273 /* INDEX_EDGE returns a pointer to the edge. */
274 #define INDEX_EDGE(el, index) ((el)->index_to_edge[(index)])
276 /* Number of edges in the compressed edge list. */
277 #define NUM_EDGES(el) ((el)->num_edges)
279 struct edge_list * create_edge_list PROTO ((void));
280 void free_edge_list PROTO ((struct edge_list *));
281 void print_edge_list PROTO ((FILE *, struct edge_list *));
282 void verify_edge_list PROTO ((FILE *, struct edge_list *));
283 int find_edge_index PROTO ((struct edge_list *,
284 basic_block, basic_block));
286 extern void compute_preds_succs PROTO ((int_list_ptr *, int_list_ptr *,
287 int *, int *));
288 extern void compute_dominators PROTO ((sbitmap *, sbitmap *,
289 int_list_ptr *,
290 int_list_ptr *));
291 extern void compute_flow_dominators PROTO ((sbitmap *, sbitmap *));
292 extern void compute_immediate_dominators PROTO ((int *, sbitmap *));
294 /* In lcm.c */
295 extern void pre_lcm PROTO ((int, int, int_list_ptr *,
296 int_list_ptr *,
297 sbitmap *, sbitmap *,
298 sbitmap *, sbitmap *));
299 extern void pre_rev_lcm PROTO ((int, int, int_list_ptr *,
300 int_list_ptr *,
301 sbitmap *, sbitmap *,
302 sbitmap *, sbitmap *));