1 |
280 |
jeremybenn |
/* Tree SCC value numbering
|
2 |
|
|
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
|
3 |
|
|
Contributed by Daniel Berlin <dberlin@dberlin.org>
|
4 |
|
|
|
5 |
|
|
This file is part of GCC.
|
6 |
|
|
|
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.
|
11 |
|
|
|
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.
|
16 |
|
|
|
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/>. */
|
20 |
|
|
|
21 |
|
|
#ifndef TREE_SSA_SCCVN_H
|
22 |
|
|
#define TREE_SSA_SCCVN_H
|
23 |
|
|
|
24 |
|
|
/* In tree-ssa-sccvn.c */
|
25 |
|
|
bool expressions_equal_p (tree, tree);
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
/* TOP of the VN lattice. */
|
29 |
|
|
extern tree VN_TOP;
|
30 |
|
|
|
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. */
|
35 |
|
|
|
36 |
|
|
typedef struct vn_nary_op_s
|
37 |
|
|
{
|
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[4];
|
46 |
|
|
} *vn_nary_op_t;
|
47 |
|
|
typedef const struct vn_nary_op_s *const_vn_nary_op_t;
|
48 |
|
|
|
49 |
|
|
/* Phi nodes in the hashtable consist of their non-VN_TOP phi
|
50 |
|
|
arguments, and the basic block the phi is in. Result is the value
|
51 |
|
|
number of the operation, and hashcode is stored to avoid having to
|
52 |
|
|
calculate it repeatedly. Phi nodes not in the same block are never
|
53 |
|
|
considered equivalent. */
|
54 |
|
|
|
55 |
|
|
typedef struct vn_phi_s
|
56 |
|
|
{
|
57 |
|
|
/* Unique identifier that all expressions with the same value have. */
|
58 |
|
|
unsigned int value_id;
|
59 |
|
|
hashval_t hashcode;
|
60 |
|
|
VEC (tree, heap) *phiargs;
|
61 |
|
|
basic_block block;
|
62 |
|
|
tree result;
|
63 |
|
|
} *vn_phi_t;
|
64 |
|
|
typedef const struct vn_phi_s *const_vn_phi_t;
|
65 |
|
|
|
66 |
|
|
/* Reference operands only exist in reference operations structures.
|
67 |
|
|
They consist of an opcode, type, and some number of operands. For
|
68 |
|
|
a given opcode, some, all, or none of the operands may be used.
|
69 |
|
|
The operands are there to store the information that makes up the
|
70 |
|
|
portion of the addressing calculation that opcode performs. */
|
71 |
|
|
|
72 |
|
|
typedef struct vn_reference_op_struct
|
73 |
|
|
{
|
74 |
|
|
enum tree_code opcode;
|
75 |
|
|
tree type;
|
76 |
|
|
tree op0;
|
77 |
|
|
tree op1;
|
78 |
|
|
tree op2;
|
79 |
|
|
} vn_reference_op_s;
|
80 |
|
|
typedef vn_reference_op_s *vn_reference_op_t;
|
81 |
|
|
typedef const vn_reference_op_s *const_vn_reference_op_t;
|
82 |
|
|
|
83 |
|
|
DEF_VEC_O(vn_reference_op_s);
|
84 |
|
|
DEF_VEC_ALLOC_O(vn_reference_op_s, heap);
|
85 |
|
|
|
86 |
|
|
/* A reference operation in the hashtable is representation as
|
87 |
|
|
the vuse, representing the memory state at the time of
|
88 |
|
|
the operation, and a collection of operands that make up the
|
89 |
|
|
addressing calculation. If two vn_reference_t's have the same set
|
90 |
|
|
of operands, they access the same memory location. We also store
|
91 |
|
|
the resulting value number, and the hashcode. */
|
92 |
|
|
|
93 |
|
|
typedef struct vn_reference_s
|
94 |
|
|
{
|
95 |
|
|
/* Unique identifier that all expressions with the same value have. */
|
96 |
|
|
unsigned int value_id;
|
97 |
|
|
hashval_t hashcode;
|
98 |
|
|
tree vuse;
|
99 |
|
|
alias_set_type set;
|
100 |
|
|
tree type;
|
101 |
|
|
VEC (vn_reference_op_s, heap) *operands;
|
102 |
|
|
tree result;
|
103 |
|
|
} *vn_reference_t;
|
104 |
|
|
typedef const struct vn_reference_s *const_vn_reference_t;
|
105 |
|
|
|
106 |
|
|
typedef struct vn_constant_s
|
107 |
|
|
{
|
108 |
|
|
unsigned int value_id;
|
109 |
|
|
hashval_t hashcode;
|
110 |
|
|
tree constant;
|
111 |
|
|
} *vn_constant_t;
|
112 |
|
|
|
113 |
|
|
/* Hash the constant CONSTANT with distinguishing type incompatible
|
114 |
|
|
constants in the types_compatible_p sense. */
|
115 |
|
|
|
116 |
|
|
static inline hashval_t
|
117 |
|
|
vn_hash_constant_with_type (tree constant)
|
118 |
|
|
{
|
119 |
|
|
tree type = TREE_TYPE (constant);
|
120 |
|
|
return (iterative_hash_expr (constant, 0)
|
121 |
|
|
+ INTEGRAL_TYPE_P (type)
|
122 |
|
|
+ (INTEGRAL_TYPE_P (type)
|
123 |
|
|
? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
/* Compare the constants C1 and C2 with distinguishing type incompatible
|
127 |
|
|
constants in the types_compatible_p sense. */
|
128 |
|
|
|
129 |
|
|
static inline bool
|
130 |
|
|
vn_constant_eq_with_type (tree c1, tree c2)
|
131 |
|
|
{
|
132 |
|
|
return (expressions_equal_p (c1, c2)
|
133 |
|
|
&& types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
typedef struct vn_ssa_aux
|
137 |
|
|
{
|
138 |
|
|
/* Value number. This may be an SSA name or a constant. */
|
139 |
|
|
tree valnum;
|
140 |
|
|
/* Representative expression, if not a direct constant. */
|
141 |
|
|
tree expr;
|
142 |
|
|
|
143 |
|
|
/* Unique identifier that all expressions with the same value have. */
|
144 |
|
|
unsigned int value_id;
|
145 |
|
|
|
146 |
|
|
/* SCC information. */
|
147 |
|
|
unsigned int dfsnum;
|
148 |
|
|
unsigned int low;
|
149 |
|
|
unsigned visited : 1;
|
150 |
|
|
unsigned on_sccstack : 1;
|
151 |
|
|
|
152 |
|
|
/* Whether the representative expression contains constants. */
|
153 |
|
|
unsigned has_constants : 1;
|
154 |
|
|
/* Whether the SSA_NAME has been value numbered already. This is
|
155 |
|
|
only saying whether visit_use has been called on it at least
|
156 |
|
|
once. It cannot be used to avoid visitation for SSA_NAME's
|
157 |
|
|
involved in non-singleton SCC's. */
|
158 |
|
|
unsigned use_processed : 1;
|
159 |
|
|
|
160 |
|
|
/* Whether the SSA_NAME has no defining statement and thus an
|
161 |
|
|
insertion of such with EXPR as definition is required before
|
162 |
|
|
a use can be created of it. */
|
163 |
|
|
unsigned needs_insertion : 1;
|
164 |
|
|
} *vn_ssa_aux_t;
|
165 |
|
|
|
166 |
|
|
/* Return the value numbering info for an SSA_NAME. */
|
167 |
|
|
extern vn_ssa_aux_t VN_INFO (tree);
|
168 |
|
|
extern vn_ssa_aux_t VN_INFO_GET (tree);
|
169 |
|
|
tree vn_get_expr_for (tree);
|
170 |
|
|
bool run_scc_vn (bool);
|
171 |
|
|
void free_scc_vn (void);
|
172 |
|
|
tree vn_nary_op_lookup (tree, vn_nary_op_t *);
|
173 |
|
|
tree vn_nary_op_lookup_stmt (gimple, vn_nary_op_t *);
|
174 |
|
|
tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
|
175 |
|
|
tree, tree, tree, tree, tree,
|
176 |
|
|
vn_nary_op_t *);
|
177 |
|
|
vn_nary_op_t vn_nary_op_insert (tree, tree);
|
178 |
|
|
vn_nary_op_t vn_nary_op_insert_stmt (gimple, tree);
|
179 |
|
|
vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
|
180 |
|
|
tree, tree, tree, tree,
|
181 |
|
|
tree, tree, unsigned int);
|
182 |
|
|
void vn_reference_fold_indirect (VEC (vn_reference_op_s, heap) **,
|
183 |
|
|
unsigned int *);
|
184 |
|
|
void copy_reference_ops_from_ref (tree, VEC(vn_reference_op_s, heap) **);
|
185 |
|
|
void copy_reference_ops_from_call (gimple, VEC(vn_reference_op_s, heap) **);
|
186 |
|
|
bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
|
187 |
|
|
VEC (vn_reference_op_s, heap) *);
|
188 |
|
|
tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
|
189 |
|
|
VEC (vn_reference_op_s, heap) *,
|
190 |
|
|
vn_reference_t *, bool);
|
191 |
|
|
tree vn_reference_lookup (tree, tree, bool, vn_reference_t *);
|
192 |
|
|
vn_reference_t vn_reference_insert (tree, tree, tree);
|
193 |
|
|
vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
|
194 |
|
|
VEC (vn_reference_op_s, heap) *,
|
195 |
|
|
tree, unsigned int);
|
196 |
|
|
|
197 |
|
|
hashval_t vn_nary_op_compute_hash (const vn_nary_op_t);
|
198 |
|
|
int vn_nary_op_eq (const void *, const void *);
|
199 |
|
|
bool vn_nary_may_trap (vn_nary_op_t);
|
200 |
|
|
hashval_t vn_reference_compute_hash (const vn_reference_t);
|
201 |
|
|
int vn_reference_eq (const void *, const void *);
|
202 |
|
|
unsigned int get_max_value_id (void);
|
203 |
|
|
unsigned int get_next_value_id (void);
|
204 |
|
|
unsigned int get_constant_value_id (tree);
|
205 |
|
|
unsigned int get_or_alloc_constant_value_id (tree);
|
206 |
|
|
bool value_id_constant_p (unsigned int);
|
207 |
|
|
#endif /* TREE_SSA_SCCVN_H */
|