OSDN Git Service

2004-06-09 Benjamin Kosnik <bkoz@redhat.com>
[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, 2004 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 #ifndef GCC_DF_H
24 #define GCC_DF_H
25
26 #include "bitmap.h"
27 #include "sbitmap.h"
28 #include "basic-block.h"
29
30 #define DF_RD           1       /* Reaching definitions.  */
31 #define DF_RU           2       /* Reaching uses.  */
32 #define DF_LR           4       /* Live registers.  */
33 #define DF_DU_CHAIN     8       /* Def-use chain.  */
34 #define DF_UD_CHAIN     16      /* Use-def chain.  */
35 #define DF_REG_INFO     32      /* Register info.  */
36 #define DF_RD_CHAIN     64      /* Reg-def chain.  */
37 #define DF_RU_CHAIN     128     /* Reg-use chain.  */
38 #define DF_ALL          255
39 #define DF_HARD_REGS    1024    /* Mark hard registers.  */
40 #define DF_EQUIV_NOTES  2048    /* Mark uses present in EQUIV/EQUAL notes.  */
41 #define DF_FOR_REGALLOC 4096    /* If called for the register allocator.  */
42
43 enum df_ref_type {DF_REF_REG_DEF, DF_REF_REG_USE, DF_REF_REG_MEM_LOAD,
44                   DF_REF_REG_MEM_STORE};
45
46 #define DF_REF_TYPE_NAMES {"def", "use", "mem load", "mem store"}
47
48 /* Link on a def-use or use-def chain.  */
49 struct df_link
50 {
51   struct df_link *next;
52   struct ref *ref;
53 };
54
55 enum df_ref_flags
56   {
57     /* Read-modify-write refs generate both a use and a def and
58        these are marked with this flag to show that they are not
59        independent.  */
60     DF_REF_READ_WRITE = 1,
61
62     /* This flag is set on register references inside a subreg on
63        machines which have CANNOT_CHANGE_MODE_CLASS.
64        Note, that this flag can also be set on df_refs representing
65        the REG itself (i.e., one might not see the subreg anymore).
66        Also note, that this flag is set also for hardreg refs, i.e.,
67        you must check yourself if it's a pseudo.  */
68     DF_REF_MODE_CHANGE = 2,
69
70     /* This flag is set, if we stripped the subreg from the reference.
71        In this case we must make conservative guesses, at what the
72        outer mode was.  */
73     DF_REF_STRIPPED = 4,
74
75     /* This flag is set during register allocation if it's okay for
76     the reference's INSN to have one of its operands replaced with a
77     memory reference.  */
78     DF_REF_MEM_OK = 8
79   };
80
81
82 /* Define a register reference structure.  One of these is allocated
83    for every register reference (use or def).  Note some register
84    references (e.g., post_inc, subreg) generate both a def and a use.  */
85 struct ref
86 {
87   rtx reg;                      /* The register referenced.  */
88   rtx insn;                     /* Insn containing ref.  */
89   rtx *loc;                     /* The location of the reg.  */
90   struct df_link *chain;        /* Head of def-use or use-def chain.  */
91   unsigned int id;              /* Ref index.  */
92   enum df_ref_type type;        /* Type of ref.  */
93   enum df_ref_flags flags;      /* Various flags.  */
94 };
95
96
97 /* One of these structures is allocated for every insn.  */
98 struct insn_info
99 {
100   struct df_link *defs;         /* Head of insn-def chain.  */
101   struct df_link *uses;         /* Head of insn-use chain.  */
102   /* ???? The following luid field should be considered private so that
103      we can change it on the fly to accommodate new insns?  */
104   int luid;                     /* Logical UID.  */
105 };
106
107
108 /* One of these structures is allocated for every reg.  */
109 struct reg_info
110 {
111   struct df_link *defs;         /* Head of reg-def chain.  */
112   struct df_link *uses;         /* Head of reg-use chain.  */
113   int lifetime;
114   int n_defs;
115   int n_uses;
116 };
117
118
119 /* One of these structures is allocated for every basic block.  */
120 struct bb_info
121 {
122   /* Reaching def bitmaps have def_id elements.  */
123   bitmap rd_kill;
124   bitmap rd_gen;
125   bitmap rd_in;
126   bitmap rd_out;
127   /* Reaching use bitmaps have use_id elements.  */
128   bitmap ru_kill;
129   bitmap ru_gen;
130   bitmap ru_in;
131   bitmap ru_out;
132   /* Live variable bitmaps have n_regs elements.  */
133   bitmap lr_def;
134   bitmap lr_use;
135   bitmap lr_in;
136   bitmap lr_out;
137   int rd_valid;
138   int ru_valid;
139   int lr_valid;
140 };
141
142
143 struct df
144 {
145   int flags;                    /* Indicates what's recorded.  */
146   struct bb_info *bbs;          /* Basic block table.  */
147   struct ref **defs;            /* Def table, indexed by def_id.  */
148   struct ref **uses;            /* Use table, indexed by use_id.  */
149   struct ref **reg_def_last;    /* Indexed by regno.  */
150   struct reg_info *regs;        /* Regs table, index by regno.  */
151   unsigned int reg_size;        /* Size of regs table.  */
152   struct insn_info *insns;      /* Insn table, indexed by insn UID.  */
153   unsigned int insn_size;       /* Size of insn table.  */
154   unsigned int def_id;          /* Next def ID.  */
155   unsigned int def_size;        /* Size of def table.  */
156   unsigned int n_defs;          /* Size of def bitmaps.  */
157   unsigned int use_id;          /* Next use ID.  */
158   unsigned int use_size;        /* Size of use table.  */
159   unsigned int n_uses;          /* Size of use bitmaps.  */
160   unsigned int n_bbs;           /* Number of basic blocks.  */
161   unsigned int n_regs;          /* Number of regs.  */
162   unsigned int def_id_save;     /* Saved next def ID.  */
163   unsigned int use_id_save;     /* Saved next use ID.  */
164   bitmap insns_modified;        /* Insns that (may) have changed.  */
165   bitmap bbs_modified;          /* Blocks that (may) have changed.  */
166   bitmap all_blocks;            /* All blocks in CFG.  */
167   /* The sbitmap vector of dominators or NULL if not computed.
168      Ideally, this should be a pointer to a CFG object.  */
169   sbitmap *dom;
170   int *dfs_order;               /* DFS order -> block number.  */
171   int *rc_order;                /* Reverse completion order -> block number.  */
172   int *rts_order;               /* Reverse top sort order -> block number.  */
173   int *inverse_rc_map;          /* Block number -> reverse completion order.  */
174   int *inverse_dfs_map;         /* Block number -> DFS order.  */
175   int *inverse_rts_map;         /* Block number -> reverse top-sort order.  */
176 };
177
178
179 struct df_map
180 {
181   rtx old;
182   rtx new;
183 };
184
185
186 #define DF_BB_INFO(REFS, BB) (&REFS->bbs[(BB)->index])
187
188
189 /* Macros to access the elements within the ref structure.  */
190
191 #define DF_REF_REAL_REG(REF) (GET_CODE ((REF)->reg) == SUBREG \
192                                 ? SUBREG_REG ((REF)->reg) : ((REF)->reg))
193 #define DF_REF_REGNO(REF) REGNO (DF_REF_REAL_REG (REF))
194 #define DF_REF_REAL_LOC(REF) (GET_CODE ((REF)->reg) == SUBREG \
195                                 ? &SUBREG_REG ((REF)->reg) : ((REF)->loc))
196 #define DF_REF_REG(REF) ((REF)->reg)
197 #define DF_REF_LOC(REF) ((REF)->loc)
198 #define DF_REF_BB(REF) (BLOCK_FOR_INSN ((REF)->insn))
199 #define DF_REF_BBNO(REF) (BLOCK_FOR_INSN ((REF)->insn)->index)
200 #define DF_REF_INSN(REF) ((REF)->insn)
201 #define DF_REF_INSN_UID(REF) (INSN_UID ((REF)->insn))
202 #define DF_REF_TYPE(REF) ((REF)->type)
203 #define DF_REF_CHAIN(REF) ((REF)->chain)
204 #define DF_REF_ID(REF) ((REF)->id)
205 #define DF_REF_FLAGS(REF) ((REF)->flags)
206
207 /* Macros to determine the reference type.  */
208
209 #define DF_REF_REG_DEF_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_DEF)
210 #define DF_REF_REG_USE_P(REF) ((REF) && ! DF_REF_REG_DEF_P (REF))
211 #define DF_REF_REG_MEM_STORE_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_STORE)
212 #define DF_REF_REG_MEM_LOAD_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_LOAD)
213 #define DF_REF_REG_MEM_P(REF) (DF_REF_REG_MEM_STORE_P (REF) \
214                                || DF_REF_REG_MEM_LOAD_P (REF))
215
216
217 /* Macros to access the elements within the reg_info structure table.  */
218
219 #define DF_REGNO_FIRST_DEF(DF, REGNUM) \
220 ((DF)->regs[REGNUM].defs ? (DF)->regs[REGNUM].defs->ref : 0)
221 #define DF_REGNO_LAST_USE(DF, REGNUM) \
222 ((DF)->regs[REGNUM].uses ? (DF)->regs[REGNUM].uses->ref : 0)
223
224 #define DF_REGNO_FIRST_BB(DF, REGNUM) \
225 (DF_REGNO_FIRST_DEF (DF, REGNUM) \
226 ? DF_REF_BB (DF_REGNO_FIRST_DEF (DF, REGNUM)) : 0)
227 #define DF_REGNO_LAST_BB(DF, REGNUM) \
228 (DF_REGNO_LAST_USE (DF, REGNUM) \
229 ? DF_REF_BB (DF_REGNO_LAST_USE (DF, REGNUM)) : 0)
230
231
232 /* Macros to access the elements within the insn_info structure table.  */
233
234 #define DF_INSN_LUID(DF, INSN) ((DF)->insns[INSN_UID (INSN)].luid)
235 #define DF_INSN_DEFS(DF, INSN) ((DF)->insns[INSN_UID (INSN)].defs)
236 #define DF_INSN_USES(DF, INSN) ((DF)->insns[INSN_UID (INSN)].uses)
237
238
239 /* Functions to build and analyze dataflow information.  */
240
241 extern struct df *df_init (void);
242
243 extern int df_analyze (struct df *, bitmap, int);
244
245 extern void df_finish (struct df *);
246
247 extern void df_dump (struct df *, int, FILE *);
248
249
250 /* Functions to modify insns.  */
251
252 extern void df_insn_modify (struct df *, basic_block, rtx);
253
254 extern rtx df_insn_delete (struct df *, basic_block, rtx);
255
256 extern rtx df_pattern_emit_before (struct df *, rtx, basic_block, rtx);
257
258 extern rtx df_jump_pattern_emit_after (struct df *, rtx, basic_block, rtx);
259
260 extern rtx df_pattern_emit_after (struct df *, rtx, basic_block, rtx);
261
262 extern rtx df_insn_move_before (struct df *, basic_block, rtx, basic_block,
263                                 rtx);
264
265 extern int df_reg_replace (struct df *, bitmap, rtx, rtx);
266
267 extern int df_ref_reg_replace (struct df *, struct ref *, rtx, rtx);
268
269 extern int df_ref_remove (struct df *, struct ref *);
270
271 extern int df_insn_reg_replace (struct df *, basic_block, rtx, rtx, rtx);
272
273 extern int df_insn_mem_replace (struct df *, basic_block, rtx, rtx, rtx);
274
275 extern struct ref *df_bb_def_use_swap (struct df *, basic_block, rtx, rtx,
276                                        unsigned int);
277
278
279 /* Functions to query dataflow information.  */
280
281 extern basic_block df_regno_bb (struct df *, unsigned int);
282
283 extern int df_reg_lifetime (struct df *, rtx);
284
285 extern int df_reg_global_p (struct df *, rtx);
286
287 extern int df_insn_regno_def_p (struct df *, basic_block, rtx, unsigned int);
288
289 extern int df_insn_dominates_all_uses_p (struct df *, basic_block, rtx);
290
291 extern int df_insn_dominates_uses_p (struct df *, basic_block, rtx, bitmap);
292
293 extern int df_bb_reg_live_start_p (struct df *, basic_block, rtx);
294
295 extern int df_bb_reg_live_end_p (struct df *, basic_block, rtx);
296
297 extern int df_bb_regs_lives_compare (struct df *, basic_block, rtx, rtx);
298
299 extern rtx df_bb_single_def_use_insn_find (struct df *, basic_block, rtx,
300                                            rtx);
301 extern struct ref *df_bb_regno_last_use_find (struct df *, basic_block, unsigned int);
302
303 extern struct ref *df_bb_regno_first_def_find (struct df *, basic_block, unsigned int);
304
305 extern struct ref *df_bb_regno_last_def_find (struct df *, basic_block, unsigned int);
306
307 extern struct ref *df_find_def (struct df *, rtx, rtx);
308
309 extern int df_reg_used (struct df *, rtx, rtx);
310
311
312 /* Functions for debugging from GDB.  */
313
314 extern void debug_df_insn (rtx);
315
316 extern void debug_df_regno (unsigned int);
317
318 extern void debug_df_reg (rtx);
319
320 extern void debug_df_defno (unsigned int);
321
322 extern void debug_df_useno (unsigned int);
323
324 extern void debug_df_ref (struct ref *);
325
326 extern void debug_df_chain (struct df_link *);
327
328 extern void df_insn_debug (struct df *, rtx, FILE *);
329
330 extern void df_insn_debug_regno (struct df *, rtx, FILE *);
331
332
333 /* Meet over any path (UNION) or meet over all paths (INTERSECTION).  */
334 enum df_confluence_op
335   {
336     DF_UNION,
337     DF_INTERSECTION
338   };
339
340
341 /* Dataflow direction.  */
342 enum df_flow_dir
343   {
344     DF_FORWARD,
345     DF_BACKWARD
346   };
347
348
349 typedef void (*transfer_function_sbitmap) (int, int *, sbitmap, sbitmap,
350                                            sbitmap, sbitmap, void *);
351
352 typedef void (*transfer_function_bitmap) (int, int *, bitmap, bitmap,
353                                           bitmap, bitmap, void *);
354
355 extern void iterative_dataflow_sbitmap (sbitmap *, sbitmap *, sbitmap *,
356                                         sbitmap *, bitmap, enum df_flow_dir,
357                                         enum df_confluence_op,
358                                         transfer_function_sbitmap,
359                                         int *, void *);
360
361 extern void iterative_dataflow_bitmap (bitmap *, bitmap *, bitmap *,
362                                        bitmap *, bitmap,
363                                        enum df_flow_dir,
364                                        enum df_confluence_op,
365                                        transfer_function_bitmap,
366                                        int *, void *);
367 extern bool read_modify_subreg_p (rtx);
368
369 #endif /* GCC_DF_H */