xref: /dflybsd-src/contrib/gcc-8.0/gcc/gimple-ssa.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Header file for routines that straddle the border between GIMPLE and
2*38fd1498Szrj    SSA in gimple.
3*38fd1498Szrj    Copyright (C) 2009-2018 Free Software Foundation, Inc.
4*38fd1498Szrj 
5*38fd1498Szrj This file is part of GCC.
6*38fd1498Szrj 
7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify
8*38fd1498Szrj it under the terms of the GNU General Public License as published by
9*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
10*38fd1498Szrj any later version.
11*38fd1498Szrj 
12*38fd1498Szrj GCC is distributed in the hope that it will be useful,
13*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
14*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*38fd1498Szrj GNU General Public License for more details.
16*38fd1498Szrj 
17*38fd1498Szrj You should have received a copy of the GNU General Public License
18*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
19*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
20*38fd1498Szrj 
21*38fd1498Szrj #ifndef GCC_GIMPLE_SSA_H
22*38fd1498Szrj #define GCC_GIMPLE_SSA_H
23*38fd1498Szrj 
24*38fd1498Szrj #include "tree-ssa-operands.h"
25*38fd1498Szrj 
26*38fd1498Szrj /* This structure is used to map a gimple statement to a label,
27*38fd1498Szrj    or list of labels to represent transaction restart.  */
28*38fd1498Szrj 
29*38fd1498Szrj struct GTY((for_user)) tm_restart_node {
30*38fd1498Szrj   gimple *stmt;
31*38fd1498Szrj   tree label_or_list;
32*38fd1498Szrj };
33*38fd1498Szrj 
34*38fd1498Szrj /* Hasher for tm_restart_node.  */
35*38fd1498Szrj 
36*38fd1498Szrj struct tm_restart_hasher : ggc_ptr_hash<tm_restart_node>
37*38fd1498Szrj {
hashtm_restart_hasher38*38fd1498Szrj   static hashval_t hash (tm_restart_node *n) { return htab_hash_pointer (n); }
39*38fd1498Szrj 
40*38fd1498Szrj   static bool
equaltm_restart_hasher41*38fd1498Szrj   equal (tm_restart_node *a, tm_restart_node *b)
42*38fd1498Szrj   {
43*38fd1498Szrj     return a == b;
44*38fd1498Szrj   }
45*38fd1498Szrj };
46*38fd1498Szrj 
47*38fd1498Szrj extern void gt_ggc_mx (gimple *&);
48*38fd1498Szrj extern void gt_pch_nx (gimple *&);
49*38fd1498Szrj 
50*38fd1498Szrj struct ssa_name_hasher : ggc_ptr_hash<tree_node>
51*38fd1498Szrj {
52*38fd1498Szrj   /* Hash a tree in a uid_decl_map.  */
53*38fd1498Szrj 
54*38fd1498Szrj   static hashval_t
hashssa_name_hasher55*38fd1498Szrj   hash (tree item)
56*38fd1498Szrj   {
57*38fd1498Szrj     return item->ssa_name.var->decl_minimal.uid;
58*38fd1498Szrj   }
59*38fd1498Szrj 
60*38fd1498Szrj   /* Return true if the DECL_UID in both trees are equal.  */
61*38fd1498Szrj 
62*38fd1498Szrj   static bool
equalssa_name_hasher63*38fd1498Szrj   equal (tree a, tree b)
64*38fd1498Szrj {
65*38fd1498Szrj   return (a->ssa_name.var->decl_minimal.uid == b->ssa_name.var->decl_minimal.uid);
66*38fd1498Szrj }
67*38fd1498Szrj };
68*38fd1498Szrj 
69*38fd1498Szrj /* Gimple dataflow datastructure. All publicly available fields shall have
70*38fd1498Szrj    gimple_ accessor defined, all publicly modifiable fields should have
71*38fd1498Szrj    gimple_set accessor.  */
72*38fd1498Szrj struct GTY(()) gimple_df {
73*38fd1498Szrj   /* Array of all SSA_NAMEs used in the function.  */
74*38fd1498Szrj   vec<tree, va_gc> *ssa_names;
75*38fd1498Szrj 
76*38fd1498Szrj   /* Artificial variable used for the virtual operand FUD chain.  */
77*38fd1498Szrj   tree vop;
78*38fd1498Szrj 
79*38fd1498Szrj   /* The PTA solution for the ESCAPED artificial variable.  */
80*38fd1498Szrj   struct pt_solution escaped;
81*38fd1498Szrj 
82*38fd1498Szrj   /* A map of decls to artificial ssa-names that point to the partition
83*38fd1498Szrj      of the decl.  */
84*38fd1498Szrj   hash_map<tree, tree> * GTY((skip(""))) decls_to_pointers;
85*38fd1498Szrj 
86*38fd1498Szrj   /* Free list of SSA_NAMEs.  */
87*38fd1498Szrj   vec<tree, va_gc> *free_ssanames;
88*38fd1498Szrj 
89*38fd1498Szrj   /* Queue of SSA_NAMEs to be freed at the next opportunity.  */
90*38fd1498Szrj   vec<tree, va_gc> *free_ssanames_queue;
91*38fd1498Szrj 
92*38fd1498Szrj   /* Hashtable holding definition for symbol.  If this field is not NULL, it
93*38fd1498Szrj      means that the first reference to this variable in the function is a
94*38fd1498Szrj      USE or a VUSE.  In those cases, the SSA renamer creates an SSA name
95*38fd1498Szrj      for this variable with an empty defining statement.  */
96*38fd1498Szrj   hash_table<ssa_name_hasher> *default_defs;
97*38fd1498Szrj 
98*38fd1498Szrj   /* True if there are any symbols that need to be renamed.  */
99*38fd1498Szrj   unsigned int ssa_renaming_needed : 1;
100*38fd1498Szrj 
101*38fd1498Szrj   /* True if all virtual operands need to be renamed.  */
102*38fd1498Szrj   unsigned int rename_vops : 1;
103*38fd1498Szrj 
104*38fd1498Szrj   /* True if the code is in ssa form.  */
105*38fd1498Szrj   unsigned int in_ssa_p : 1;
106*38fd1498Szrj 
107*38fd1498Szrj   /* True if IPA points-to information was computed for this function.  */
108*38fd1498Szrj   unsigned int ipa_pta : 1;
109*38fd1498Szrj 
110*38fd1498Szrj   struct ssa_operands ssa_operands;
111*38fd1498Szrj 
112*38fd1498Szrj   /* Map gimple stmt to tree label (or list of labels) for transaction
113*38fd1498Szrj      restart and abort.  */
114*38fd1498Szrj   hash_table<tm_restart_hasher> *tm_restart;
115*38fd1498Szrj };
116*38fd1498Szrj 
117*38fd1498Szrj 
118*38fd1498Szrj /* Return true when gimple SSA form was built.
119*38fd1498Szrj    gimple_in_ssa_p is queried by gimplifier in various early stages before SSA
120*38fd1498Szrj    infrastructure is initialized.  Check for presence of the datastructures
121*38fd1498Szrj    at first place.  */
122*38fd1498Szrj static inline bool
gimple_in_ssa_p(const struct function * fun)123*38fd1498Szrj gimple_in_ssa_p (const struct function *fun)
124*38fd1498Szrj {
125*38fd1498Szrj   return fun && fun->gimple_df && fun->gimple_df->in_ssa_p;
126*38fd1498Szrj }
127*38fd1498Szrj 
128*38fd1498Szrj /* Artificial variable used for the virtual operand FUD chain.  */
129*38fd1498Szrj static inline tree
gimple_vop(const struct function * fun)130*38fd1498Szrj gimple_vop (const struct function *fun)
131*38fd1498Szrj {
132*38fd1498Szrj   gcc_checking_assert (fun && fun->gimple_df);
133*38fd1498Szrj   return fun->gimple_df->vop;
134*38fd1498Szrj }
135*38fd1498Szrj 
136*38fd1498Szrj /* Return the set of VUSE operand for statement G.  */
137*38fd1498Szrj 
138*38fd1498Szrj static inline use_operand_p
gimple_vuse_op(const gimple * g)139*38fd1498Szrj gimple_vuse_op (const gimple *g)
140*38fd1498Szrj {
141*38fd1498Szrj   struct use_optype_d *ops;
142*38fd1498Szrj   const gimple_statement_with_memory_ops *mem_ops_stmt =
143*38fd1498Szrj      dyn_cast <const gimple_statement_with_memory_ops *> (g);
144*38fd1498Szrj   if (!mem_ops_stmt)
145*38fd1498Szrj     return NULL_USE_OPERAND_P;
146*38fd1498Szrj   ops = mem_ops_stmt->use_ops;
147*38fd1498Szrj   if (ops
148*38fd1498Szrj       && USE_OP_PTR (ops)->use == &mem_ops_stmt->vuse)
149*38fd1498Szrj     return USE_OP_PTR (ops);
150*38fd1498Szrj   return NULL_USE_OPERAND_P;
151*38fd1498Szrj }
152*38fd1498Szrj 
153*38fd1498Szrj /* Return the set of VDEF operand for statement G.  */
154*38fd1498Szrj 
155*38fd1498Szrj static inline def_operand_p
gimple_vdef_op(gimple * g)156*38fd1498Szrj gimple_vdef_op (gimple *g)
157*38fd1498Szrj {
158*38fd1498Szrj   gimple_statement_with_memory_ops *mem_ops_stmt =
159*38fd1498Szrj      dyn_cast <gimple_statement_with_memory_ops *> (g);
160*38fd1498Szrj   if (!mem_ops_stmt)
161*38fd1498Szrj     return NULL_DEF_OPERAND_P;
162*38fd1498Szrj   if (mem_ops_stmt->vdef)
163*38fd1498Szrj     return &mem_ops_stmt->vdef;
164*38fd1498Szrj   return NULL_DEF_OPERAND_P;
165*38fd1498Szrj }
166*38fd1498Szrj 
167*38fd1498Szrj /* Mark statement S as modified, and update it.  */
168*38fd1498Szrj 
169*38fd1498Szrj static inline void
update_stmt(gimple * s)170*38fd1498Szrj update_stmt (gimple *s)
171*38fd1498Szrj {
172*38fd1498Szrj   if (gimple_has_ops (s))
173*38fd1498Szrj     {
174*38fd1498Szrj       gimple_set_modified (s, true);
175*38fd1498Szrj       update_stmt_operands (cfun, s);
176*38fd1498Szrj     }
177*38fd1498Szrj }
178*38fd1498Szrj 
179*38fd1498Szrj /* Update statement S if it has been optimized.  */
180*38fd1498Szrj 
181*38fd1498Szrj static inline void
update_stmt_if_modified(gimple * s)182*38fd1498Szrj update_stmt_if_modified (gimple *s)
183*38fd1498Szrj {
184*38fd1498Szrj   if (gimple_modified_p (s))
185*38fd1498Szrj     update_stmt_operands (cfun, s);
186*38fd1498Szrj }
187*38fd1498Szrj 
188*38fd1498Szrj /* Mark statement S as modified, and update it.  */
189*38fd1498Szrj 
190*38fd1498Szrj static inline void
update_stmt_fn(struct function * fn,gimple * s)191*38fd1498Szrj update_stmt_fn (struct function *fn, gimple *s)
192*38fd1498Szrj {
193*38fd1498Szrj   if (gimple_has_ops (s))
194*38fd1498Szrj     {
195*38fd1498Szrj       gimple_set_modified (s, true);
196*38fd1498Szrj       update_stmt_operands (fn, s);
197*38fd1498Szrj     }
198*38fd1498Szrj }
199*38fd1498Szrj 
200*38fd1498Szrj 
201*38fd1498Szrj #endif /* GCC_GIMPLE_SSA_H */
202