1*e4b17023SJohn Marino /* SSA operand management for trees. 2*e4b17023SJohn Marino Copyright (C) 2003, 2005, 2006, 2007, 2008, 2010 3*e4b17023SJohn Marino Free Software Foundation, Inc. 4*e4b17023SJohn Marino 5*e4b17023SJohn Marino This file is part of GCC. 6*e4b17023SJohn Marino 7*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 8*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 9*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 10*e4b17023SJohn Marino version. 11*e4b17023SJohn Marino 12*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 14*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15*e4b17023SJohn Marino for more details. 16*e4b17023SJohn Marino 17*e4b17023SJohn Marino You should have received a copy of the GNU General Public License 18*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see 19*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 20*e4b17023SJohn Marino 21*e4b17023SJohn Marino #ifndef GCC_TREE_SSA_OPERANDS_H 22*e4b17023SJohn Marino #define GCC_TREE_SSA_OPERANDS_H 23*e4b17023SJohn Marino 24*e4b17023SJohn Marino /* Interface to SSA operands. */ 25*e4b17023SJohn Marino 26*e4b17023SJohn Marino 27*e4b17023SJohn Marino /* This represents a pointer to a DEF operand. */ 28*e4b17023SJohn Marino typedef tree *def_operand_p; 29*e4b17023SJohn Marino 30*e4b17023SJohn Marino /* This represents a pointer to a USE operand. */ 31*e4b17023SJohn Marino typedef ssa_use_operand_t *use_operand_p; 32*e4b17023SJohn Marino 33*e4b17023SJohn Marino /* NULL operand types. */ 34*e4b17023SJohn Marino #define NULL_USE_OPERAND_P ((use_operand_p)NULL) 35*e4b17023SJohn Marino #define NULL_DEF_OPERAND_P ((def_operand_p)NULL) 36*e4b17023SJohn Marino 37*e4b17023SJohn Marino /* This represents the DEF operands of a stmt. */ 38*e4b17023SJohn Marino struct def_optype_d 39*e4b17023SJohn Marino { 40*e4b17023SJohn Marino struct def_optype_d *next; 41*e4b17023SJohn Marino tree *def_ptr; 42*e4b17023SJohn Marino }; 43*e4b17023SJohn Marino typedef struct def_optype_d *def_optype_p; 44*e4b17023SJohn Marino 45*e4b17023SJohn Marino /* This represents the USE operands of a stmt. */ 46*e4b17023SJohn Marino struct use_optype_d 47*e4b17023SJohn Marino { 48*e4b17023SJohn Marino struct use_optype_d *next; 49*e4b17023SJohn Marino struct ssa_use_operand_d use_ptr; 50*e4b17023SJohn Marino }; 51*e4b17023SJohn Marino typedef struct use_optype_d *use_optype_p; 52*e4b17023SJohn Marino 53*e4b17023SJohn Marino /* This structure represents a variable sized buffer which is allocated by the 54*e4b17023SJohn Marino operand memory manager. Operands are suballocated out of this block. The 55*e4b17023SJohn Marino MEM array varies in size. */ 56*e4b17023SJohn Marino 57*e4b17023SJohn Marino struct GTY((chain_next("%h.next"), variable_size)) ssa_operand_memory_d { 58*e4b17023SJohn Marino struct ssa_operand_memory_d *next; 59*e4b17023SJohn Marino char mem[1]; 60*e4b17023SJohn Marino }; 61*e4b17023SJohn Marino 62*e4b17023SJohn Marino /* Per-function operand caches. */ 63*e4b17023SJohn Marino struct GTY(()) ssa_operands { 64*e4b17023SJohn Marino struct ssa_operand_memory_d *operand_memory; 65*e4b17023SJohn Marino unsigned operand_memory_index; 66*e4b17023SJohn Marino /* Current size of the operand memory buffer. */ 67*e4b17023SJohn Marino unsigned int ssa_operand_mem_size; 68*e4b17023SJohn Marino 69*e4b17023SJohn Marino bool ops_active; 70*e4b17023SJohn Marino 71*e4b17023SJohn Marino struct def_optype_d * GTY ((skip (""))) free_defs; 72*e4b17023SJohn Marino struct use_optype_d * GTY ((skip (""))) free_uses; 73*e4b17023SJohn Marino }; 74*e4b17023SJohn Marino 75*e4b17023SJohn Marino #define USE_FROM_PTR(PTR) get_use_from_ptr (PTR) 76*e4b17023SJohn Marino #define DEF_FROM_PTR(PTR) get_def_from_ptr (PTR) 77*e4b17023SJohn Marino #define SET_USE(USE, V) set_ssa_use_from_ptr (USE, V) 78*e4b17023SJohn Marino #define SET_DEF(DEF, V) ((*(DEF)) = (V)) 79*e4b17023SJohn Marino 80*e4b17023SJohn Marino #define USE_STMT(USE) (USE)->loc.stmt 81*e4b17023SJohn Marino 82*e4b17023SJohn Marino #define USE_OP_PTR(OP) (&((OP)->use_ptr)) 83*e4b17023SJohn Marino #define USE_OP(OP) (USE_FROM_PTR (USE_OP_PTR (OP))) 84*e4b17023SJohn Marino 85*e4b17023SJohn Marino #define DEF_OP_PTR(OP) ((OP)->def_ptr) 86*e4b17023SJohn Marino #define DEF_OP(OP) (DEF_FROM_PTR (DEF_OP_PTR (OP))) 87*e4b17023SJohn Marino 88*e4b17023SJohn Marino #define PHI_RESULT_PTR(PHI) gimple_phi_result_ptr (PHI) 89*e4b17023SJohn Marino #define PHI_RESULT(PHI) DEF_FROM_PTR (PHI_RESULT_PTR (PHI)) 90*e4b17023SJohn Marino #define SET_PHI_RESULT(PHI, V) SET_DEF (PHI_RESULT_PTR (PHI), (V)) 91*e4b17023SJohn Marino 92*e4b17023SJohn Marino #define PHI_ARG_DEF_PTR(PHI, I) gimple_phi_arg_imm_use_ptr ((PHI), (I)) 93*e4b17023SJohn Marino #define PHI_ARG_DEF(PHI, I) USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I))) 94*e4b17023SJohn Marino #define SET_PHI_ARG_DEF(PHI, I, V) \ 95*e4b17023SJohn Marino SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V)) 96*e4b17023SJohn Marino #define PHI_ARG_DEF_FROM_EDGE(PHI, E) \ 97*e4b17023SJohn Marino PHI_ARG_DEF ((PHI), (E)->dest_idx) 98*e4b17023SJohn Marino #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E) \ 99*e4b17023SJohn Marino PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx) 100*e4b17023SJohn Marino #define PHI_ARG_INDEX_FROM_USE(USE) phi_arg_index_from_use (USE) 101*e4b17023SJohn Marino 102*e4b17023SJohn Marino 103*e4b17023SJohn Marino extern void init_ssa_operands (void); 104*e4b17023SJohn Marino extern void fini_ssa_operands (void); 105*e4b17023SJohn Marino extern void update_stmt_operands (gimple); 106*e4b17023SJohn Marino extern void free_stmt_operands (gimple); 107*e4b17023SJohn Marino extern bool verify_imm_links (FILE *f, tree var); 108*e4b17023SJohn Marino extern bool verify_ssa_operands (gimple stmt); 109*e4b17023SJohn Marino 110*e4b17023SJohn Marino extern void dump_immediate_uses (FILE *file); 111*e4b17023SJohn Marino extern void dump_immediate_uses_for (FILE *file, tree var); 112*e4b17023SJohn Marino extern void debug_immediate_uses (void); 113*e4b17023SJohn Marino extern void debug_immediate_uses_for (tree var); 114*e4b17023SJohn Marino extern void dump_decl_set (FILE *, bitmap); 115*e4b17023SJohn Marino extern void debug_decl_set (bitmap); 116*e4b17023SJohn Marino 117*e4b17023SJohn Marino extern bool ssa_operands_active (void); 118*e4b17023SJohn Marino 119*e4b17023SJohn Marino extern void unlink_stmt_vdef (gimple); 120*e4b17023SJohn Marino 121*e4b17023SJohn Marino enum ssa_op_iter_type { 122*e4b17023SJohn Marino ssa_op_iter_none = 0, 123*e4b17023SJohn Marino ssa_op_iter_tree, 124*e4b17023SJohn Marino ssa_op_iter_use, 125*e4b17023SJohn Marino ssa_op_iter_def 126*e4b17023SJohn Marino }; 127*e4b17023SJohn Marino 128*e4b17023SJohn Marino /* This structure is used in the operand iterator loops. It contains the 129*e4b17023SJohn Marino items required to determine which operand is retrieved next. During 130*e4b17023SJohn Marino optimization, this structure is scalarized, and any unused fields are 131*e4b17023SJohn Marino optimized away, resulting in little overhead. */ 132*e4b17023SJohn Marino 133*e4b17023SJohn Marino typedef struct ssa_operand_iterator_d 134*e4b17023SJohn Marino { 135*e4b17023SJohn Marino bool done; 136*e4b17023SJohn Marino enum ssa_op_iter_type iter_type; 137*e4b17023SJohn Marino def_optype_p defs; 138*e4b17023SJohn Marino use_optype_p uses; 139*e4b17023SJohn Marino int phi_i; 140*e4b17023SJohn Marino int num_phi; 141*e4b17023SJohn Marino gimple phi_stmt; 142*e4b17023SJohn Marino } ssa_op_iter; 143*e4b17023SJohn Marino 144*e4b17023SJohn Marino /* These flags are used to determine which operands are returned during 145*e4b17023SJohn Marino execution of the loop. */ 146*e4b17023SJohn Marino #define SSA_OP_USE 0x01 /* Real USE operands. */ 147*e4b17023SJohn Marino #define SSA_OP_DEF 0x02 /* Real DEF operands. */ 148*e4b17023SJohn Marino #define SSA_OP_VUSE 0x04 /* VUSE operands. */ 149*e4b17023SJohn Marino #define SSA_OP_VDEF 0x08 /* VDEF operands. */ 150*e4b17023SJohn Marino 151*e4b17023SJohn Marino /* These are commonly grouped operand flags. */ 152*e4b17023SJohn Marino #define SSA_OP_VIRTUAL_USES (SSA_OP_VUSE) 153*e4b17023SJohn Marino #define SSA_OP_VIRTUAL_DEFS (SSA_OP_VDEF) 154*e4b17023SJohn Marino #define SSA_OP_ALL_VIRTUALS (SSA_OP_VIRTUAL_USES | SSA_OP_VIRTUAL_DEFS) 155*e4b17023SJohn Marino #define SSA_OP_ALL_USES (SSA_OP_VIRTUAL_USES | SSA_OP_USE) 156*e4b17023SJohn Marino #define SSA_OP_ALL_DEFS (SSA_OP_VIRTUAL_DEFS | SSA_OP_DEF) 157*e4b17023SJohn Marino #define SSA_OP_ALL_OPERANDS (SSA_OP_ALL_USES | SSA_OP_ALL_DEFS) 158*e4b17023SJohn Marino 159*e4b17023SJohn Marino /* This macro executes a loop over the operands of STMT specified in FLAG, 160*e4b17023SJohn Marino returning each operand as a 'tree' in the variable TREEVAR. ITER is an 161*e4b17023SJohn Marino ssa_op_iter structure used to control the loop. */ 162*e4b17023SJohn Marino #define FOR_EACH_SSA_TREE_OPERAND(TREEVAR, STMT, ITER, FLAGS) \ 163*e4b17023SJohn Marino for (TREEVAR = op_iter_init_tree (&(ITER), STMT, FLAGS); \ 164*e4b17023SJohn Marino !op_iter_done (&(ITER)); \ 165*e4b17023SJohn Marino (void) (TREEVAR = op_iter_next_tree (&(ITER)))) 166*e4b17023SJohn Marino 167*e4b17023SJohn Marino /* This macro executes a loop over the operands of STMT specified in FLAG, 168*e4b17023SJohn Marino returning each operand as a 'use_operand_p' in the variable USEVAR. 169*e4b17023SJohn Marino ITER is an ssa_op_iter structure used to control the loop. */ 170*e4b17023SJohn Marino #define FOR_EACH_SSA_USE_OPERAND(USEVAR, STMT, ITER, FLAGS) \ 171*e4b17023SJohn Marino for (USEVAR = op_iter_init_use (&(ITER), STMT, FLAGS); \ 172*e4b17023SJohn Marino !op_iter_done (&(ITER)); \ 173*e4b17023SJohn Marino USEVAR = op_iter_next_use (&(ITER))) 174*e4b17023SJohn Marino 175*e4b17023SJohn Marino /* This macro executes a loop over the operands of STMT specified in FLAG, 176*e4b17023SJohn Marino returning each operand as a 'def_operand_p' in the variable DEFVAR. 177*e4b17023SJohn Marino ITER is an ssa_op_iter structure used to control the loop. */ 178*e4b17023SJohn Marino #define FOR_EACH_SSA_DEF_OPERAND(DEFVAR, STMT, ITER, FLAGS) \ 179*e4b17023SJohn Marino for (DEFVAR = op_iter_init_def (&(ITER), STMT, FLAGS); \ 180*e4b17023SJohn Marino !op_iter_done (&(ITER)); \ 181*e4b17023SJohn Marino DEFVAR = op_iter_next_def (&(ITER))) 182*e4b17023SJohn Marino 183*e4b17023SJohn Marino /* This macro will execute a loop over all the arguments of a PHI which 184*e4b17023SJohn Marino match FLAGS. A use_operand_p is always returned via USEVAR. FLAGS 185*e4b17023SJohn Marino can be either SSA_OP_USE or SSA_OP_VIRTUAL_USES or SSA_OP_ALL_USES. */ 186*e4b17023SJohn Marino #define FOR_EACH_PHI_ARG(USEVAR, STMT, ITER, FLAGS) \ 187*e4b17023SJohn Marino for ((USEVAR) = op_iter_init_phiuse (&(ITER), STMT, FLAGS); \ 188*e4b17023SJohn Marino !op_iter_done (&(ITER)); \ 189*e4b17023SJohn Marino (USEVAR) = op_iter_next_use (&(ITER))) 190*e4b17023SJohn Marino 191*e4b17023SJohn Marino 192*e4b17023SJohn Marino /* This macro will execute a loop over a stmt, regardless of whether it is 193*e4b17023SJohn Marino a real stmt or a PHI node, looking at the USE nodes matching FLAGS. */ 194*e4b17023SJohn Marino #define FOR_EACH_PHI_OR_STMT_USE(USEVAR, STMT, ITER, FLAGS) \ 195*e4b17023SJohn Marino for ((USEVAR) = (gimple_code (STMT) == GIMPLE_PHI \ 196*e4b17023SJohn Marino ? op_iter_init_phiuse (&(ITER), STMT, FLAGS) \ 197*e4b17023SJohn Marino : op_iter_init_use (&(ITER), STMT, FLAGS)); \ 198*e4b17023SJohn Marino !op_iter_done (&(ITER)); \ 199*e4b17023SJohn Marino (USEVAR) = op_iter_next_use (&(ITER))) 200*e4b17023SJohn Marino 201*e4b17023SJohn Marino /* This macro will execute a loop over a stmt, regardless of whether it is 202*e4b17023SJohn Marino a real stmt or a PHI node, looking at the DEF nodes matching FLAGS. */ 203*e4b17023SJohn Marino #define FOR_EACH_PHI_OR_STMT_DEF(DEFVAR, STMT, ITER, FLAGS) \ 204*e4b17023SJohn Marino for ((DEFVAR) = (gimple_code (STMT) == GIMPLE_PHI \ 205*e4b17023SJohn Marino ? op_iter_init_phidef (&(ITER), STMT, FLAGS) \ 206*e4b17023SJohn Marino : op_iter_init_def (&(ITER), STMT, FLAGS)); \ 207*e4b17023SJohn Marino !op_iter_done (&(ITER)); \ 208*e4b17023SJohn Marino (DEFVAR) = op_iter_next_def (&(ITER))) 209*e4b17023SJohn Marino 210*e4b17023SJohn Marino /* This macro returns an operand in STMT as a tree if it is the ONLY 211*e4b17023SJohn Marino operand matching FLAGS. If there are 0 or more than 1 operand matching 212*e4b17023SJohn Marino FLAGS, then NULL_TREE is returned. */ 213*e4b17023SJohn Marino #define SINGLE_SSA_TREE_OPERAND(STMT, FLAGS) \ 214*e4b17023SJohn Marino single_ssa_tree_operand (STMT, FLAGS) 215*e4b17023SJohn Marino 216*e4b17023SJohn Marino /* This macro returns an operand in STMT as a use_operand_p if it is the ONLY 217*e4b17023SJohn Marino operand matching FLAGS. If there are 0 or more than 1 operand matching 218*e4b17023SJohn Marino FLAGS, then NULL_USE_OPERAND_P is returned. */ 219*e4b17023SJohn Marino #define SINGLE_SSA_USE_OPERAND(STMT, FLAGS) \ 220*e4b17023SJohn Marino single_ssa_use_operand (STMT, FLAGS) 221*e4b17023SJohn Marino 222*e4b17023SJohn Marino /* This macro returns an operand in STMT as a def_operand_p if it is the ONLY 223*e4b17023SJohn Marino operand matching FLAGS. If there are 0 or more than 1 operand matching 224*e4b17023SJohn Marino FLAGS, then NULL_DEF_OPERAND_P is returned. */ 225*e4b17023SJohn Marino #define SINGLE_SSA_DEF_OPERAND(STMT, FLAGS) \ 226*e4b17023SJohn Marino single_ssa_def_operand (STMT, FLAGS) 227*e4b17023SJohn Marino 228*e4b17023SJohn Marino /* This macro returns TRUE if there are no operands matching FLAGS in STMT. */ 229*e4b17023SJohn Marino #define ZERO_SSA_OPERANDS(STMT, FLAGS) zero_ssa_operands (STMT, FLAGS) 230*e4b17023SJohn Marino 231*e4b17023SJohn Marino /* This macro counts the number of operands in STMT matching FLAGS. */ 232*e4b17023SJohn Marino #define NUM_SSA_OPERANDS(STMT, FLAGS) num_ssa_operands (STMT, FLAGS) 233*e4b17023SJohn Marino 234*e4b17023SJohn Marino #endif /* GCC_TREE_SSA_OPERANDS_H */ 235