[PR67828] don't unswitch on default defs of non-parms
[official-gcc.git] / gcc / tree-ssa-sccvn.h
blobc8b918aa4e998c137f9dfa4be6b8e5a2481ffcbf
1 /* Tree SCC value numbering
2 Copyright (C) 2007-2015 Free Software Foundation, Inc.
3 Contributed by Daniel Berlin <dberlin@dberlin.org>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef TREE_SSA_SCCVN_H
22 #define TREE_SSA_SCCVN_H
24 /* In tree-ssa-sccvn.c */
25 bool expressions_equal_p (tree, tree);
28 /* TOP of the VN lattice. */
29 extern tree VN_TOP;
31 /* N-ary operations in the hashtable consist of length operands, an
32 opcode, and a type. Result is the value number of the operation,
33 and hashcode is stored to avoid having to calculate it
34 repeatedly. */
36 typedef struct vn_nary_op_s
38 /* Unique identify that all expressions with the same value have. */
39 unsigned int value_id;
40 ENUM_BITFIELD(tree_code) opcode : 16;
41 unsigned length : 16;
42 hashval_t hashcode;
43 tree result;
44 tree type;
45 tree op[1];
46 } *vn_nary_op_t;
47 typedef const struct vn_nary_op_s *const_vn_nary_op_t;
49 /* Return the size of a vn_nary_op_t with LENGTH operands. */
51 static inline size_t
52 sizeof_vn_nary_op (unsigned int length)
54 return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
57 /* Phi nodes in the hashtable consist of their non-VN_TOP phi
58 arguments, and the basic block the phi is in. Result is the value
59 number of the operation, and hashcode is stored to avoid having to
60 calculate it repeatedly. Phi nodes not in the same block are never
61 considered equivalent. */
63 typedef struct vn_phi_s
65 /* Unique identifier that all expressions with the same value have. */
66 unsigned int value_id;
67 hashval_t hashcode;
68 vec<tree> phiargs;
69 basic_block block;
70 tree type;
71 tree result;
72 } *vn_phi_t;
73 typedef const struct vn_phi_s *const_vn_phi_t;
75 /* Reference operands only exist in reference operations structures.
76 They consist of an opcode, type, and some number of operands. For
77 a given opcode, some, all, or none of the operands may be used.
78 The operands are there to store the information that makes up the
79 portion of the addressing calculation that opcode performs. */
81 typedef struct vn_reference_op_struct
83 ENUM_BITFIELD(tree_code) opcode : 16;
84 /* 1 for instrumented calls. */
85 unsigned with_bounds : 1;
86 /* Dependence info, used for [TARGET_]MEM_REF only. */
87 unsigned short clique;
88 unsigned short base;
89 /* Constant offset this op adds or -1 if it is variable. */
90 HOST_WIDE_INT off;
91 tree type;
92 tree op0;
93 tree op1;
94 tree op2;
95 } vn_reference_op_s;
96 typedef vn_reference_op_s *vn_reference_op_t;
97 typedef const vn_reference_op_s *const_vn_reference_op_t;
100 /* A reference operation in the hashtable is representation as
101 the vuse, representing the memory state at the time of
102 the operation, and a collection of operands that make up the
103 addressing calculation. If two vn_reference_t's have the same set
104 of operands, they access the same memory location. We also store
105 the resulting value number, and the hashcode. */
107 typedef struct vn_reference_s
109 /* Unique identifier that all expressions with the same value have. */
110 unsigned int value_id;
111 hashval_t hashcode;
112 tree vuse;
113 alias_set_type set;
114 tree type;
115 vec<vn_reference_op_s> operands;
116 tree result;
117 tree result_vdef;
118 } *vn_reference_t;
119 typedef const struct vn_reference_s *const_vn_reference_t;
121 typedef struct vn_constant_s
123 unsigned int value_id;
124 hashval_t hashcode;
125 tree constant;
126 } *vn_constant_t;
128 enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI };
129 enum vn_kind vn_get_stmt_kind (gimple *);
131 /* Hash the type TYPE using bits that distinguishes it in the
132 types_compatible_p sense. */
134 static inline hashval_t
135 vn_hash_type (tree type)
137 return (INTEGRAL_TYPE_P (type)
138 + (INTEGRAL_TYPE_P (type)
139 ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
142 /* Hash the constant CONSTANT with distinguishing type incompatible
143 constants in the types_compatible_p sense. */
145 static inline hashval_t
146 vn_hash_constant_with_type (tree constant)
148 inchash::hash hstate;
149 inchash::add_expr (constant, hstate);
150 hstate.merge_hash (vn_hash_type (TREE_TYPE (constant)));
151 return hstate.end ();
154 /* Compare the constants C1 and C2 with distinguishing type incompatible
155 constants in the types_compatible_p sense. */
157 static inline bool
158 vn_constant_eq_with_type (tree c1, tree c2)
160 return (expressions_equal_p (c1, c2)
161 && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
164 typedef struct vn_ssa_aux
166 /* Value number. This may be an SSA name or a constant. */
167 tree valnum;
168 /* Statements to insert if needs_insertion is true. */
169 gimple_seq expr;
171 /* Unique identifier that all expressions with the same value have. */
172 unsigned int value_id;
174 /* SCC information. */
175 unsigned int dfsnum;
176 unsigned int low;
177 unsigned visited : 1;
178 unsigned on_sccstack : 1;
180 /* Whether the SSA_NAME has been value numbered already. This is
181 only saying whether visit_use has been called on it at least
182 once. It cannot be used to avoid visitation for SSA_NAME's
183 involved in non-singleton SCC's. */
184 unsigned use_processed : 1;
186 /* Whether the SSA_NAME has no defining statement and thus an
187 insertion of such with EXPR as definition is required before
188 a use can be created of it. */
189 unsigned needs_insertion : 1;
190 } *vn_ssa_aux_t;
192 enum vn_lookup_kind { VN_NOWALK, VN_WALK, VN_WALKREWRITE };
194 /* Return the value numbering info for an SSA_NAME. */
195 extern vn_ssa_aux_t VN_INFO (tree);
196 extern vn_ssa_aux_t VN_INFO_GET (tree);
197 tree vn_get_expr_for (tree);
198 bool run_scc_vn (vn_lookup_kind);
199 void free_scc_vn (void);
200 tree vn_nary_op_lookup (tree, vn_nary_op_t *);
201 tree vn_nary_op_lookup_stmt (gimple *, vn_nary_op_t *);
202 tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
203 tree, tree *, vn_nary_op_t *);
204 vn_nary_op_t vn_nary_op_insert (tree, tree);
205 vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
206 tree, tree *, tree, unsigned int);
207 bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
208 vec<vn_reference_op_s> );
209 tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
210 vec<vn_reference_op_s> ,
211 vn_reference_t *, vn_lookup_kind);
212 tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *);
213 void vn_reference_lookup_call (gcall *, vn_reference_t *, vn_reference_t);
214 vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
215 vec<vn_reference_op_s> ,
216 tree, unsigned int);
218 bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
219 const_vn_nary_op_t const vno2);
220 bool vn_nary_may_trap (vn_nary_op_t);
221 bool vn_reference_eq (const_vn_reference_t const, const_vn_reference_t const);
222 unsigned int get_max_value_id (void);
223 unsigned int get_next_value_id (void);
224 unsigned int get_constant_value_id (tree);
225 unsigned int get_or_alloc_constant_value_id (tree);
226 bool value_id_constant_p (unsigned int);
227 tree fully_constant_vn_reference_p (vn_reference_t);
229 /* Valueize NAME if it is an SSA name, otherwise just return it. */
231 static inline tree
232 vn_valueize (tree name)
234 if (TREE_CODE (name) == SSA_NAME)
236 tree tem = VN_INFO (name)->valnum;
237 return tem == VN_TOP ? name : tem;
239 return name;
242 #endif /* TREE_SSA_SCCVN_H */