OSDN Git Service

[pf3gnuchains/gcc-fork.git] / gcc / basic-block.h
1 /* Define control and data flow tables, and regsets.
2    Copyright (C) 1987, 1997, 1998 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
24 typedef bitmap regset;          /* Head of register set linked list.  */
25
26 /* Clear a register set by freeing up the linked list.  */
27 #define CLEAR_REG_SET(HEAD) bitmap_clear (HEAD)
28
29 /* Copy a register set to another register set.  */
30 #define COPY_REG_SET(TO, FROM) bitmap_copy (TO, FROM)
31
32 /* `and' a register set with a second register set.  */
33 #define AND_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_AND)
34
35 /* `and' the complement of a register set with a register set.  */
36 #define AND_COMPL_REG_SET(TO, FROM) \
37   bitmap_operation (TO, TO, FROM, BITMAP_AND_COMPL)
38
39 /* Inclusive or a register set with a second register set.  */
40 #define IOR_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_IOR)
41
42 /* Or into TO the register set FROM1 `and'ed with the complement of FROM2.  */
43 #define IOR_AND_COMPL_REG_SET(TO, FROM1, FROM2) \
44   bitmap_ior_and_compl (TO, FROM1, FROM2)
45
46 /* Clear a single register in a register set.  */
47 #define CLEAR_REGNO_REG_SET(HEAD, REG) bitmap_clear_bit (HEAD, REG)
48
49 /* Set a single register in a register set.  */
50 #define SET_REGNO_REG_SET(HEAD, REG) bitmap_set_bit (HEAD, REG)
51
52 /* Return true if a register is set in a register set.  */
53 #define REGNO_REG_SET_P(TO, REG) bitmap_bit_p (TO, REG)
54
55 /* Copy the hard registers in a register set to the hard register set.  */
56 #define REG_SET_TO_HARD_REG_SET(TO, FROM)                               \
57 do {                                                                    \
58   int i_;                                                               \
59   CLEAR_HARD_REG_SET (TO);                                              \
60   for (i_ = 0; i_ < FIRST_PSEUDO_REGISTER; i_++)                        \
61     if (REGNO_REG_SET_P (FROM, i_))                                     \
62       SET_HARD_REG_BIT (TO, i_);                                        \
63 } while (0)
64
65 /* Loop over all registers in REGSET, starting with MIN, setting REGNUM to the
66    register number and executing CODE for all registers that are set. */
67 #define EXECUTE_IF_SET_IN_REG_SET(REGSET, MIN, REGNUM, CODE)            \
68   EXECUTE_IF_SET_IN_BITMAP (REGSET, MIN, REGNUM, CODE)
69
70 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
71    REGNUM to the register number and executing CODE for all registers that are
72    set in the first regset and not set in the second. */
73 #define EXECUTE_IF_AND_COMPL_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
74   EXECUTE_IF_AND_COMPL_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
75
76 /* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
77    REGNUM to the register number and executing CODE for all registers that are
78    set in both regsets. */
79 #define EXECUTE_IF_AND_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
80   EXECUTE_IF_AND_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
81
82 /* Allocate a register set with oballoc.  */
83 #define OBSTACK_ALLOC_REG_SET(OBSTACK) BITMAP_OBSTACK_ALLOC (OBSTACK)
84
85 /* Allocate a register set with alloca.  */
86 #define ALLOCA_REG_SET() BITMAP_ALLOCA ()
87
88 /* Do any cleanup needed on a regset when it is no longer used.  */
89 #define FREE_REG_SET(REGSET) BITMAP_FREE(REGSET)
90
91 /* Do any one-time initializations needed for regsets.  */
92 #define INIT_ONCE_REG_SET() BITMAP_INIT_ONCE ()
93
94 /* Grow any tables needed when the number of registers is calculated
95    or extended.  For the linked list allocation, nothing needs to
96    be done, other than zero the statistics on the first allocation.  */
97 #define MAX_REGNO_REG_SET(NUM_REGS, NEW_P, RENUMBER_P)
98
99 /* Number of basic blocks in the current function.  */
100
101 extern int n_basic_blocks;
102
103 /* Index by basic block number, get first insn in the block.  */
104
105 extern rtx *basic_block_head;
106
107 /* Index by basic block number, get last insn in the block.  */
108
109 extern rtx *basic_block_end;
110
111 /* Index by basic block number, determine whether the block can be reached
112    through a computed jump.  */
113
114 extern char *basic_block_computed_jump_target;
115
116 /* Index by basic block number, get address of regset
117    describing the registers live at the start of that block.  */
118
119 extern regset *basic_block_live_at_start;
120
121 /* What registers are live at the setjmp call.  */
122
123 extern regset regs_live_at_setjmp;
124
125 /* Indexed by n, gives number of basic block that  (REG n) is used in.
126    If the value is REG_BLOCK_GLOBAL (-2),
127    it means (REG n) is used in more than one basic block.
128    REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
129    This information remains valid for the rest of the compilation
130    of the current function; it is used to control register allocation.  */
131
132 #define REG_BLOCK_UNKNOWN -1
133 #define REG_BLOCK_GLOBAL -2
134
135 #define REG_BASIC_BLOCK(N) (VARRAY_REG (reg_n_info, N)->basic_block)
136
137 /* List of integers.
138    These are used for storing things like predecessors, etc.
139
140    This scheme isn't very space efficient, especially on 64 bit machines.
141    The interface is designed so that the implementation can be replaced with
142    something more efficient if desirable.  */
143
144 typedef struct int_list {
145   struct int_list *next;
146   int val;
147 } int_list;
148
149 typedef int_list *int_list_ptr;
150
151 /* Integer list elements are allocated in blocks to reduce the frequency
152    of calls to malloc and to reduce the associated space overhead.  */
153
154 typedef struct int_list_block {
155   struct int_list_block *next;
156   int nodes_left;
157 #define INT_LIST_NODES_IN_BLK 500
158   struct int_list nodes[INT_LIST_NODES_IN_BLK];
159 } int_list_block;
160
161 /* Given a pointer to the list, return pointer to first element.  */
162 #define INT_LIST_FIRST(il) (il)
163
164 /* Given a pointer to a list element, return pointer to next element.  */
165 #define INT_LIST_NEXT(p) ((p)->next)
166
167 /* Return non-zero if P points to the end of the list.  */
168 #define INT_LIST_END(p) ((p) == NULL)
169
170 /* Return element pointed to by P.  */
171 #define INT_LIST_VAL(p) ((p)->val)
172
173 #define INT_LIST_SET_VAL(p, new_val) ((p)->val = (new_val))
174
175 extern void free_int_list               PROTO ((int_list_block **));
176 \f
177 /* Stuff for recording basic block info.  */
178
179 #define BLOCK_HEAD(B)      basic_block_head[(B)]
180 #define BLOCK_END(B)       basic_block_end[(B)]
181
182 /* Special block numbers [markers] for entry and exit.  */
183 #define ENTRY_BLOCK (-1)
184 #define EXIT_BLOCK (-2)
185
186 /* from flow.c */
187 extern void free_regset_vector PROTO ((regset *, int nelts));
188 extern int *uid_block_number;
189 #define BLOCK_NUM(INSN)    uid_block_number[INSN_UID (INSN)]
190
191 extern void compute_preds_succs PROTO ((int_list_ptr *, int_list_ptr *,
192                                         int *, int *));
193 extern void dump_bb_data       PROTO ((FILE *, int_list_ptr *, int_list_ptr *));
194 extern void free_bb_mem        PROTO ((void));
195 extern void free_basic_block_vars       PROTO ((int));
196
197 \f
198 /* Simple bitmaps.
199    It's not clear yet whether using bitmap.[ch] will be a win.
200    It should be straightforward to convert so for now we keep things simple
201    while more important issues are dealt with.  */
202
203 #define SBITMAP_ELT_BITS HOST_BITS_PER_WIDE_INT
204 #define SBITMAP_ELT_TYPE unsigned HOST_WIDE_INT
205
206 typedef struct simple_bitmap_def {
207   /* Number of bits.  */
208   int n_bits;
209   /* Size in elements.  */
210   int size;
211   /* Size in bytes.  */
212   int bytes;
213   /* The elements.  */
214   SBITMAP_ELT_TYPE elms[1];
215 } *sbitmap;
216
217 typedef SBITMAP_ELT_TYPE *sbitmap_ptr;
218
219 /* Return the set size needed for N elements.  */
220 #define SBITMAP_SET_SIZE(n) (((n) + SBITMAP_ELT_BITS - 1) / SBITMAP_ELT_BITS)
221
222 /* set bit number bitno in the bitmap */
223 #define SET_BIT(bitmap, bitno) \
224 do { \
225   (bitmap)->elms [(bitno) / SBITMAP_ELT_BITS] |= (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS; \
226 } while (0)
227
228 /* test if bit number bitno in the bitmap is set */
229 #define TEST_BIT(bitmap, bitno) \
230 ((bitmap)->elms [(bitno) / SBITMAP_ELT_BITS] & ((SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS))
231
232 /* reset bit number bitno in the bitmap  */
233 #define RESET_BIT(bitmap, bitno) \
234 do { \
235   (bitmap)->elms [(bitno) / SBITMAP_ELT_BITS] &= ~((SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS); \
236 } while (0)
237
238 extern void dump_sbitmap       PROTO ((FILE *, sbitmap));
239 extern void dump_sbitmap_vector PROTO ((FILE *, char *, char *,
240                                         sbitmap *, int));
241 extern sbitmap sbitmap_alloc PROTO ((int));
242 extern sbitmap *sbitmap_vector_alloc PROTO ((int, int));
243 extern void sbitmap_copy PROTO ((sbitmap, sbitmap));
244 extern void sbitmap_zero PROTO ((sbitmap));
245 extern void sbitmap_ones PROTO ((sbitmap));
246 extern void sbitmap_vector_zero PROTO ((sbitmap *, int));
247 extern void sbitmap_vector_ones PROTO ((sbitmap *, int));
248 extern int sbitmap_union_of_diff PROTO ((sbitmap, sbitmap, sbitmap, sbitmap));
249 extern void sbitmap_difference PROTO ((sbitmap, sbitmap, sbitmap));
250 extern void sbitmap_not PROTO ((sbitmap, sbitmap));
251 extern int sbitmap_a_or_b_and_c PROTO ((sbitmap, sbitmap, sbitmap, sbitmap));
252 extern int sbitmap_a_and_b_or_c PROTO ((sbitmap, sbitmap, sbitmap, sbitmap));
253 extern int sbitmap_a_and_b PROTO ((sbitmap, sbitmap, sbitmap));
254 extern int sbitmap_a_or_b PROTO ((sbitmap, sbitmap, sbitmap));
255 extern void sbitmap_intersect_of_predsucc PROTO ((sbitmap, sbitmap *,
256                                                   int, int_list_ptr *));
257 extern void sbitmap_intersect_of_predecessors PROTO ((sbitmap, sbitmap *, int,
258                                                       int_list_ptr *));
259 extern void sbitmap_intersect_of_successors PROTO ((sbitmap, sbitmap *, int,
260                                                     int_list_ptr *));
261 extern void sbitmap_union_of_predecessors PROTO ((sbitmap, sbitmap *, int,
262                                                   int_list_ptr *));
263 extern void sbitmap_union_of_successors PROTO ((sbitmap, sbitmap *, int,
264                                                 int_list_ptr *));
265 extern void compute_dominators PROTO ((sbitmap *, sbitmap *,
266                                        int_list_ptr *, int_list_ptr *));