1 /* Tree SCC value numbering
2 Copyright (C) 2007, 2008, 2009, 2010 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. */
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
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;
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. */
52 sizeof_vn_nary_op (unsigned int length
)
54 return sizeof (struct vn_nary_op_s
) + sizeof (tree
) * (length
- 1);
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
;
68 VEC (tree
, heap
) *phiargs
;
72 typedef const struct vn_phi_s
*const_vn_phi_t
;
74 /* Reference operands only exist in reference operations structures.
75 They consist of an opcode, type, and some number of operands. For
76 a given opcode, some, all, or none of the operands may be used.
77 The operands are there to store the information that makes up the
78 portion of the addressing calculation that opcode performs. */
80 typedef struct vn_reference_op_struct
82 enum tree_code opcode
;
83 /* Constant offset this op adds or -1 if it is variable. */
90 typedef vn_reference_op_s
*vn_reference_op_t
;
91 typedef const vn_reference_op_s
*const_vn_reference_op_t
;
93 DEF_VEC_O(vn_reference_op_s
);
94 DEF_VEC_ALLOC_O(vn_reference_op_s
, heap
);
96 /* A reference operation in the hashtable is representation as
97 the vuse, representing the memory state at the time of
98 the operation, and a collection of operands that make up the
99 addressing calculation. If two vn_reference_t's have the same set
100 of operands, they access the same memory location. We also store
101 the resulting value number, and the hashcode. */
103 typedef struct vn_reference_s
105 /* Unique identifier that all expressions with the same value have. */
106 unsigned int value_id
;
111 VEC (vn_reference_op_s
, heap
) *operands
;
114 typedef const struct vn_reference_s
*const_vn_reference_t
;
116 typedef struct vn_constant_s
118 unsigned int value_id
;
123 /* Hash the constant CONSTANT with distinguishing type incompatible
124 constants in the types_compatible_p sense. */
126 static inline hashval_t
127 vn_hash_constant_with_type (tree constant
)
129 tree type
= TREE_TYPE (constant
);
130 return (iterative_hash_expr (constant
, 0)
131 + INTEGRAL_TYPE_P (type
)
132 + (INTEGRAL_TYPE_P (type
)
133 ? TYPE_PRECISION (type
) + TYPE_UNSIGNED (type
) : 0));
136 /* Compare the constants C1 and C2 with distinguishing type incompatible
137 constants in the types_compatible_p sense. */
140 vn_constant_eq_with_type (tree c1
, tree c2
)
142 return (expressions_equal_p (c1
, c2
)
143 && types_compatible_p (TREE_TYPE (c1
), TREE_TYPE (c2
)));
146 typedef struct vn_ssa_aux
148 /* Value number. This may be an SSA name or a constant. */
150 /* Representative expression, if not a direct constant. */
153 /* Unique identifier that all expressions with the same value have. */
154 unsigned int value_id
;
156 /* SCC information. */
159 unsigned visited
: 1;
160 unsigned on_sccstack
: 1;
162 /* Whether the representative expression contains constants. */
163 unsigned has_constants
: 1;
164 /* Whether the SSA_NAME has been value numbered already. This is
165 only saying whether visit_use has been called on it at least
166 once. It cannot be used to avoid visitation for SSA_NAME's
167 involved in non-singleton SCC's. */
168 unsigned use_processed
: 1;
170 /* Whether the SSA_NAME has no defining statement and thus an
171 insertion of such with EXPR as definition is required before
172 a use can be created of it. */
173 unsigned needs_insertion
: 1;
176 typedef enum { VN_NOWALK
, VN_WALK
, VN_WALKREWRITE
} vn_lookup_kind
;
178 /* Return the value numbering info for an SSA_NAME. */
179 extern vn_ssa_aux_t
VN_INFO (tree
);
180 extern vn_ssa_aux_t
VN_INFO_GET (tree
);
181 tree
vn_get_expr_for (tree
);
182 bool run_scc_vn (vn_lookup_kind
);
183 void free_scc_vn (void);
184 tree
vn_nary_op_lookup (tree
, vn_nary_op_t
*);
185 tree
vn_nary_op_lookup_stmt (gimple
, vn_nary_op_t
*);
186 tree
vn_nary_op_lookup_pieces (unsigned int, enum tree_code
,
187 tree
, tree
*, vn_nary_op_t
*);
188 vn_nary_op_t
vn_nary_op_insert (tree
, tree
);
189 vn_nary_op_t
vn_nary_op_insert_stmt (gimple
, tree
);
190 vn_nary_op_t
vn_nary_op_insert_pieces (unsigned int, enum tree_code
,
191 tree
, tree
*, tree
, unsigned int);
192 void vn_reference_fold_indirect (VEC (vn_reference_op_s
, heap
) **,
194 void copy_reference_ops_from_ref (tree
, VEC(vn_reference_op_s
, heap
) **);
195 void copy_reference_ops_from_call (gimple
, VEC(vn_reference_op_s
, heap
) **);
196 bool ao_ref_init_from_vn_reference (ao_ref
*, alias_set_type
, tree
,
197 VEC (vn_reference_op_s
, heap
) *);
198 tree
vn_reference_lookup_pieces (tree
, alias_set_type
, tree
,
199 VEC (vn_reference_op_s
, heap
) *,
200 vn_reference_t
*, vn_lookup_kind
);
201 tree
vn_reference_lookup (tree
, tree
, vn_lookup_kind
, vn_reference_t
*);
202 vn_reference_t
vn_reference_insert (tree
, tree
, tree
);
203 vn_reference_t
vn_reference_insert_pieces (tree
, alias_set_type
, tree
,
204 VEC (vn_reference_op_s
, heap
) *,
207 hashval_t
vn_nary_op_compute_hash (const vn_nary_op_t
);
208 int vn_nary_op_eq (const void *, const void *);
209 bool vn_nary_may_trap (vn_nary_op_t
);
210 hashval_t
vn_reference_compute_hash (const vn_reference_t
);
211 int vn_reference_eq (const void *, const void *);
212 unsigned int get_max_value_id (void);
213 unsigned int get_next_value_id (void);
214 unsigned int get_constant_value_id (tree
);
215 unsigned int get_or_alloc_constant_value_id (tree
);
216 bool value_id_constant_p (unsigned int);
217 tree
fully_constant_vn_reference_p (vn_reference_t
);
219 /* Valueize NAME if it is an SSA name, otherwise just return it. */
222 vn_valueize (tree name
)
224 if (TREE_CODE (name
) == SSA_NAME
)
226 tree tem
= VN_INFO (name
)->valnum
;
227 return tem
== VN_TOP
? name
: tem
;
232 #endif /* TREE_SSA_SCCVN_H */