OSDN Git Service

* Makefile.in: Remove pointless setting of CXXFLAGS for dejagnu
[pf3gnuchains/gcc-fork.git] / gcc / df.h
1 /* Form lists of pseudo register references for autoinc optimization
2    for GNU compiler.  This is part of flow optimization.  
3    Copyright (C) 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
4    Contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING.  If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA.  */
22
23 #define DF_RD            1      /* Reaching definitions.  */
24 #define DF_RU            2      /* Reaching uses.  */
25 #define DF_LR            4      /* Live registers.  */
26 #define DF_DU_CHAIN      8      /* Def-use chain.  */
27 #define DF_UD_CHAIN     16      /* Use-def chain.  */
28 #define DF_REG_INFO     32      /* Register info.  */
29 #define DF_RD_CHAIN     64      /* Reg-def chain.  */
30 #define DF_RU_CHAIN    128      /* Reg-use chain.  */
31 #define DF_ALL         255
32 #define DF_HARD_REGS  1024      /* Mark hard registers.  */
33 #define DF_EQUIV_NOTES 2048     /* Mark uses present in EQUIV/EQUAL notes.  */
34
35 enum df_ref_type {DF_REF_REG_DEF, DF_REF_REG_USE, DF_REF_REG_MEM_LOAD,
36                   DF_REF_REG_MEM_STORE};
37
38 #define DF_REF_TYPE_NAMES {"def", "use", "mem load", "mem store"}
39
40 /* Link on a def-use or use-def chain.  */
41 struct df_link
42 {
43   struct df_link *next;
44   struct ref *ref;
45 };
46
47 enum df_ref_flags
48   {
49     /* Read-modify-write refs generate both a use and a def and
50        these are marked with this flag to show that they are not
51        independent.  */
52     DF_REF_READ_WRITE = 1,
53     
54     /* This flag is set on register references inside a subreg on
55        machines which have CLASS_CANNOT_CHANGE_MODE and where the mode
56        change of that subreg expression is invalid for this class.
57        Note, that this flag can also be set on df_refs representing
58        the REG itself (i.e., one might not see the subreg anyore).
59        Also note, that this flag is set also for hardreg refs, i.e.,
60        you must check yourself if it's a pseudo.  */
61     DF_REF_MODE_CHANGE = 2
62   };
63
64
65 /* Define a register reference structure.  One of these is allocated
66    for every register reference (use or def).  Note some register
67    references (e.g., post_inc, subreg) generate both a def and a use.  */
68 struct ref
69 {
70   rtx reg;                      /* The register referenced.  */
71   rtx insn;                     /* Insn containing ref.  */
72   rtx *loc;                     /* The location of the reg.  */
73   struct df_link *chain;        /* Head of def-use or use-def chain.  */
74   unsigned int id;              /* Ref index.  */
75   enum df_ref_type type;        /* Type of ref.  */
76   enum df_ref_flags flags;      /* Various flags.  */
77 };
78
79
80 /* One of these structures is allocated for every insn.  */
81 struct insn_info
82 {
83   struct df_link *defs;         /* Head of insn-def chain.  */
84   struct df_link *uses;         /* Head of insn-use chain.  */
85   /* ???? The following luid field should be considerd private so that
86      we can change it on the fly to accommodate new insns?  */
87   int luid;                     /* Logical UID.  */
88 };
89
90
91 /* One of these structures is allocated for every reg.  */
92 struct reg_info
93 {
94   struct df_link *defs;         /* Head of reg-def chain.  */
95   struct df_link *uses;         /* Head of reg-use chain.  */
96   int lifetime;
97   int n_defs;
98   int n_uses;
99 };
100
101
102 /* One of these structures is allocated for every basic block.  */
103 struct bb_info
104 {
105   /* Reaching def bitmaps have def_id elements.  */
106   bitmap rd_kill;
107   bitmap rd_gen;
108   bitmap rd_in;
109   bitmap rd_out;
110   /* Reaching use bitmaps have use_id elements.  */
111   bitmap ru_kill;
112   bitmap ru_gen;
113   bitmap ru_in;
114   bitmap ru_out;
115   /* Live variable bitmaps have n_regs elements.  */
116   bitmap lr_def;
117   bitmap lr_use;
118   bitmap lr_in;
119   bitmap lr_out;
120   int rd_valid;
121   int ru_valid;
122   int lr_valid;
123 };
124
125
126 struct df
127 {
128   int flags;                    /* Indicates what's recorded.  */
129   struct bb_info *bbs;          /* Basic block table.  */
130   struct ref **defs;            /* Def table, indexed by def_id.  */
131   struct ref **uses;            /* Use table, indexed by use_id.  */
132   struct ref **reg_def_last;    /* Indexed by regno.  */
133   struct reg_info *regs;        /* Regs table, index by regno.  */
134   unsigned int reg_size;        /* Size of regs table.  */
135   struct insn_info *insns;      /* Insn table, indexed by insn UID.  */
136   unsigned int insn_size;       /* Size of insn table.  */
137   unsigned int def_id;          /* Next def ID.  */
138   unsigned int def_size;        /* Size of def table.  */
139   unsigned int n_defs;          /* Size of def bitmaps.  */
140   unsigned int use_id;          /* Next use ID.  */
141   unsigned int use_size;        /* Size of use table.  */
142   unsigned int n_uses;          /* Size of use bitmaps.  */
143   unsigned int n_bbs;           /* Number of basic blocks.  */
144   unsigned int n_regs;          /* Number of regs.  */
145   unsigned int def_id_save;     /* Saved next def ID.  */
146   unsigned int use_id_save;     /* Saved next use ID.  */
147   bitmap insns_modified;        /* Insns that (may) have changed.  */
148   bitmap bbs_modified;          /* Blocks that (may) have changed.  */
149   bitmap all_blocks;            /* All blocks in CFG.  */
150   /* The sbitmap vector of dominators or NULL if not computed. 
151      Ideally, this should be a pointer to a CFG object.  */
152   sbitmap *dom;
153   int *dfs_order;               /* DFS order -> block number.  */
154   int *rc_order;                /* Reverse completion order -> block number.  */
155   int *rts_order;               /* Reverse top sort order -> block number.  */
156   int *inverse_rc_map;          /* Block number -> reverse completion order.  */
157   int *inverse_dfs_map;         /* Block number -> DFS order.  */
158   int *inverse_rts_map;         /* Block number -> reverse top-sort order.  */
159 };
160
161
162 struct df_map
163 {
164   rtx old;
165   rtx new;
166 };
167
168
169 #define DF_BB_INFO(REFS, BB) (&REFS->bbs[(BB)->index])
170
171
172 /* Macros to access the elements within the ref structure.  */
173
174 #define DF_REF_REAL_REG(REF) (GET_CODE ((REF)->reg) == SUBREG \
175                                 ? SUBREG_REG ((REF)->reg) : ((REF)->reg))
176 #define DF_REF_REGNO(REF) REGNO (DF_REF_REAL_REG (REF))
177 #define DF_REF_REAL_LOC(REF) (GET_CODE ((REF)->reg) == SUBREG \
178                                 ? &SUBREG_REG ((REF)->reg) : ((REF)->loc))
179 #define DF_REF_REG(REF) ((REF)->reg)
180 #define DF_REF_LOC(REF) ((REF)->loc)
181 #define DF_REF_BB(REF) (BLOCK_FOR_INSN ((REF)->insn))
182 #define DF_REF_BBNO(REF) (BLOCK_FOR_INSN ((REF)->insn)->index)
183 #define DF_REF_INSN(REF) ((REF)->insn)
184 #define DF_REF_INSN_UID(REF) (INSN_UID ((REF)->insn))
185 #define DF_REF_TYPE(REF) ((REF)->type)
186 #define DF_REF_CHAIN(REF) ((REF)->chain)
187 #define DF_REF_ID(REF) ((REF)->id)
188 #define DF_REF_FLAGS(REF) ((REF)->flags)
189
190 /* Macros to determine the reference type.  */
191
192 #define DF_REF_REG_DEF_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_DEF)
193 #define DF_REF_REG_USE_P(REF) ((REF) && ! DF_REF_REG_DEF_P (REF))
194 #define DF_REF_REG_MEM_STORE_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_STORE)
195 #define DF_REF_REG_MEM_LOAD_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_LOAD)
196 #define DF_REF_REG_MEM_P(REF) (DF_REF_REG_MEM_STORE_P (REF) \
197                                || DF_REF_REG_MEM_LOAD_P (REF))
198
199
200 /* Macros to access the elements within the reg_info structure table.  */
201
202 #define DF_REGNO_FIRST_DEF(DF, REGNUM) \
203 ((DF)->regs[REGNUM].defs ? (DF)->regs[REGNUM].defs->ref : 0)
204 #define DF_REGNO_LAST_USE(DF, REGNUM) \
205 ((DF)->regs[REGNUM].uses ? (DF)->regs[REGNUM].uses->ref : 0)
206
207 #define DF_REGNO_FIRST_BB(DF, REGNUM) \
208 (DF_REGNO_FIRST_DEF (DF, REGNUM) \
209 ? DF_REF_BB (DF_REGNO_FIRST_DEF (DF, REGNUM)) : 0)
210 #define DF_REGNO_LAST_BB(DF, REGNUM) \
211 (DF_REGNO_LAST_USE (DF, REGNUM) \
212 ? DF_REF_BB (DF_REGNO_LAST_USE (DF, REGNUM)) : 0)
213
214
215 /* Macros to access the elements within the insn_info structure table.  */
216
217 #define DF_INSN_LUID(DF, INSN) ((DF)->insns[INSN_UID (INSN)].luid)
218 #define DF_INSN_DEFS(DF, INSN) ((DF)->insns[INSN_UID (INSN)].defs)
219 #define DF_INSN_USES(DF, INSN) ((DF)->insns[INSN_UID (INSN)].uses)
220
221
222 /* Functions to build and analyse dataflow information.  */
223
224 extern struct df *df_init PARAMS ((void));
225
226 extern int df_analyse PARAMS ((struct df *, bitmap, int));
227
228 extern void df_finish PARAMS ((struct df *));
229
230 extern void df_dump PARAMS ((struct df *, int, FILE *));
231
232
233 /* Functions to modify insns.  */
234
235 extern void df_insn_modify PARAMS ((struct df *, basic_block, rtx));
236
237 extern rtx df_insn_delete PARAMS ((struct df *, basic_block, rtx));
238
239 extern rtx df_pattern_emit_before PARAMS ((struct df *, rtx, 
240                                            basic_block, rtx));
241
242 extern rtx df_jump_pattern_emit_after PARAMS ((struct df *, rtx, 
243                                                basic_block, rtx));
244
245 extern rtx df_pattern_emit_after PARAMS ((struct df *, rtx, 
246                                           basic_block, rtx));
247
248 extern rtx df_insn_move_before PARAMS ((struct df *, basic_block, rtx,
249                                         basic_block, rtx));
250
251 extern int df_reg_replace PARAMS ((struct df *, bitmap, rtx, rtx));
252
253 extern int df_ref_reg_replace PARAMS ((struct df *, struct ref *, rtx, rtx));
254
255 extern int df_ref_remove PARAMS ((struct df *, struct ref *));
256
257 extern int df_insn_reg_replace PARAMS ((struct df *, basic_block,
258                                         rtx, rtx, rtx));
259
260 extern int df_insn_mem_replace PARAMS ((struct df *, basic_block,
261                                         rtx, rtx, rtx));
262
263 extern struct ref *df_bb_def_use_swap PARAMS ((struct df *, basic_block, 
264                                                rtx, rtx, unsigned int));
265
266
267 /* Functions to query dataflow information.  */
268
269 extern basic_block df_regno_bb PARAMS((struct df *, unsigned int));
270
271 extern int df_reg_lifetime PARAMS ((struct df *, rtx));
272
273 extern int df_reg_global_p PARAMS ((struct df *, rtx));
274
275 extern int df_insn_regno_def_p PARAMS ((struct df *, 
276                                         basic_block, rtx, unsigned int));
277
278 extern int df_insn_dominates_all_uses_p PARAMS ((struct df *, 
279                                                  basic_block, rtx));
280
281 extern int df_insn_dominates_uses_p PARAMS ((struct df *, basic_block,
282                                              rtx, bitmap));
283
284 extern int df_bb_reg_live_start_p PARAMS ((struct df *, basic_block, rtx));
285
286 extern int df_bb_reg_live_end_p PARAMS ((struct df *, basic_block, rtx));
287
288 extern int df_bb_regs_lives_compare PARAMS ((struct df *, basic_block,
289                                              rtx, rtx));
290
291 extern rtx df_bb_single_def_use_insn_find PARAMS((struct df *, basic_block,
292                                                   rtx, rtx));
293
294
295 /* Functions for debugging from GDB.  */
296
297 extern void debug_df_insn PARAMS ((rtx));
298
299 extern void debug_df_regno PARAMS ((unsigned int));
300
301 extern void debug_df_reg PARAMS ((rtx));
302
303 extern void debug_df_defno PARAMS ((unsigned int));
304
305 extern void debug_df_useno PARAMS ((unsigned int));
306
307 extern void debug_df_ref PARAMS ((struct ref *));
308
309 extern void debug_df_chain PARAMS ((struct df_link *));
310
311 extern void df_insn_debug PARAMS ((struct df *, rtx, FILE *));
312
313 extern void df_insn_debug_regno PARAMS ((struct df *, rtx, FILE *));
314
315
316 /* Meet over any path (UNION) or meet over all paths (INTERSECTION).  */
317 enum df_confluence_op
318   {
319     DF_UNION,
320     DF_INTERSECTION
321   };
322
323
324 /* Dataflow direction.  */
325 enum df_flow_dir
326   {
327     DF_FORWARD,
328     DF_BACKWARD
329   };
330
331
332 typedef void (*transfer_function_sbitmap) PARAMS ((int, int *, sbitmap, sbitmap, 
333                                                    sbitmap, sbitmap, void *));
334
335 typedef void (*transfer_function_bitmap) PARAMS ((int, int *, bitmap, bitmap,
336                                                   bitmap, bitmap, void *));
337
338 extern void iterative_dataflow_sbitmap PARAMS ((sbitmap *, sbitmap *, 
339                                                 sbitmap *, sbitmap *, 
340                                                 bitmap, enum df_flow_dir, 
341                                                 enum df_confluence_op, 
342                                                 transfer_function_sbitmap, 
343                                                 int *, void *));
344
345 extern void iterative_dataflow_bitmap PARAMS ((bitmap *, bitmap *, bitmap *, 
346                                                bitmap *, bitmap, 
347                                                enum df_flow_dir, 
348                                                enum df_confluence_op, 
349                                                transfer_function_bitmap, 
350                                                int *, void *));