00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GCC_TREE_SSA_OPERANDS_H
00022 #define GCC_TREE_SSA_OPERANDS_H
00023
00024
00025
00026
00027
00028 typedef tree *def_operand_p;
00029
00030
00031 typedef ssa_use_operand_t *use_operand_p;
00032
00033
00034 #define NULL_USE_OPERAND_P NULL
00035 #define NULL_DEF_OPERAND_P NULL
00036
00037
00038 struct def_optype_d
00039 {
00040 struct def_optype_d *next;
00041 tree *def_ptr;
00042 };
00043 typedef struct def_optype_d *def_optype_p;
00044
00045
00046 struct use_optype_d
00047 {
00048 struct use_optype_d *next;
00049 struct ssa_use_operand_d use_ptr;
00050 };
00051 typedef struct use_optype_d *use_optype_p;
00052
00053
00054 struct maydef_optype_d
00055 {
00056 struct maydef_optype_d *next;
00057 tree def_var;
00058 tree use_var;
00059 struct ssa_use_operand_d use_ptr;
00060 };
00061 typedef struct maydef_optype_d *maydef_optype_p;
00062
00063
00064 struct vuse_optype_d
00065 {
00066 struct vuse_optype_d *next;
00067 tree use_var;
00068 struct ssa_use_operand_d use_ptr;
00069 };
00070 typedef struct vuse_optype_d *vuse_optype_p;
00071
00072
00073 struct mustdef_optype_d
00074 {
00075 struct mustdef_optype_d *next;
00076 tree def_var;
00077 tree kill_var;
00078 struct ssa_use_operand_d use_ptr;
00079 };
00080 typedef struct mustdef_optype_d *mustdef_optype_p;
00081
00082
00083 #define SSA_OPERAND_MEMORY_SIZE (2048 - sizeof (void *))
00084
00085 struct ssa_operand_memory_d GTY((chain_next("%h.next")))
00086 {
00087 struct ssa_operand_memory_d *next;
00088 char mem[SSA_OPERAND_MEMORY_SIZE];
00089 };
00090
00091
00092 /* This represents the operand cache for a stmt. */
00093 struct stmt_operands_d
00094 {
00095 /* Statement operands. */
00096 struct def_optype_d * def_ops;
00097 struct use_optype_d * use_ops;
00098
00099 /* Virtual operands (V_MAY_DEF, VUSE, and V_MUST_DEF). */
00100 struct maydef_optype_d * maydef_ops;
00101 struct vuse_optype_d * vuse_ops;
00102 struct mustdef_optype_d * mustdef_ops;
00103 };
00104
00105 typedef struct stmt_operands_d *stmt_operands_p;
00106
00107 #define USE_FROM_PTR(PTR) get_use_from_ptr (PTR)
00108 #define DEF_FROM_PTR(PTR) get_def_from_ptr (PTR)
00109 #define SET_USE(USE, V) set_ssa_use_from_ptr (USE, V)
00110 #define SET_DEF(DEF, V) ((*(DEF)) = (V))
00111
00112 #define USE_STMT(USE) (USE)->stmt
00113
00114 #define DEF_OPS(STMT) (stmt_ann (STMT)->operands.def_ops)
00115 #define USE_OPS(STMT) (stmt_ann (STMT)->operands.use_ops)
00116 #define VUSE_OPS(STMT) (stmt_ann (STMT)->operands.vuse_ops)
00117 #define MAYDEF_OPS(STMT) (stmt_ann (STMT)->operands.maydef_ops)
00118 #define MUSTDEF_OPS(STMT) (stmt_ann (STMT)->operands.mustdef_ops)
00119
00120 #define USE_OP_PTR(OP) (&((OP)->use_ptr))
00121 #define USE_OP(OP) (USE_FROM_PTR (USE_OP_PTR (OP)))
00122
00123 #define DEF_OP_PTR(OP) ((OP)->def_ptr)
00124 #define DEF_OP(OP) (DEF_FROM_PTR (DEF_OP_PTR (OP)))
00125
00126 #define VUSE_OP_PTR(OP) USE_OP_PTR(OP)
00127 #define VUSE_OP(OP) ((OP)->use_var)
00128
00129 #define MAYDEF_RESULT_PTR(OP) (&((OP)->def_var))
00130 #define MAYDEF_RESULT(OP) ((OP)->def_var)
00131 #define MAYDEF_OP_PTR(OP) USE_OP_PTR (OP)
00132 #define MAYDEF_OP(OP) ((OP)->use_var)
00133
00134 #define MUSTDEF_RESULT_PTR(OP) (&((OP)->def_var))
00135 #define MUSTDEF_RESULT(OP) ((OP)->def_var)
00136 #define MUSTDEF_KILL_PTR(OP) USE_OP_PTR (OP)
00137 #define MUSTDEF_KILL(OP) ((OP)->kill_var)
00138
00139 #define PHI_RESULT_PTR(PHI) get_phi_result_ptr (PHI)
00140 #define PHI_RESULT(PHI) DEF_FROM_PTR (PHI_RESULT_PTR (PHI))
00141 #define SET_PHI_RESULT(PHI, V) SET_DEF (PHI_RESULT_PTR (PHI), (V))
00142
00143 #define PHI_ARG_DEF_PTR(PHI, I) get_phi_arg_def_ptr ((PHI), (I))
00144 #define PHI_ARG_DEF(PHI, I) USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I)))
00145 #define SET_PHI_ARG_DEF(PHI, I, V) \
00146 SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V))
00147 #define PHI_ARG_DEF_FROM_EDGE(PHI, E) \
00148 PHI_ARG_DEF ((PHI), (E)->dest_idx)
00149 #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E) \
00150 PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx)
00151 #define PHI_ARG_INDEX_FROM_USE(USE) phi_arg_index_from_use (USE)
00152
00153
00154 extern void init_ssa_operands (void);
00155 extern void fini_ssa_operands (void);
00156 extern void free_ssa_operands (stmt_operands_p);
00157 extern void update_stmt_operands (tree);
00158 extern bool verify_imm_links (FILE *f, tree var);
00159
00160 extern void copy_virtual_operands (tree, tree);
00161 extern void create_ssa_artficial_load_stmt (tree, tree);
00162
00163 extern void dump_immediate_uses (FILE *file);
00164 extern void dump_immediate_uses_for (FILE *file, tree var);
00165 extern void debug_immediate_uses (void);
00166 extern void debug_immediate_uses_for (tree var);
00167
00168 extern bool ssa_operands_active (void);
00169
00170 extern void add_to_addressable_set (tree, bitmap *);
00171
00172 enum ssa_op_iter_type {
00173 ssa_op_iter_none = 0,
00174 ssa_op_iter_tree,
00175 ssa_op_iter_use,
00176 ssa_op_iter_def,
00177 ssa_op_iter_maymustdef
00178 };
00179 /* This structure is used in the operand iterator loops. It contains the
00180 items required to determine which operand is retrieved next. During
00181 optimization, this structure is scalarized, and any unused fields are
00182 optimized away, resulting in little overhead. */
00183
00184 typedef struct ssa_operand_iterator_d
00185 {
00186 def_optype_p defs;
00187 use_optype_p uses;
00188 vuse_optype_p vuses;
00189 maydef_optype_p maydefs;
00190 maydef_optype_p mayuses;
00191 mustdef_optype_p mustdefs;
00192 mustdef_optype_p mustkills;
00193 enum ssa_op_iter_type iter_type;
00194 int phi_i;
00195 int num_phi;
00196 tree phi_stmt;
00197 bool done;
00198 } ssa_op_iter;
00199
00200 /* These flags are used to determine which operands are returned during
00201 execution of the loop. */
00202 #define SSA_OP_USE 0x01 /* Real USE operands. */
00203 #define SSA_OP_DEF 0x02 /* Real DEF operands. */
00204 #define SSA_OP_VUSE 0x04 /* VUSE operands. */
00205 #define SSA_OP_VMAYUSE 0x08 /* USE portion of V_MAY_DEFS. */
00206 #define SSA_OP_VMAYDEF 0x10 /* DEF portion of V_MAY_DEFS. */
00207 #define SSA_OP_VMUSTDEF 0x20 /* V_MUST_DEF definitions. */
00208 #define SSA_OP_VMUSTKILL 0x40 /* V_MUST_DEF kills. */
00209
00210 /* These are commonly grouped operand flags. */
00211 #define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE | SSA_OP_VMAYUSE)
00212 #define SSA_OP_VIRTUAL_DEFS (SSA_OP_VMAYDEF | SSA_OP_VMUSTDEF)
00213 #define SSA_OP_VIRTUAL_KILLS (SSA_OP_VMUSTKILL)
00214 #define SSA_OP_ALL_VIRTUALS (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_KILLS \
00215 | SSA_OP_VIRTUAL_DEFS)
00216 #define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE)
00217 #define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF)
00218 #define SSA_OP_ALL_KILLS (SSA_OP_VIRTUAL_KILLS)
00219 #define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS \
00220 | SSA_OP_ALL_KILLS)
00221
00222 /* This macro executes a loop over the operands of STMT specified in FLAG,
00223 returning each operand as a 'tree' in the variable TREEVAR. ITER is an
00224 ssa_op_iter structure used to control the loop. */
00225 #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS) \
00226 for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS); \
00227 !op_iter_done (&(ITER)); \
00228 TREEVAR = op_iter_next_tree (&(ITER)))
00229
00230 /* This macro executes a loop over the operands of STMT specified in FLAG,
00231 returning each operand as a 'use_operand_p' in the variable USEVAR.
00232 ITER is an ssa_op_iter structure used to control the loop. */
00233 #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS) \
00234 for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS); \
00235 !op_iter_done (&(ITER)); \
00236 USEVAR = op_iter_next_use (&(ITER)))
00237
00238 /* This macro executes a loop over the operands of STMT specified in FLAG,
00239 returning each operand as a 'def_operand_p' in the variable DEFVAR.
00240 ITER is an ssa_op_iter structure used to control the loop. */
00241 #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS) \
00242 for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS); \
00243 !op_iter_done (&(ITER)); \
00244 DEFVAR = op_iter_next_def (&(ITER)))
00245
00246 /* This macro executes a loop over the V_MAY_DEF operands of STMT. The def
00247 and use for each V_MAY_DEF is returned in DEFVAR and USEVAR.
00248 ITER is an ssa_op_iter structure used to control the loop. */
00249 #define FOR_EACH_SSA_MAYDEF_OPERAND(DEFVAR, USEVAR, STMT, ITER) \
00250 for (op_iter_init_maydef (&(ITER), STMT, &(USEVAR), &(DEFVAR)); \
00251 !op_iter_done (&(ITER)); \
00252 op_iter_next_maymustdef (&(USEVAR), &(DEFVAR), &(ITER)))
00253
00254 /* This macro executes a loop over the V_MUST_DEF operands of STMT. The def
00255 and kill for each V_MUST_DEF is returned in DEFVAR and KILLVAR.
00256 ITER is an ssa_op_iter structure used to control the loop. */
00257 #define FOR_EACH_SSA_MUSTDEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER) \
00258 for (op_iter_init_mustdef (&(ITER), STMT, &(KILLVAR), &(DEFVAR)); \
00259 !op_iter_done (&(ITER)); \
00260 op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
00261
00262 /* This macro executes a loop over the V_{MUST,MAY}_DEF of STMT. The def
00263 and kill for each V_{MUST,MAY}_DEF is returned in DEFVAR and KILLVAR.
00264 ITER is an ssa_op_iter structure used to control the loop. */
00265 #define FOR_EACH_SSA_MUST_AND_MAY_DEF_OPERAND(DEFVAR, KILLVAR, STMT, ITER)\
00266 for (op_iter_init_must_and_may_def (&(ITER), STMT, &(KILLVAR), &(DEFVAR));\
00267 !op_iter_done (&(ITER)); \
00268 op_iter_next_maymustdef (&(KILLVAR), &(DEFVAR), &(ITER)))
00269
00270 /* This macro will execute a loop over all the arguments of a PHI which
00271 match FLAGS. A use_operand_p is always returned via USEVAR. FLAGS
00272 can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES. */
00273 #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS) \
00274 for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS); \
00275 !op_iter_done (&(ITER)); \
00276 (USEVAR) = op_iter_next_use (&(ITER)))
00277
00278
00279 /* This macro will execute a loop over a stmt, regardless of whether it is
00280 a real stmt or a PHI node, looking at the USE nodes matching FLAGS. */
00281 #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS) \
00282 for ((USEVAR) = (TREE_CODE (STMT) == PHI_NODE \
00283 ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \
00284 : op_iter_init_use (&(ITER), STMT, FLAGS)); \
00285 !op_iter_done (&(ITER)); \
00286 (USEVAR) = op_iter_next_use (&(ITER)))
00287
00288 /* This macro will execute a loop over a stmt, regardless of whether it is
00289 a real stmt or a PHI node, looking at the DEF nodes matching FLAGS. */
00290 #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS) \
00291 for ((DEFVAR) = (TREE_CODE (STMT) == PHI_NODE \
00292 ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \
00293 : op_iter_init_def (&(ITER), STMT, FLAGS)); \
00294 !op_iter_done (&(ITER)); \
00295 (DEFVAR) = op_iter_next_def (&(ITER)))
00296
00297 /* This macro returns an operand in STMT as a tree if it is the ONLY
00298 operand matching FLAGS. If there are 0 or more than 1 operand matching
00299 FLAGS, then NULL_TREE is returned. */
00300 #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS) \
00301 single_ssa_tree_operand (STMT, FLAGS)
00302
00303 /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY
00304 operand matching FLAGS. If there are 0 or more than 1 operand matching
00305 FLAGS, then NULL_USE_OPERAND_P is returned. */
00306 #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS) \
00307 single_ssa_use_operand (STMT, FLAGS)
00308
00309 /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY
00310 operand matching FLAGS. If there are 0 or more than 1 operand matching
00311 FLAGS, then NULL_DEF_OPERAND_P is returned. */
00312 #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS) \
00313 single_ssa_def_operand (STMT, FLAGS)
00314
00315 /* This macro returns TRUE if there are no operands matching FLAGS in STMT. */
00316 #define ZERO_SSA_OPERANDS(STMT, FLAGS) zero_ssa_operands (STMT, FLAGS)
00317
00318 /* This macro counts the number of operands in STMT matching FLAGS. */
00319 #define NUM_SSA_OPERANDS(STMT, FLAGS) num_ssa_operands (STMT, FLAGS)
00320
00321 #endif /* GCC_TREE_SSA_OPERANDS_H */