OSDN Git Service

* lcm.c (optimize_mode_switching): Do not rebuild liveness information
[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 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
24 #define DF_RD            1      /* Reaching definitions.  */
25 #define DF_RU            2      /* Reaching uses.  */
26 #define DF_LR            4      /* Live registers.  */
27 #define DF_DU_CHAIN      8      /* Def-use chain.  */
28 #define DF_UD_CHAIN     16      /* Use-def chain.  */
29 #define DF_REG_INFO     32      /* Register info.  */
30 #define DF_RD_CHAIN     64      /* Reg-def chain.  */
31 #define DF_RU_CHAIN    128      /* Reg-use chain.  */
32 #define DF_ALL         255
33 #define DF_HARD_REGS  1024
34 #define DF_EQUIV_NOTES 2048     /* Mark uses present in EQUIV/EQUAL notes.  */
35
36 enum df_ref_type {DF_REF_REG_DEF, DF_REF_REG_USE, DF_REF_REG_MEM_LOAD,
37                   DF_REF_REG_MEM_STORE};
38
39 #define DF_REF_TYPE_NAMES {"def", "use", "mem load", "mem store"}
40
41 /* ???> Perhaps all these data structures should be made private
42    to enforce the interface.  */
43
44
45 /* Link on a def-use or use-def chain.  */
46 struct df_link
47 {
48   struct df_link *next;
49   struct ref *ref;
50 };
51
52
53 /* Define a register reference structure.  */
54 struct ref
55 {
56   rtx reg;                      /* The register referenced.  */
57   basic_block bb;               /* BB containing ref.  */
58   rtx insn;                     /* Insn containing ref.  */
59   rtx *loc;                     /* Loc is the location of the reg.  */
60   struct df_link *chain;        /* Head of def-use or use-def chain.  */
61   enum df_ref_type type;        /* Type of ref.  */
62   int id;                       /* Ref index.  */
63 };
64
65
66 /* One of these structures is allocated for every insn.  */
67 struct insn_info
68 {
69   struct df_link *defs;         /* Head of insn-def chain.  */
70   struct df_link *uses;         /* Head of insn-use chain.  */
71   /* ???? The following luid field should be considerd private so that
72      we can change it on the fly to accommodate new insns?  */
73   int luid;                     /* Logical UID.  */
74 #if 0
75   rtx insn;                     /* Backpointer to the insn.  */
76 #endif
77 };
78
79
80 /* One of these structures is allocated for every reg.  */
81 struct reg_info
82 {
83   struct df_link *defs;         /* Head of reg-def chain.  */
84   struct df_link *uses;         /* Head of reg-use chain.  */
85   int lifetime;
86   int n_defs;
87   int n_uses;
88 };
89
90
91 /* One of these structures is allocated for every basic block.  */
92 struct bb_info
93 {
94   /* Reaching def bitmaps have def_id elements.  */
95   bitmap rd_kill;
96   bitmap rd_gen;
97   bitmap rd_in;
98   bitmap rd_out;
99   /* Reaching use bitmaps have use_id elements.  */
100   bitmap ru_kill;
101   bitmap ru_gen;
102   bitmap ru_in;
103   bitmap ru_out;
104   /* Live variable bitmaps have n_regs elements.  */
105   bitmap lr_def;
106   bitmap lr_use;
107   bitmap lr_in;
108   bitmap lr_out;
109   int rd_valid;
110   int ru_valid;
111   int lr_valid;
112 };
113
114
115 struct df
116 {
117   int flags;                    /* Indicates what's recorded.  */
118   struct bb_info *bbs;          /* Basic block table.  */
119   struct ref **defs;            /* Def table, indexed by def_id.  */
120   struct ref **uses;            /* Use table, indexed by use_id.  */
121   struct ref **reg_def_last;    /* Indexed by regno.  */
122   struct reg_info *regs;        /* Regs table, index by regno.  */
123   unsigned int reg_size;        /* Size of regs table.  */
124   struct insn_info *insns;      /* Insn table, indexed by insn UID.  */
125   unsigned int insn_size;       /* Size of insn table.  */
126   unsigned int def_id;          /* Next def ID.  */
127   unsigned int def_size;        /* Size of def table.  */
128   unsigned int n_defs;          /* Size of def bitmaps.  */
129   unsigned int use_id;          /* Next use ID.  */
130   unsigned int use_size;        /* Size of use table.  */
131   unsigned int n_uses;          /* Size of use bitmaps.  */
132   unsigned int n_bbs;           /* Number of basic blocks.  */
133   unsigned int n_regs;          /* Number of regs.  */
134   unsigned int def_id_save;     /* Saved next def ID.  */
135   unsigned int use_id_save;     /* Saved next use ID.  */
136   bitmap insns_modified;        /* Insns that (may) have changed.  */
137   bitmap bbs_modified;          /* Blocks that (may) have changed.  */
138   bitmap all_blocks;            /* All blocks in CFG.  */
139   /* The bitmap vector of dominators or NULL if not computed. 
140      Ideally, this should be a pointer to a CFG object.  */
141   bitmap *dom;
142   int * dfs_order;
143   int * rc_order;
144   int * rts_order;
145 };
146
147
148 struct df_map
149 {
150   rtx old;
151   rtx new;
152 };
153
154
155 #define DF_BB_INFO(REFS, BB) (&REFS->bbs[(BB)->index])
156
157
158 /* Macros to access the elements within the ref structure.  */
159 #define DF_REF_REAL_REG(REF) (GET_CODE ((REF)->reg) == SUBREG \
160                                 ? SUBREG_REG ((REF)->reg) : ((REF)->reg))
161 #define DF_REF_REGNO(REF) REGNO (DF_REF_REAL_REG (REF))
162 #define DF_REF_REAL_LOC(REF) (GET_CODE ((REF)->reg) == SUBREG \
163                                 ? &SUBREG_REG ((REF)->reg) : ((REF)->loc))
164 #ifdef OLD_DF_INTERFACE
165 #define DF_REF_REG(REF) DF_REF_REAL_REG(REF)
166 #define DF_REF_LOC(REF) DF_REF_REAL_LOC(REF)
167 #else
168 #define DF_REF_REG(REF) ((REF)->reg)
169 #define DF_REF_LOC(REF) ((REF)->loc)
170 #endif
171 #define DF_REF_BB(REF) ((REF)->bb)
172 #define DF_REF_BBNO(REF) ((REF)->bb->index)
173 #define DF_REF_INSN(REF) ((REF)->insn)
174 #define DF_REF_INSN_UID(REF) (INSN_UID ((REF)->insn))
175 #define DF_REF_TYPE(REF) ((REF)->type)
176 #define DF_REF_CHAIN(REF) ((REF)->chain)
177 #define DF_REF_ID(REF) ((REF)->id)
178
179 /* Macros to determine the reference type.  */
180
181 #define DF_REF_REG_DEF_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_DEF)
182 #define DF_REF_REG_USE_P(REF) ((REF) && ! DF_REF_REG_DEF_P (REF))
183 #define DF_REF_REG_MEM_STORE_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_STORE)
184 #define DF_REF_REG_MEM_LOAD_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_LOAD)
185 #define DF_REF_REG_MEM_P(REF) (DF_REF_REG_MEM_STORE_P (REF) \
186                             || DF_REF_REG_MEM_LOAD_P (REF))
187
188
189 /* Macros to access the elements within the reg_info structure table.  */
190
191 #define DF_REGNO_FIRST_DEF(DF, REGNUM) \
192 ((DF)->regs[REGNUM].defs ? (DF)->regs[REGNUM].defs->ref : 0)
193 #define DF_REGNO_LAST_USE(DF, REGNUM) \
194 ((DF)->regs[REGNUM].uses ? (DF)->regs[REGNUM].uses->ref : 0)
195
196 #define DF_REGNO_FIRST_BB(DF, REGNUM) \
197 (DF_REGNO_FIRST_DEF (DF, REGNUM) \
198 ? DF_REF_BB (DF_REGNO_FIRST_DEF (DF, REGNUM)) : 0)
199 #define DF_REGNO_LAST_BB(DF, REGNUM) \
200 (DF_REGNO_LAST_USE (DF, REGNUM) \
201 ? DF_REF_BB (DF_REGNO_LAST_USE (DF, REGNUM)) : 0)
202
203
204 /* Macros to access the elements within the insn_info structure table.  */
205
206 #define DF_INSN_LUID(DF, INSN) ((DF)->insns[INSN_UID (INSN)].luid)
207 #define DF_INSN_DEFS(DF, INSN) ((DF)->insns[INSN_UID (INSN)].defs)
208 #define DF_INSN_USES(DF, INSN) ((DF)->insns[INSN_UID (INSN)].uses)
209
210
211 /* Functions to build and analyse dataflow information.  */
212
213 extern struct df *df_init PARAMS ((void));
214
215 extern int df_analyse PARAMS ((struct df *, bitmap, int));
216
217 extern void df_finish PARAMS ((struct df *));
218
219 extern void df_dump PARAMS ((struct df *, int, FILE *));
220
221 /* Functions to modify insns.  */
222
223 extern void df_insn_modify PARAMS ((struct df *, basic_block, rtx));
224
225 extern rtx df_insn_delete PARAMS ((struct df *, basic_block, rtx));
226
227 extern rtx df_pattern_emit_before PARAMS ((struct df *, rtx, 
228                                            basic_block, rtx));
229
230 extern rtx df_jump_pattern_emit_after PARAMS ((struct df *, rtx, 
231                                                basic_block, rtx));
232
233 extern rtx df_pattern_emit_after PARAMS ((struct df *, rtx, 
234                                            basic_block, rtx));
235
236 extern rtx df_insn_move_before PARAMS ((struct df *, basic_block, rtx,
237                                         basic_block, rtx));
238
239 extern int df_reg_replace PARAMS ((struct df *, bitmap, rtx, rtx));
240
241 extern int df_ref_reg_replace PARAMS ((struct df *, struct ref *, rtx, rtx));
242
243 extern int df_ref_remove PARAMS ((struct df *, struct ref *));
244
245 extern int df_insn_reg_replace PARAMS ((struct df *, basic_block,
246                                         rtx, rtx, rtx));
247
248 extern int df_insn_mem_replace PARAMS ((struct df *, basic_block,
249                                         rtx, rtx, rtx));
250
251 extern struct ref *df_bb_def_use_swap PARAMS ((struct df *, basic_block, 
252                                                rtx, rtx, unsigned int));
253
254
255 /* Functions to query dataflow information.  */
256
257 extern basic_block df_regno_bb PARAMS((struct df *, unsigned int));
258
259 extern int df_reg_lifetime PARAMS ((struct df *, rtx));
260
261 extern int df_reg_global_p PARAMS ((struct df *, rtx));
262
263 extern int df_insn_regno_def_p PARAMS ((struct df *, 
264                                         basic_block, rtx, unsigned int));
265
266 extern int df_insn_dominates_all_uses_p PARAMS ((struct df *, 
267                                                  basic_block, rtx));
268
269 extern int df_insn_dominates_uses_p PARAMS ((struct df *, basic_block,
270                                              rtx, bitmap));
271
272 extern int df_bb_reg_live_start_p PARAMS ((struct df *, basic_block, rtx));
273
274 extern int df_bb_reg_live_end_p PARAMS ((struct df *, basic_block, rtx));
275
276 extern int df_bb_regs_lives_compare PARAMS ((struct df *, basic_block,
277                                              rtx, rtx));
278
279 extern rtx df_bb_single_def_use_insn_find PARAMS((struct df *, basic_block,
280                                                   rtx, rtx));
281
282
283 /* Functions for debugging from GDB.  */
284
285 extern void debug_df_insn PARAMS ((rtx));
286
287 extern void debug_df_regno PARAMS ((unsigned int));
288
289 extern void debug_df_reg PARAMS ((rtx));
290
291 extern void debug_df_defno PARAMS ((unsigned int));
292
293 extern void debug_df_useno PARAMS ((unsigned int));
294
295 extern void debug_df_ref PARAMS ((struct ref *));
296
297 extern void debug_df_chain PARAMS ((struct df_link *));
298 extern void df_insn_debug PARAMS ((struct df *, rtx, FILE *));
299 extern void df_insn_debug_regno PARAMS ((struct df *, rtx, FILE *));