OSDN Git Service

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