basic-block.h revision 52284
121308Sache/* Define control and data flow tables, and regsets.
221308Sache   Copyright (C) 1987, 1997, 1998, 1999 Free Software Foundation, Inc.
321308Sache
421308SacheThis file is part of GNU CC.
521308Sache
621308SacheGNU CC is free software; you can redistribute it and/or modify
721308Sacheit under the terms of the GNU General Public License as published by
821308Sachethe Free Software Foundation; either version 2, or (at your option)
921308Sacheany later version.
1021308Sache
1158310SacheGNU CC is distributed in the hope that it will be useful,
1221308Sachebut WITHOUT ANY WARRANTY; without even the implied warranty of
1321308SacheMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1421308SacheGNU General Public License for more details.
1521308Sache
1621308SacheYou should have received a copy of the GNU General Public License
1721308Sachealong with GNU CC; see the file COPYING.  If not, write to
1821308Sachethe Free Software Foundation, 59 Temple Place - Suite 330,
1921308SacheBoston, MA 02111-1307, USA.  */
2021308Sache
2121308Sache
2258310Sache#include "bitmap.h"
2321308Sache#include "sbitmap.h"
2421308Sache#include "varray.h"
2558310Sache
2621308Sachetypedef bitmap regset;		/* Head of register set linked list.  */
2721308Sache
2821308Sache/* Clear a register set by freeing up the linked list.  */
2921308Sache#define CLEAR_REG_SET(HEAD) bitmap_clear (HEAD)
3021308Sache
3121308Sache/* Copy a register set to another register set.  */
3221308Sache#define COPY_REG_SET(TO, FROM) bitmap_copy (TO, FROM)
3321308Sache
3421308Sache/* `and' a register set with a second register set.  */
3521308Sache#define AND_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_AND)
3621308Sache
3721308Sache/* `and' the complement of a register set with a register set.  */
3821308Sache#define AND_COMPL_REG_SET(TO, FROM) \
3921308Sache  bitmap_operation (TO, TO, FROM, BITMAP_AND_COMPL)
4021308Sache
4121308Sache/* Inclusive or a register set with a second register set.  */
4221308Sache#define IOR_REG_SET(TO, FROM) bitmap_operation (TO, TO, FROM, BITMAP_IOR)
4321308Sache
4421308Sache/* Or into TO the register set FROM1 `and'ed with the complement of FROM2.  */
4535486Sache#define IOR_AND_COMPL_REG_SET(TO, FROM1, FROM2) \
4626497Sache  bitmap_ior_and_compl (TO, FROM1, FROM2)
4721308Sache
4821308Sache/* Clear a single register in a register set.  */
4921308Sache#define CLEAR_REGNO_REG_SET(HEAD, REG) bitmap_clear_bit (HEAD, REG)
5021308Sache
5121308Sache/* Set a single register in a register set.  */
5221308Sache#define SET_REGNO_REG_SET(HEAD, REG) bitmap_set_bit (HEAD, REG)
5321308Sache
5421308Sache/* Return true if a register is set in a register set.  */
5521308Sache#define REGNO_REG_SET_P(TO, REG) bitmap_bit_p (TO, REG)
5621308Sache
5721308Sache/* Copy the hard registers in a register set to the hard register set.  */
5821308Sache#define REG_SET_TO_HARD_REG_SET(TO, FROM)				\
5921308Sachedo {									\
6021308Sache  int i_;								\
6121308Sache  CLEAR_HARD_REG_SET (TO);						\
6221308Sache  for (i_ = 0; i_ < FIRST_PSEUDO_REGISTER; i_++)			\
6358310Sache    if (REGNO_REG_SET_P (FROM, i_))					\
64136644Sache      SET_HARD_REG_BIT (TO, i_);					\
65136644Sache} while (0)
66136644Sache
67136644Sache/* Loop over all registers in REGSET, starting with MIN, setting REGNUM to the
68136644Sache   register number and executing CODE for all registers that are set. */
69136644Sache#define EXECUTE_IF_SET_IN_REG_SET(REGSET, MIN, REGNUM, CODE)		\
70136644Sache  EXECUTE_IF_SET_IN_BITMAP (REGSET, MIN, REGNUM, CODE)
71136644Sache
72136644Sache/* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
73136644Sache   REGNUM to the register number and executing CODE for all registers that are
74136644Sache   set in the first regset and not set in the second. */
75136644Sache#define EXECUTE_IF_AND_COMPL_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
76136644Sache  EXECUTE_IF_AND_COMPL_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
77136644Sache
78136644Sache/* Loop over all registers in REGSET1 and REGSET2, starting with MIN, setting
79136644Sache   REGNUM to the register number and executing CODE for all registers that are
8058310Sache   set in both regsets. */
8158310Sache#define EXECUTE_IF_AND_IN_REG_SET(REGSET1, REGSET2, MIN, REGNUM, CODE) \
8221308Sache  EXECUTE_IF_AND_IN_BITMAP (REGSET1, REGSET2, MIN, REGNUM, CODE)
83
84/* Allocate a register set with oballoc.  */
85#define OBSTACK_ALLOC_REG_SET(OBSTACK) BITMAP_OBSTACK_ALLOC (OBSTACK)
86
87/* Allocate a register set with alloca.  */
88#define ALLOCA_REG_SET() BITMAP_ALLOCA ()
89
90/* Do any cleanup needed on a regset when it is no longer used.  */
91#define FREE_REG_SET(REGSET) BITMAP_FREE(REGSET)
92
93/* Do any one-time initializations needed for regsets.  */
94#define INIT_ONCE_REG_SET() BITMAP_INIT_ONCE ()
95
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)
100
101/* Control flow edge information.  */
102typedef struct edge_def {
103  /* Links through the predecessor and successor lists.  */
104  struct edge_def *pred_next, *succ_next;
105
106  /* The two blocks at the ends of the edge.  */
107  struct basic_block_def *src, *dest;
108
109  /* Instructions queued on the edge.  */
110  rtx insns;
111
112  /* Auxiliary info specific to a pass.  */
113  void *aux;
114
115  int flags;			/* see EDGE_* below  */
116  int probability;		/* biased by REG_BR_PROB_BASE */
117} *edge;
118
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
125
126
127/* Basic block information indexed by block number.  */
128typedef struct basic_block_def {
129  /* The first and last insns of the block.  */
130  rtx head, end;
131
132  /* The edges into and out of the block.  */
133  edge pred, succ;
134
135  /* Liveness info.  */
136  regset local_set;
137  regset global_live_at_start;
138  regset global_live_at_end;
139
140  /* Auxiliary info specific to a pass.  */
141  void *aux;
142
143  /* The index of this block.  */
144  int index;
145  /* The loop depth of this block plus one.  */
146  int loop_depth;
147} *basic_block;
148
149/* Number of basic blocks in the current function.  */
150
151extern int n_basic_blocks;
152
153/* Index by basic block number, get basic block struct info.  */
154
155extern varray_type basic_block_info;
156
157#define BASIC_BLOCK(N)  (VARRAY_BB (basic_block_info, (N)))
158
159/* What registers are live at the setjmp call.  */
160
161extern regset regs_live_at_setjmp;
162
163/* Indexed by n, gives number of basic block that  (REG n) is used in.
164   If the value is REG_BLOCK_GLOBAL (-2),
165   it means (REG n) is used in more than one basic block.
166   REG_BLOCK_UNKNOWN (-1) means it hasn't been seen yet so we don't know.
167   This information remains valid for the rest of the compilation
168   of the current function; it is used to control register allocation.  */
169
170#define REG_BLOCK_UNKNOWN -1
171#define REG_BLOCK_GLOBAL -2
172
173#define REG_BASIC_BLOCK(N) (VARRAY_REG (reg_n_info, N)->basic_block)
174
175/* List of integers.
176   These are used for storing things like predecessors, etc.
177
178   This scheme isn't very space efficient, especially on 64 bit machines.
179   The interface is designed so that the implementation can be replaced with
180   something more efficient if desirable.  */
181
182typedef struct int_list {
183  struct int_list *next;
184  int val;
185} int_list;
186
187typedef int_list *int_list_ptr;
188
189/* Integer list elements are allocated in blocks to reduce the frequency
190   of calls to malloc and to reduce the associated space overhead.  */
191
192typedef struct int_list_block {
193  struct int_list_block *next;
194  int nodes_left;
195#define INT_LIST_NODES_IN_BLK 500
196  struct int_list nodes[INT_LIST_NODES_IN_BLK];
197} int_list_block;
198
199/* Given a pointer to the list, return pointer to first element.  */
200#define INT_LIST_FIRST(il) (il)
201
202/* Given a pointer to a list element, return pointer to next element.  */
203#define INT_LIST_NEXT(p) ((p)->next)
204
205/* Return non-zero if P points to the end of the list.  */
206#define INT_LIST_END(p) ((p) == NULL)
207
208/* Return element pointed to by P.  */
209#define INT_LIST_VAL(p) ((p)->val)
210
211#define INT_LIST_SET_VAL(p, new_val) ((p)->val = (new_val))
212
213extern void free_int_list               PROTO ((int_list_block **));
214
215/* Stuff for recording basic block info.  */
216
217#define BLOCK_HEAD(B)      (BASIC_BLOCK (B)->head)
218#define BLOCK_END(B)       (BASIC_BLOCK (B)->end)
219
220/* Special block numbers [markers] for entry and exit.  */
221#define ENTRY_BLOCK (-1)
222#define EXIT_BLOCK (-2)
223
224/* Similarly, block pointers for the edge list.  */
225extern struct basic_block_def entry_exit_blocks[2];
226#define ENTRY_BLOCK_PTR	(&entry_exit_blocks[0])
227#define EXIT_BLOCK_PTR	(&entry_exit_blocks[1])
228
229/* from flow.c */
230extern void free_regset_vector		PROTO ((regset *, int nelts));
231
232extern varray_type basic_block_for_insn;
233#define BLOCK_FOR_INSN(INSN)  VARRAY_BB (basic_block_for_insn, INSN_UID (INSN))
234#define BLOCK_NUM(INSN)	      (BLOCK_FOR_INSN (INSN)->index + 0)
235
236extern void set_block_for_insn		PROTO ((rtx, basic_block));
237
238extern void dump_bb_data		PROTO ((FILE *, int_list_ptr *,
239						int_list_ptr *, int));
240extern void free_bb_mem			PROTO ((void));
241extern void free_basic_block_vars	PROTO ((int));
242
243extern basic_block split_edge		PROTO ((edge));
244extern void insert_insn_on_edge		PROTO ((rtx, edge));
245extern void commit_edge_insertions	PROTO ((void));
246
247extern void compute_preds_succs		PROTO ((int_list_ptr *, int_list_ptr *,
248						int *, int *));
249extern void compute_dominators		PROTO ((sbitmap *, sbitmap *,
250						int_list_ptr *,
251						int_list_ptr *));
252extern void compute_immediate_dominators	PROTO ((int *, sbitmap *));
253
254/* In lcm.c */
255extern void pre_lcm 			PROTO ((int, int, int_list_ptr *,
256						int_list_ptr *,
257						sbitmap *, sbitmap *,
258						sbitmap *, sbitmap *));
259extern void pre_rev_lcm 		PROTO ((int, int, int_list_ptr *,
260						int_list_ptr *,
261						sbitmap *, sbitmap *,
262						sbitmap *, sbitmap *));
263