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)
6 This file is part of GCC.
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
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
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
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. */
32 #define DF_HARD_REGS 1024
33 #define DF_EQUIV_NOTES 2048 /* Mark uses present in EQUIV/EQUAL notes. */
35 enum df_ref_type
{DF_REF_REG_DEF
, DF_REF_REG_USE
, DF_REF_REG_MEM_LOAD
,
36 DF_REF_REG_MEM_STORE
};
38 #define DF_REF_TYPE_NAMES {"def", "use", "mem load", "mem store"}
40 /* ???> Perhaps all these data structures should be made private
41 to enforce the interface. */
44 /* Link on a def-use or use-def chain. */
53 DF_REF_READ_WRITE
= 1,
55 /* This flag is set on register references itself representing a or
56 being inside a subreg on machines which have CLASS_CANNOT_CHANGE_MODE
57 and where the mode change of that subreg expression is invalid for
58 this class. Note, that this flag can also be set on df_refs
59 representing the REG itself (i.e. one might not see the subreg
60 anyore). Also note, that this flag is set also for hardreg refs.
61 I.e. you must check yourself if it's a pseudo. */
62 DF_REF_MODE_CHANGE
= 2
65 /* Define a register reference structure. */
68 rtx reg
; /* The register referenced. */
69 rtx insn
; /* Insn containing ref. */
70 rtx
*loc
; /* Loc is the location of the reg. */
71 struct df_link
*chain
; /* Head of def-use or use-def chain. */
72 enum df_ref_type type
; /* Type of ref. */
73 unsigned int id
; /* Ref index. */
74 enum df_ref_flags flags
; /* Various flags. */
78 /* One of these structures is allocated for every insn. */
81 struct df_link
*defs
; /* Head of insn-def chain. */
82 struct df_link
*uses
; /* Head of insn-use chain. */
83 /* ???? The following luid field should be considerd private so that
84 we can change it on the fly to accommodate new insns? */
85 int luid
; /* Logical UID. */
87 rtx insn
; /* Backpointer to the insn. */
92 /* One of these structures is allocated for every reg. */
95 struct df_link
*defs
; /* Head of reg-def chain. */
96 struct df_link
*uses
; /* Head of reg-use chain. */
103 /* One of these structures is allocated for every basic block. */
106 /* Reaching def bitmaps have def_id elements. */
111 /* Reaching use bitmaps have use_id elements. */
116 /* Live variable bitmaps have n_regs elements. */
129 int flags
; /* Indicates what's recorded. */
130 struct bb_info
*bbs
; /* Basic block table. */
131 struct ref
**defs
; /* Def table, indexed by def_id. */
132 struct ref
**uses
; /* Use table, indexed by use_id. */
133 struct ref
**reg_def_last
; /* Indexed by regno. */
134 struct reg_info
*regs
; /* Regs table, index by regno. */
135 unsigned int reg_size
; /* Size of regs table. */
136 struct insn_info
*insns
; /* Insn table, indexed by insn UID. */
137 unsigned int insn_size
; /* Size of insn table. */
138 unsigned int def_id
; /* Next def ID. */
139 unsigned int def_size
; /* Size of def table. */
140 unsigned int n_defs
; /* Size of def bitmaps. */
141 unsigned int use_id
; /* Next use ID. */
142 unsigned int use_size
; /* Size of use table. */
143 unsigned int n_uses
; /* Size of use bitmaps. */
144 unsigned int n_bbs
; /* Number of basic blocks. */
145 unsigned int n_regs
; /* Number of regs. */
146 unsigned int def_id_save
; /* Saved next def ID. */
147 unsigned int use_id_save
; /* Saved next use ID. */
148 bitmap insns_modified
; /* Insns that (may) have changed. */
149 bitmap bbs_modified
; /* Blocks that (may) have changed. */
150 bitmap all_blocks
; /* All blocks in CFG. */
151 /* The sbitmap vector of dominators or NULL if not computed.
152 Ideally, this should be a pointer to a CFG object. */
154 int * dfs_order
; /* DFS order -> block number */
155 int * rc_order
; /* reverse completion order -> block number */
156 int * rts_order
; /* reverse top sort order -> block number */
157 int * inverse_rc_map
; /* block number -> reverse completion order */
158 int * inverse_dfs_map
; /* block number -> DFS order */
159 int * inverse_rts_map
; /* block number -> reverse top-sort order */
170 #define DF_BB_INFO(REFS, BB) (&REFS->bbs[(BB)->index])
173 /* Macros to access the elements within the ref structure. */
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 #ifdef OLD_DF_INTERFACE
180 #define DF_REF_REG(REF) DF_REF_REAL_REG(REF)
181 #define DF_REF_LOC(REF) DF_REF_REAL_LOC(REF)
183 #define DF_REF_REG(REF) ((REF)->reg)
184 #define DF_REF_LOC(REF) ((REF)->loc)
186 #define DF_REF_BB(REF) (BLOCK_FOR_INSN ((REF)->insn))
187 #define DF_REF_BBNO(REF) (BLOCK_FOR_INSN ((REF)->insn)->index)
188 #define DF_REF_INSN(REF) ((REF)->insn)
189 #define DF_REF_INSN_UID(REF) (INSN_UID ((REF)->insn))
190 #define DF_REF_TYPE(REF) ((REF)->type)
191 #define DF_REF_CHAIN(REF) ((REF)->chain)
192 #define DF_REF_ID(REF) ((REF)->id)
193 #define DF_REF_FLAGS(REF) ((REF)->flags)
195 /* Macros to determine the reference type. */
197 #define DF_REF_REG_DEF_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_DEF)
198 #define DF_REF_REG_USE_P(REF) ((REF) && ! DF_REF_REG_DEF_P (REF))
199 #define DF_REF_REG_MEM_STORE_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_STORE)
200 #define DF_REF_REG_MEM_LOAD_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_LOAD)
201 #define DF_REF_REG_MEM_P(REF) (DF_REF_REG_MEM_STORE_P (REF) \
202 || DF_REF_REG_MEM_LOAD_P (REF))
205 /* Macros to access the elements within the reg_info structure table. */
207 #define DF_REGNO_FIRST_DEF(DF, REGNUM) \
208 ((DF)->regs[REGNUM].defs ? (DF)->regs[REGNUM].defs->ref : 0)
209 #define DF_REGNO_LAST_USE(DF, REGNUM) \
210 ((DF)->regs[REGNUM].uses ? (DF)->regs[REGNUM].uses->ref : 0)
212 #define DF_REGNO_FIRST_BB(DF, REGNUM) \
213 (DF_REGNO_FIRST_DEF (DF, REGNUM) \
214 ? DF_REF_BB (DF_REGNO_FIRST_DEF (DF, REGNUM)) : 0)
215 #define DF_REGNO_LAST_BB(DF, REGNUM) \
216 (DF_REGNO_LAST_USE (DF, REGNUM) \
217 ? DF_REF_BB (DF_REGNO_LAST_USE (DF, REGNUM)) : 0)
220 /* Macros to access the elements within the insn_info structure table. */
222 #define DF_INSN_LUID(DF, INSN) ((DF)->insns[INSN_UID (INSN)].luid)
223 #define DF_INSN_DEFS(DF, INSN) ((DF)->insns[INSN_UID (INSN)].defs)
224 #define DF_INSN_USES(DF, INSN) ((DF)->insns[INSN_UID (INSN)].uses)
227 /* Functions to build and analyse dataflow information. */
229 extern struct df
*df_init
PARAMS ((void));
231 extern int df_analyse
PARAMS ((struct df
*, bitmap
, int));
233 extern void df_finish
PARAMS ((struct df
*));
235 extern void df_dump
PARAMS ((struct df
*, int, FILE *));
237 /* Functions to modify insns. */
239 extern void df_insn_modify
PARAMS ((struct df
*, basic_block
, rtx
));
241 extern rtx df_insn_delete
PARAMS ((struct df
*, basic_block
, rtx
));
243 extern rtx df_pattern_emit_before
PARAMS ((struct df
*, rtx
,
246 extern rtx df_jump_pattern_emit_after
PARAMS ((struct df
*, rtx
,
249 extern rtx df_pattern_emit_after
PARAMS ((struct df
*, rtx
,
252 extern rtx df_insn_move_before
PARAMS ((struct df
*, basic_block
, rtx
,
255 extern int df_reg_replace
PARAMS ((struct df
*, bitmap
, rtx
, rtx
));
257 extern int df_ref_reg_replace
PARAMS ((struct df
*, struct ref
*, rtx
, rtx
));
259 extern int df_ref_remove
PARAMS ((struct df
*, struct ref
*));
261 extern int df_insn_reg_replace
PARAMS ((struct df
*, basic_block
,
264 extern int df_insn_mem_replace
PARAMS ((struct df
*, basic_block
,
267 extern struct ref
*df_bb_def_use_swap
PARAMS ((struct df
*, basic_block
,
268 rtx
, rtx
, unsigned int));
271 /* Functions to query dataflow information. */
273 extern basic_block df_regno_bb
PARAMS((struct df
*, unsigned int));
275 extern int df_reg_lifetime
PARAMS ((struct df
*, rtx
));
277 extern int df_reg_global_p
PARAMS ((struct df
*, rtx
));
279 extern int df_insn_regno_def_p
PARAMS ((struct df
*,
280 basic_block
, rtx
, unsigned int));
282 extern int df_insn_dominates_all_uses_p
PARAMS ((struct df
*,
285 extern int df_insn_dominates_uses_p
PARAMS ((struct df
*, basic_block
,
288 extern int df_bb_reg_live_start_p
PARAMS ((struct df
*, basic_block
, rtx
));
290 extern int df_bb_reg_live_end_p
PARAMS ((struct df
*, basic_block
, rtx
));
292 extern int df_bb_regs_lives_compare
PARAMS ((struct df
*, basic_block
,
295 extern rtx df_bb_single_def_use_insn_find
PARAMS((struct df
*, basic_block
,
299 /* Functions for debugging from GDB. */
301 extern void debug_df_insn
PARAMS ((rtx
));
303 extern void debug_df_regno
PARAMS ((unsigned int));
305 extern void debug_df_reg
PARAMS ((rtx
));
307 extern void debug_df_defno
PARAMS ((unsigned int));
309 extern void debug_df_useno
PARAMS ((unsigned int));
311 extern void debug_df_ref
PARAMS ((struct ref
*));
313 extern void debug_df_chain
PARAMS ((struct df_link
*));
314 extern void df_insn_debug
PARAMS ((struct df
*, rtx
, FILE *));
315 extern void df_insn_debug_regno
PARAMS ((struct df
*, rtx
, FILE *));
316 /* Meet over any path (UNION) or meet over all paths (INTERSECTION) */
317 enum df_confluence_op
322 /* Dataflow direction */
329 typedef void (*transfer_function_sbitmap
) PARAMS ((int, int *, sbitmap
, sbitmap
,
330 sbitmap
, sbitmap
, void *));
331 typedef void (*transfer_function_bitmap
) PARAMS ((int, int *, bitmap
, bitmap
,
332 bitmap
, bitmap
, void *));
334 extern void iterative_dataflow_sbitmap
PARAMS ((sbitmap
*, sbitmap
*,
335 sbitmap
*, sbitmap
*,
336 bitmap
, enum df_flow_dir
,
337 enum df_confluence_op
,
338 transfer_function_sbitmap
,
340 extern void iterative_dataflow_bitmap
PARAMS ((bitmap
*, bitmap
*, bitmap
*,
343 enum df_confluence_op
,
344 transfer_function_bitmap
,