df.h 12.2 KB
Newer Older
Jeff Law committed
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.
Jeff Law committed
4 5
   Contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)

6
This file is part of GCC.
Jeff Law committed
7

8 9 10 11
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.
Jeff Law committed
12

13 14 15 16
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.
Jeff Law committed
17 18

You should have received a copy of the GNU General Public License
19 20 21
along with GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  */
Jeff Law committed
22

23 24 25 26 27 28
#ifndef GCC_DF_H
#define GCC_DF_H

#include "bitmap.h"
#include "basic-block.h"

29 30 31 32 33
#define DF_RD		1	/* Reaching definitions.  */
#define DF_RU		2	/* Reaching uses.  */
#define DF_LR		4	/* Live registers.  */
#define DF_DU_CHAIN	8	/* Def-use chain.  */
#define DF_UD_CHAIN	16	/* Use-def chain.  */
Jeff Law committed
34 35
#define DF_REG_INFO	32	/* Register info.  */
#define DF_RD_CHAIN	64	/* Reg-def chain.  */
36 37 38 39 40
#define DF_RU_CHAIN	128	/* Reg-use chain.  */
#define DF_ALL		255
#define DF_HARD_REGS	1024	/* Mark hard registers.  */
#define DF_EQUIV_NOTES	2048	/* Mark uses present in EQUIV/EQUAL notes.  */
#define DF_FOR_REGALLOC	4096    /* If called for the register allocator.  */
Jeff Law committed
41 42 43 44 45 46 47 48 49 50 51 52 53

enum df_ref_type {DF_REF_REG_DEF, DF_REF_REG_USE, DF_REF_REG_MEM_LOAD,
		  DF_REF_REG_MEM_STORE};

#define DF_REF_TYPE_NAMES {"def", "use", "mem load", "mem store"}

/* Link on a def-use or use-def chain.  */
struct df_link
{
  struct df_link *next;
  struct ref *ref;
};

54 55
enum df_ref_flags
  {
56 57 58
    /* Read-modify-write refs generate both a use and a def and
       these are marked with this flag to show that they are not
       independent.  */
Michael Matz committed
59
    DF_REF_READ_WRITE = 1,
60

61
    /* This flag is set on register references inside a subreg on
62
       machines which have CANNOT_CHANGE_MODE_CLASS.
63
       Note, that this flag can also be set on df_refs representing
64
       the REG itself (i.e., one might not see the subreg anymore).
65 66
       Also note, that this flag is set also for hardreg refs, i.e.,
       you must check yourself if it's a pseudo.  */
67 68 69 70 71
    DF_REF_MODE_CHANGE = 2,

    /* This flag is set, if we stripped the subreg from the reference.
       In this case we must make conservative guesses, at what the
       outer mode was.  */
72 73 74 75 76 77
    DF_REF_STRIPPED = 4,

    /* This flag is set during register allocation if it's okay for
    the reference's INSN to have one of its operands replaced with a
    memory reference.  */
    DF_REF_MEM_OK = 8
78
  };
Jeff Law committed
79

80 81 82 83

/* Define a register reference structure.  One of these is allocated
   for every register reference (use or def).  Note some register
   references (e.g., post_inc, subreg) generate both a def and a use.  */
Jeff Law committed
84 85 86 87
struct ref
{
  rtx reg;			/* The register referenced.  */
  rtx insn;			/* Insn containing ref.  */
88
  rtx *loc;			/* The location of the reg.  */
Jeff Law committed
89
  struct df_link *chain;	/* Head of def-use or use-def chain.  */
Michael Matz committed
90
  unsigned int id;		/* Ref index.  */
91
  enum df_ref_type type;	/* Type of ref.  */
92
  enum df_ref_flags flags;	/* Various flags.  */
93
  void *data;			/* The data assigned to it by user.  */
Jeff Law committed
94 95 96 97 98 99 100 101
};


/* One of these structures is allocated for every insn.  */
struct insn_info
{
  struct df_link *defs;		/* Head of insn-def chain.  */
  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?  */
Jeff Law committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  int luid;			/* Logical UID.  */
};


/* One of these structures is allocated for every reg.  */
struct reg_info
{
  struct df_link *defs;		/* Head of reg-def chain.  */
  struct df_link *uses;		/* Head of reg-use chain.  */
  int lifetime;
  int n_defs;
  int n_uses;
};


/* One of these structures is allocated for every basic block.  */
struct bb_info
{
  /* Reaching def bitmaps have def_id elements.  */
  bitmap rd_kill;
  bitmap rd_gen;
  bitmap rd_in;
  bitmap rd_out;
  /* Reaching use bitmaps have use_id elements.  */
  bitmap ru_kill;
  bitmap ru_gen;
  bitmap ru_in;
  bitmap ru_out;
  /* Live variable bitmaps have n_regs elements.  */
  bitmap lr_def;
  bitmap lr_use;
  bitmap lr_in;
  bitmap lr_out;
  int rd_valid;
  int ru_valid;
  int lr_valid;
};


struct df
{
  int flags;			/* Indicates what's recorded.  */
  struct bb_info *bbs;		/* Basic block table.  */
  struct ref **defs;		/* Def table, indexed by def_id.  */
  struct ref **uses;		/* Use table, indexed by use_id.  */
  struct ref **reg_def_last;	/* Indexed by regno.  */
  struct reg_info *regs;	/* Regs table, index by regno.  */
  unsigned int reg_size;	/* Size of regs table.  */
  struct insn_info *insns;	/* Insn table, indexed by insn UID.  */
  unsigned int insn_size;	/* Size of insn table.  */
  unsigned int def_id;		/* Next def ID.  */
  unsigned int def_size;	/* Size of def table.  */
  unsigned int n_defs;		/* Size of def bitmaps.  */
  unsigned int use_id;		/* Next use ID.  */
  unsigned int use_size;	/* Size of use table.  */
  unsigned int n_uses;		/* Size of use bitmaps.  */
  unsigned int n_bbs;		/* Number of basic blocks.  */
  unsigned int n_regs;		/* Number of regs.  */
  unsigned int def_id_save;	/* Saved next def ID.  */
  unsigned int use_id_save;	/* Saved next use ID.  */
  bitmap insns_modified;	/* Insns that (may) have changed.  */
  bitmap bbs_modified;		/* Blocks that (may) have changed.  */
  bitmap all_blocks;		/* All blocks in CFG.  */
167 168 169 170 171 172
  int *dfs_order;		/* DFS order -> block number.  */
  int *rc_order;		/* Reverse completion order -> block number.  */
  int *rts_order;		/* Reverse top sort order -> block number.  */
  int *inverse_rc_map;		/* Block number -> reverse completion order.  */
  int *inverse_dfs_map;		/* Block number -> DFS order.  */
  int *inverse_rts_map;		/* Block number -> reverse top-sort order.  */
Jeff Law committed
173 174 175 176 177 178 179 180 181 182
};


struct df_map
{
  rtx old;
  rtx new;
};


183
#define DF_BB_INFO(REFS, BB) (&REFS->bbs[(BB)->index])
Jeff Law committed
184 185 186


/* Macros to access the elements within the ref structure.  */
187

Jeff Law committed
188 189 190 191 192 193 194
#define DF_REF_REAL_REG(REF) (GET_CODE ((REF)->reg) == SUBREG \
				? SUBREG_REG ((REF)->reg) : ((REF)->reg))
#define DF_REF_REGNO(REF) REGNO (DF_REF_REAL_REG (REF))
#define DF_REF_REAL_LOC(REF) (GET_CODE ((REF)->reg) == SUBREG \
			        ? &SUBREG_REG ((REF)->reg) : ((REF)->loc))
#define DF_REF_REG(REF) ((REF)->reg)
#define DF_REF_LOC(REF) ((REF)->loc)
195
#define DF_REF_BB(REF) (BLOCK_FOR_INSN ((REF)->insn))
196
#define DF_REF_BBNO(REF) (BLOCK_FOR_INSN ((REF)->insn)->index)
Jeff Law committed
197 198 199 200 201
#define DF_REF_INSN(REF) ((REF)->insn)
#define DF_REF_INSN_UID(REF) (INSN_UID ((REF)->insn))
#define DF_REF_TYPE(REF) ((REF)->type)
#define DF_REF_CHAIN(REF) ((REF)->chain)
#define DF_REF_ID(REF) ((REF)->id)
202
#define DF_REF_FLAGS(REF) ((REF)->flags)
203
#define DF_REF_DATA(REF) ((REF)->data)
Jeff Law committed
204 205 206 207 208 209 210 211

/* Macros to determine the reference type.  */

#define DF_REF_REG_DEF_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_DEF)
#define DF_REF_REG_USE_P(REF) ((REF) && ! DF_REF_REG_DEF_P (REF))
#define DF_REF_REG_MEM_STORE_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_STORE)
#define DF_REF_REG_MEM_LOAD_P(REF) (DF_REF_TYPE (REF) == DF_REF_REG_MEM_LOAD)
#define DF_REF_REG_MEM_P(REF) (DF_REF_REG_MEM_STORE_P (REF) \
212
                               || DF_REF_REG_MEM_LOAD_P (REF))
Jeff Law committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236


/* Macros to access the elements within the reg_info structure table.  */

#define DF_REGNO_FIRST_DEF(DF, REGNUM) \
((DF)->regs[REGNUM].defs ? (DF)->regs[REGNUM].defs->ref : 0)
#define DF_REGNO_LAST_USE(DF, REGNUM) \
((DF)->regs[REGNUM].uses ? (DF)->regs[REGNUM].uses->ref : 0)

#define DF_REGNO_FIRST_BB(DF, REGNUM) \
(DF_REGNO_FIRST_DEF (DF, REGNUM) \
? DF_REF_BB (DF_REGNO_FIRST_DEF (DF, REGNUM)) : 0)
#define DF_REGNO_LAST_BB(DF, REGNUM) \
(DF_REGNO_LAST_USE (DF, REGNUM) \
? DF_REF_BB (DF_REGNO_LAST_USE (DF, REGNUM)) : 0)


/* Macros to access the elements within the insn_info structure table.  */

#define DF_INSN_LUID(DF, INSN) ((DF)->insns[INSN_UID (INSN)].luid)
#define DF_INSN_DEFS(DF, INSN) ((DF)->insns[INSN_UID (INSN)].defs)
#define DF_INSN_USES(DF, INSN) ((DF)->insns[INSN_UID (INSN)].uses)


237
/* Functions to build and analyze dataflow information.  */
Jeff Law committed
238

239
extern struct df *df_init (void);
Jeff Law committed
240

241
extern int df_analyze (struct df *, bitmap, int);
242
extern void df_analyze_subcfg (struct df *, bitmap, int);
Jeff Law committed
243

244
extern void df_finish (struct df *);
Jeff Law committed
245

246
extern void df_dump (struct df *, int, FILE *);
Jeff Law committed
247

248

Jeff Law committed
249 250
/* Functions to modify insns.  */

251
extern void df_insn_modify (struct df *, basic_block, rtx);
Jeff Law committed
252

253
extern rtx df_insn_delete (struct df *, basic_block, rtx);
Jeff Law committed
254

255
extern rtx df_pattern_emit_before (struct df *, rtx, basic_block, rtx);
Jeff Law committed
256

257
extern rtx df_jump_pattern_emit_after (struct df *, rtx, basic_block, rtx);
Jeff Law committed
258

259
extern rtx df_pattern_emit_after (struct df *, rtx, basic_block, rtx);
Jeff Law committed
260

261 262
extern rtx df_insn_move_before (struct df *, basic_block, rtx, basic_block,
				rtx);
Jeff Law committed
263

264
extern int df_reg_replace (struct df *, bitmap, rtx, rtx);
Jeff Law committed
265

266
extern int df_ref_reg_replace (struct df *, struct ref *, rtx, rtx);
Jeff Law committed
267

268
extern int df_ref_remove (struct df *, struct ref *);
Jeff Law committed
269

270
extern int df_insn_mem_replace (struct df *, basic_block, rtx, rtx, rtx);
Jeff Law committed
271

272 273
extern struct ref *df_bb_def_use_swap (struct df *, basic_block, rtx, rtx,
				       unsigned int);
Jeff Law committed
274 275 276 277


/* Functions to query dataflow information.  */

278
extern basic_block df_regno_bb (struct df *, unsigned int);
Jeff Law committed
279

280
extern int df_reg_lifetime (struct df *, rtx);
Jeff Law committed
281

282
extern int df_reg_global_p (struct df *, rtx);
Jeff Law committed
283

284
extern int df_insn_regno_def_p (struct df *, basic_block, rtx, unsigned int);
Jeff Law committed
285

286
extern int df_insn_dominates_all_uses_p (struct df *, basic_block, rtx);
Jeff Law committed
287

288
extern int df_insn_dominates_uses_p (struct df *, basic_block, rtx, bitmap);
Jeff Law committed
289

290
extern int df_bb_reg_live_start_p (struct df *, basic_block, rtx);
Jeff Law committed
291

292
extern int df_bb_reg_live_end_p (struct df *, basic_block, rtx);
Jeff Law committed
293

294
extern int df_bb_regs_lives_compare (struct df *, basic_block, rtx, rtx);
Jeff Law committed
295

296 297
extern rtx df_bb_single_def_use_insn_find (struct df *, basic_block, rtx,
					   rtx);
Ayal Zaks committed
298 299 300 301 302 303 304 305 306
extern struct ref *df_bb_regno_last_use_find (struct df *, basic_block, unsigned int);

extern struct ref *df_bb_regno_first_def_find (struct df *, basic_block, unsigned int);

extern struct ref *df_bb_regno_last_def_find (struct df *, basic_block, unsigned int);

extern struct ref *df_find_def (struct df *, rtx, rtx);

extern int df_reg_used (struct df *, rtx, rtx);
Jeff Law committed
307 308 309

/* Functions for debugging from GDB.  */

310
extern void debug_df_insn (rtx);
Jeff Law committed
311

312
extern void debug_df_regno (unsigned int);
Jeff Law committed
313

314
extern void debug_df_reg (rtx);
Jeff Law committed
315

316
extern void debug_df_defno (unsigned int);
Jeff Law committed
317

318
extern void debug_df_useno (unsigned int);
Jeff Law committed
319

320
extern void debug_df_ref (struct ref *);
Jeff Law committed
321

322
extern void debug_df_chain (struct df_link *);
323

324
extern void df_insn_debug (struct df *, rtx, FILE *);
325

326
extern void df_insn_debug_regno (struct df *, rtx, FILE *);
327 328 329


/* Meet over any path (UNION) or meet over all paths (INTERSECTION).  */
330 331
enum df_confluence_op
  {
332 333
    DF_UNION,
    DF_INTERSECTION
334
  };
335 336 337


/* Dataflow direction.  */
338 339
enum df_flow_dir
  {
340 341
    DF_FORWARD,
    DF_BACKWARD
342 343
  };

344

345 346 347 348
typedef void (*transfer_function) (int, int *, void *, void *,
				   void *, void *, void *);

/* The description of a dataflow problem to solve.  */
349

350 351 352 353 354
enum set_representation
{
  SR_SBITMAP,		/* Represent sets by bitmaps.  */
  SR_BITMAP		/* Represent sets by sbitmaps.  */
};
355

356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
struct dataflow
{
  enum set_representation repr;		/* The way the sets are represented.  */

  /* The following arrays are indexed by block indices, so they must always
     be large enough even if we restrict ourselves just to a subset of cfg.  */
  void **gen, **kill;			/* Gen and kill sets.  */
  void **in, **out;			/* Results.  */

  enum df_flow_dir dir;			/* Dataflow direction.  */
  enum df_confluence_op conf_op;	/* Confluence operator.  */ 
  unsigned n_blocks;			/* Number of basic blocks in the
					   order.  */
  int *order;				/* The list of basic blocks to work
					   with, in the order they should
					   be processed in.  */
  transfer_function transfun;		/* The transfer function.  */
  void *data;				/* Data used by the transfer
					   function.  */
};
376

377
extern void iterative_dataflow (struct dataflow *);
378
extern bool read_modify_subreg_p (rtx);
379 380

#endif /* GCC_DF_H */