OSDN Git Service

Add regset_head and INIT_REG_SET.
[pf3gnuchains/gcc-fork.git] / gcc / basic-block.h
1 /* Define control and data flow tables, and regsets.
2    Copyright (C) 1987, 1997, 1998, 1999 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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.
10
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.
15
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.  */
20
21
22 #include "bitmap.h"
23 #include "sbitmap.h"
24 #include "varray.h"
25
26 /* Head of register set linked list.  */
27 typedef bitmap_head regset_head;
28 /* A pointer to a regset_head.  */
29 typedef bitmap regset;
30
31 /* Initialize a new regset.  */
32 #define INIT_REG_SET(HEAD) bitmap_initialize (HEAD)
33
34 /* Clear a register set by freeing up the linked list.  */
35 #define CLEAR_REG_SET(HEAD) bitmap_clear (HEAD)
36
37 /* Copy a register set to another register set.  */
38 #define COPY_REG_SET(TO, FROM) bitmap_copy (TO, FROM)
39
40 /* Compare two register sets.  */
41 #define REG_SET_EQUAL_P(A, B) bitmap_equal_p (A, B)
42
43 /* `and' a register set with a second register set.  */
44 #define AND_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_AND)
45
46 /* `and' the complement of a register set with a register set.  */
47 #define AND_COMPL_REG_SET(TO, FROM) \
48   bitmap_operation (TO, TO, FROM, BITMAP_AND_COMPL)
49
50 /* Inclusive or a register set with a second register set.  */
51 #define IOR_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_IOR)
52
53 /* Exclusive or a register set with a second register set.  */
54 #define XOR_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_XOR)
55
56 /* Or into TO the register set FROM1 `and'ed with the complement of FROM2.  */
57 #define IOR_AND_COMPL_REG_SET(TO, FROM1, FROM2) \
58   bitmap_ior_and_compl (TO, FROM1, FROM2)
59
60 /* Clear a single register in a register set.  */
61 #define CLEAR_REGNO_REG_SET(HEAD, REG) bitmap_clear_bit (HEAD, REG)
62
63 /* Set a single register in a register set.  */
64 #define SET_REGNO_REG_SET(HEAD, REG) bitmap_set_bit (HEAD, REG)
65
66 /* Return true if a register is set in a register set.  */
67 #define REGNO_REG_SET_P(TO, REG) bitmap_bit_p (TO, REG)
68
69 /* Copy the hard registers in a register set to the hard register set.  */
70 #define REG_SET_TO_HARD_REG_SET(TO, FROM)                               \
71 do {                                                                    \
72   int i_;                                                               \
73   CLEAR_HARD_REG_SET (TO);                                              \
74   for (i_ = 0; i_ < FIRST_PSEUDO_REGISTER; i_++)                        \
75     if (REGNO_REG_SET_P (FROM, i_))                                     \
76       SET_HARD_REG_BIT (TO, i_);                                        \
77 } while (0)
78
79 /* Loop over all registers in REGSET, starting with MIN, setting REGNUM to the
80    register number and executing CODE for all registers that are set. */
81 #define EXECUTE_IF_SET_IN_REG_SET(REGSET, MIN, REGNUM, CODE)            \
82   EXECUTE_IF_SET_IN_BITMAP (REGSET, MIN, REGNUM, CODE)
83
84 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
85    REGNUM to the register number and executing CODE for all registers that are
86    set in the first regset and not set in the second. */
87 #define EXECUTE_IF_AND_COMPL_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
88   EXECUTE_IF_AND_COMPL_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
89
90 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
91    REGNUM to the register number and executing CODE for all registers that are
92    set in both regsets. */
93 #define EXECUTE_IF_AND_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
94   EXECUTE_IF_AND_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
95
96 /* Allocate a register set with oballoc.  */
97 #define OBSTACK_ALLOC_REG_SET(OBSTACK) BITMAP_OBSTACK_ALLOC (OBSTACK)
98
99 /* Allocate a register set with alloca.  */
100 #define ALLOCA_REG_SET() BITMAP_ALLOCA ()
101
102 /* Do any cleanup needed on a regset when it is no longer used.  */
103 #define FREE_REG_SET(REGSET) BITMAP_FREE(REGSET)
104
105 /* Do any one-time initializations needed for regsets.  */
106 #define INIT_ONCE_REG_SET() BITMAP_INIT_ONCE ()
107
108 /* Grow any tables needed when the number of registers is calculated
109    or extended.  For the linked list allocation, nothing needs to
110    be done, other than zero the statistics on the first allocation.  */
111 #define MAX_REGNO_REG_SET(NUM_REGS, NEW_P, RENUMBER_P) 
112
113 /* Control flow edge information.  */
114 typedef struct edge_def {
115   /* Links through the predecessor and successor lists.  */
116   struct edge_def *pred_next, *succ_next;
117
118   /* The two blocks at the ends of the edge.  */
119   struct basic_block_def *src, *dest;
120
121   /* Instructions queued on the edge.  */
122   rtx insns;
123
124   /* Auxiliary info specific to a pass.  */
125   void *aux;
126
127   int flags;                    /* see EDGE_* below  */
128   int probability;              /* biased by REG_BR_PROB_BASE */
129 } *edge;
130
131 #define EDGE_FALLTHRU           1
132 #define EDGE_CRITICAL           2
133 #define EDGE_ABNORMAL           4
134 #define EDGE_ABNORMAL_CALL      8
135 #define EDGE_EH                 16
136 #define EDGE_FAKE               32
137
138
139 /* Basic block information indexed by block number.  */
140 typedef struct basic_block_def {
141   /* The first and last insns of the block.  */
142   rtx head, end;
143
144   /* The edges into and out of the block.  */
145   edge pred, succ;
146
147   /* Liveness info.  */
148   regset local_set;
149   regset global_live_at_start;
150   regset global_live_at_end;
151
152   /* Auxiliary info specific to a pass.  */
153   void *aux;
154
155   /* The index of this block.  */
156   int index;
157   /* The loop depth of this block plus one.  */
158   int loop_depth;
159
160   /* The active eh region before head and after end.  */
161   int eh_beg, eh_end;
162 } *basic_block;
163
164 /* Number of basic blocks in the current function.  */
165
166 extern int n_basic_blocks;
167
168 /* Number of edges in the current function.  */
169
170 extern int n_edges;
171
172 /* Index by basic block number, get basic block struct info.  */
173
174 extern varray_type basic_block_info;
175
176 #define BASIC_BLOCK(N)  (VARRAY_BB (basic_block_info, (N)))
177
178 /* What registers are live at the setjmp call.  */
179
180 extern regset regs_live_at_setjmp;
181
182 /* Indexed by n, gives number of basic block that  (REG n) is used in.
183    If the value is REG_BLOCK_GLOBAL (-2),
184    it means (REG n) is used in more than one basic block.
185    REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
186    This information remains valid for the rest of the compilation
187    of the current function; it is used to control register allocation.  */
188
189 #define REG_BLOCK_UNKNOWN -1
190 #define REG_BLOCK_GLOBAL -2
191
192 #define REG_BASIC_BLOCK(N) (VARRAY_REG (reg_n_info, N)->basic_block)
193 \f
194 /* Stuff for recording basic block info.  */
195
196 #define BLOCK_HEAD(B)      (BASIC_BLOCK (B)->head)
197 #define BLOCK_END(B)       (BASIC_BLOCK (B)->end)
198
199 /* Special block numbers [markers] for entry and exit.  */
200 #define ENTRY_BLOCK (-1)
201 #define EXIT_BLOCK (-2)
202
203 /* Similarly, block pointers for the edge list.  */
204 extern struct basic_block_def entry_exit_blocks[2];
205 #define ENTRY_BLOCK_PTR (&entry_exit_blocks[0])
206 #define EXIT_BLOCK_PTR  (&entry_exit_blocks[1])
207
208 extern varray_type basic_block_for_insn;
209 #define BLOCK_FOR_INSN(INSN)  VARRAY_BB (basic_block_for_insn, INSN_UID (INSN))
210 #define BLOCK_NUM(INSN)       (BLOCK_FOR_INSN (INSN)->index + 0)
211
212 extern void compute_bb_for_insn         PROTO ((int));
213 extern void set_block_for_insn          PROTO ((rtx, basic_block));
214 extern void set_block_num               PROTO ((rtx, int));
215
216 extern void free_basic_block_vars       PROTO ((int));
217
218 extern basic_block split_edge           PROTO ((edge));
219 extern void insert_insn_on_edge         PROTO ((rtx, edge));
220 extern void commit_edge_insertions      PROTO ((void));
221 extern void remove_fake_edges           PROTO ((void));
222 extern void add_noreturn_fake_exit_edges        PROTO ((void));
223 extern void flow_delete_insn_chain      PROTO((rtx, rtx));
224
225 /* This structure maintains an edge list vector.  */
226 struct edge_list 
227 {
228   int num_blocks;
229   int num_edges;
230   edge *index_to_edge;
231 };
232
233 /* This is the value which indicates no edge is present.  */
234 #define EDGE_INDEX_NO_EDGE      -1
235
236 /* EDGE_INDEX returns an integer index for an edge, or EDGE_INDEX_NO_EDGE
237    if there is no edge between the 2 basic blocks.  */
238 #define EDGE_INDEX(el, pred, succ) (find_edge_index ((el), (pred), (succ)))
239
240 /* INDEX_EDGE_PRED_BB and INDEX_EDGE_SUCC_BB return a pointer to the basic
241    block which is either the pred or succ end of the indexed edge.  */
242 #define INDEX_EDGE_PRED_BB(el, index)   ((el)->index_to_edge[(index)]->src)
243 #define INDEX_EDGE_SUCC_BB(el, index)   ((el)->index_to_edge[(index)]->dest)
244
245 /* INDEX_EDGE returns a pointer to the edge.  */
246 #define INDEX_EDGE(el, index)           ((el)->index_to_edge[(index)])
247
248 /* Number of edges in the compressed edge list.  */
249 #define NUM_EDGES(el)                   ((el)->num_edges)
250
251 struct edge_list * create_edge_list     PROTO ((void));
252 void free_edge_list                     PROTO ((struct edge_list *));
253 void print_edge_list                    PROTO ((FILE *, struct edge_list *));
254 void verify_edge_list                   PROTO ((FILE *, struct edge_list *));
255 int find_edge_index                     PROTO ((struct edge_list *, 
256                                                 basic_block, basic_block));
257
258 extern void compute_flow_dominators     PROTO ((sbitmap *, sbitmap *));
259 extern void compute_immediate_dominators        PROTO ((int *, sbitmap *));
260
261
262 enum update_life_extent
263 {
264   UPDATE_LIFE_LOCAL = 0,
265   UPDATE_LIFE_GLOBAL = 1,
266   UPDATE_LIFE_GLOBAL_RM_NOTES = 2
267 };
268
269 /* Flags for life_analysis and update_life_info.  */
270
271 #define PROP_DEATH_NOTES        1       /* Create DEAD and UNUSED notes.  */
272 #define PROP_LOG_LINKS          2       /* Create LOG_LINKS.  */
273 #define PROP_REG_INFO           4       /* Update regs_ever_live et al.  */
274 #define PROP_KILL_DEAD_CODE     8       /* Remove dead code.  */
275 #define PROP_SCAN_DEAD_CODE     16      /* Scan for dead code.  */
276 #define PROP_AUTOINC            32      /* Create autoinc mem references.  */
277 #define PROP_FINAL              63      /* All of the above.  */
278
279 extern void update_life_info    PROTO ((sbitmap, enum update_life_extent,
280                                         int));
281 extern int count_or_remove_death_notes  PROTO ((sbitmap, int));
282
283 /* In lcm.c */
284 extern struct edge_list *pre_edge_lcm   PROTO ((FILE *, int, sbitmap *,
285                                                 sbitmap *, sbitmap *, 
286                                                 sbitmap *, sbitmap **,
287                                                 sbitmap **));
288 extern struct edge_list *pre_edge_rev_lcm PROTO ((FILE *, int, sbitmap *,
289                                                   sbitmap *, sbitmap *, 
290                                                   sbitmap *, sbitmap **, 
291                                                   sbitmap **));
292 extern void compute_available           PROTO ((sbitmap *, sbitmap *,
293                                                 sbitmap *, sbitmap *));
294
295 /* In emit-rtl.c.  */
296 extern rtx emit_block_insn_after        PROTO((rtx, rtx, basic_block));
297 extern rtx emit_block_insn_before       PROTO((rtx, rtx, basic_block));