Home | History | Annotate | Line # | Download | only in gcc
      1 /* SSA operand management for trees.
      2    Copyright (C) 2003-2024 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_t 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"))) 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(PHI, I)	USE_FROM_PTR (PHI_ARG_DEF_PTR ((PHI), (I)))
     80 */
     81 #define PHI_ARG_DEF_PTR(PHI, I)	gimple_phi_arg_imm_use_ptr ((PHI), (I))
     82 #define PHI_ARG_DEF(PHI, I)	gimple_phi_arg_def ((PHI), (I))
     83 #define SET_PHI_ARG_DEF(PHI, I, V)					\
     84 				SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V))
     85 #define SET_PHI_ARG_DEF_ON_EDGE(PHI, E, V)				      \
     86 				SET_USE (gimple_phi_arg_imm_use_ptr_from_edge \
     87 					   ((PHI), (E)), (V))
     88 #define PHI_ARG_DEF_FROM_EDGE(PHI, E)					\
     89 				gimple_phi_arg_def_from_edge ((PHI), (E))
     90 #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E)				\
     91 				gimple_phi_arg_imm_use_ptr_from_edge ((PHI), (E))
     92 #define PHI_ARG_INDEX_FROM_USE(USE)   phi_arg_index_from_use (USE)
     93 
     94 
     95 extern bool ssa_operands_active (struct function *);
     96 extern void init_ssa_operands (struct function *fn);
     97 extern void fini_ssa_operands (struct function *);
     98 extern bool verify_ssa_operands (struct function *, gimple *stmt);
     99 extern void free_stmt_operands (struct function *, gimple *);
    100 extern void update_stmt_operands (struct function *, gimple *);
    101 extern void swap_ssa_operands (gimple *, tree *, tree *);
    102 extern bool verify_imm_links (FILE *f, tree var);
    103 
    104 extern void dump_immediate_uses_for (FILE *file, tree var);
    105 extern void dump_immediate_uses (FILE *file);
    106 extern void debug_immediate_uses (void);
    107 extern void debug_immediate_uses_for (tree var);
    108 
    109 extern void unlink_stmt_vdef (gimple *);
    110 
    111 /* Return the tree pointed-to by USE.  */
    112 inline tree
    113 get_use_from_ptr (use_operand_p use)
    114 {
    115   return *(use->use);
    116 }
    117 
    118 /* Return the tree pointed-to by DEF.  */
    119 inline tree
    120 get_def_from_ptr (def_operand_p def)
    121 {
    122   return *def;
    123 }
    124 
    125 #endif  /* GCC_TREE_SSA_OPERANDS_H  */
    126