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