]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-ssa-sccvn.h
Daily bump.
[thirdparty/gcc.git] / gcc / tree-ssa-sccvn.h
CommitLineData
89fb70a3 1/* Tree SCC value numbering
d652f226 2 Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
89fb70a3
DB
3 Contributed by Daniel Berlin <dberlin@dberlin.org>
4
9dcd6f09
NC
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/>. */
89fb70a3
DB
20
21#ifndef TREE_SSA_SCCVN_H
22#define TREE_SSA_SCCVN_H
23
b2ad0284
BRF
24/* In tree-ssa-sccvn.c */
25bool expressions_equal_p (tree, tree);
26
27
89fb70a3
DB
28/* TOP of the VN lattice. */
29extern tree VN_TOP;
30
c9145754
DB
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
36typedef 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;
5a7d7f9c 45 tree op[1];
c9145754
DB
46} *vn_nary_op_t;
47typedef const struct vn_nary_op_s *const_vn_nary_op_t;
48
5a7d7f9c
RG
49/* Return the size of a vn_nary_op_t with LENGTH operands. */
50
51static inline size_t
52sizeof_vn_nary_op (unsigned int length)
53{
91af9dc9 54 return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
5a7d7f9c
RG
55}
56
c9145754
DB
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. */
62
63typedef struct vn_phi_s
64{
65 /* Unique identifier that all expressions with the same value have. */
66 unsigned int value_id;
67 hashval_t hashcode;
68 VEC (tree, heap) *phiargs;
69 basic_block block;
70 tree result;
71} *vn_phi_t;
72typedef const struct vn_phi_s *const_vn_phi_t;
73
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. */
79
80typedef struct vn_reference_op_struct
81{
82 enum tree_code opcode;
70f34814
RG
83 /* Constant offset this op adds or -1 if it is variable. */
84 HOST_WIDE_INT off;
c9145754
DB
85 tree type;
86 tree op0;
87 tree op1;
88 tree op2;
89} vn_reference_op_s;
90typedef vn_reference_op_s *vn_reference_op_t;
91typedef const vn_reference_op_s *const_vn_reference_op_t;
92
93DEF_VEC_O(vn_reference_op_s);
94DEF_VEC_ALLOC_O(vn_reference_op_s, heap);
95
5006671f
RG
96/* A reference operation in the hashtable is representation as
97 the vuse, representing the memory state at the time of
c9145754
DB
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
5006671f 101 the resulting value number, and the hashcode. */
c9145754
DB
102
103typedef struct vn_reference_s
104{
105 /* Unique identifier that all expressions with the same value have. */
106 unsigned int value_id;
107 hashval_t hashcode;
5006671f 108 tree vuse;
b45d2719
RG
109 alias_set_type set;
110 tree type;
c9145754
DB
111 VEC (vn_reference_op_s, heap) *operands;
112 tree result;
00115921 113 tree result_vdef;
c9145754
DB
114} *vn_reference_t;
115typedef const struct vn_reference_s *const_vn_reference_t;
116
117typedef struct vn_constant_s
118{
119 unsigned int value_id;
120 hashval_t hashcode;
121 tree constant;
122} *vn_constant_t;
726a989a 123
17742d62
RG
124enum vn_kind { VN_NONE, VN_CONSTANT, VN_NARY, VN_REFERENCE, VN_PHI };
125enum vn_kind vn_get_stmt_kind (gimple);
126
726a989a
RB
127/* Hash the constant CONSTANT with distinguishing type incompatible
128 constants in the types_compatible_p sense. */
129
130static inline hashval_t
131vn_hash_constant_with_type (tree constant)
132{
133 tree type = TREE_TYPE (constant);
134 return (iterative_hash_expr (constant, 0)
135 + INTEGRAL_TYPE_P (type)
136 + (INTEGRAL_TYPE_P (type)
137 ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
138}
139
140/* Compare the constants C1 and C2 with distinguishing type incompatible
141 constants in the types_compatible_p sense. */
142
143static inline bool
144vn_constant_eq_with_type (tree c1, tree c2)
145{
146 return (expressions_equal_p (c1, c2)
147 && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
148}
149
89fb70a3
DB
150typedef struct vn_ssa_aux
151{
89fb70a3
DB
152 /* Value number. This may be an SSA name or a constant. */
153 tree valnum;
154 /* Representative expression, if not a direct constant. */
155 tree expr;
71ae8557 156
c9145754
DB
157 /* Unique identifier that all expressions with the same value have. */
158 unsigned int value_id;
159
71ae8557
SB
160 /* SCC information. */
161 unsigned int dfsnum;
162 unsigned int low;
163 unsigned visited : 1;
164 unsigned on_sccstack : 1;
165
89fb70a3 166 /* Whether the representative expression contains constants. */
71ae8557 167 unsigned has_constants : 1;
89fb70a3
DB
168 /* Whether the SSA_NAME has been value numbered already. This is
169 only saying whether visit_use has been called on it at least
170 once. It cannot be used to avoid visitation for SSA_NAME's
171 involved in non-singleton SCC's. */
71ae8557 172 unsigned use_processed : 1;
3d45dd59
RG
173
174 /* Whether the SSA_NAME has no defining statement and thus an
175 insertion of such with EXPR as definition is required before
176 a use can be created of it. */
177 unsigned needs_insertion : 1;
89fb70a3
DB
178} *vn_ssa_aux_t;
179
1ec87690
RG
180typedef enum { VN_NOWALK, VN_WALK, VN_WALKREWRITE } vn_lookup_kind;
181
89fb70a3
DB
182/* Return the value numbering info for an SSA_NAME. */
183extern vn_ssa_aux_t VN_INFO (tree);
184extern vn_ssa_aux_t VN_INFO_GET (tree);
726a989a 185tree vn_get_expr_for (tree);
1ec87690 186bool run_scc_vn (vn_lookup_kind);
89fb70a3 187void free_scc_vn (void);
c9145754 188tree vn_nary_op_lookup (tree, vn_nary_op_t *);
726a989a 189tree vn_nary_op_lookup_stmt (gimple, vn_nary_op_t *);
c9145754 190tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
5a7d7f9c 191 tree, tree *, vn_nary_op_t *);
c9145754 192vn_nary_op_t vn_nary_op_insert (tree, tree);
726a989a 193vn_nary_op_t vn_nary_op_insert_stmt (gimple, tree);
c9145754 194vn_nary_op_t vn_nary_op_insert_pieces (unsigned int, enum tree_code,
5a7d7f9c 195 tree, tree *, tree, unsigned int);
aa7069aa
RG
196void vn_reference_fold_indirect (VEC (vn_reference_op_s, heap) **,
197 unsigned int *);
ce94d354 198void copy_reference_ops_from_ref (tree, VEC(vn_reference_op_s, heap) **);
726a989a 199void copy_reference_ops_from_call (gimple, VEC(vn_reference_op_s, heap) **);
b45d2719
RG
200bool ao_ref_init_from_vn_reference (ao_ref *, alias_set_type, tree,
201 VEC (vn_reference_op_s, heap) *);
202tree vn_reference_lookup_pieces (tree, alias_set_type, tree,
c9145754 203 VEC (vn_reference_op_s, heap) *,
3bc27de7
RG
204 vn_reference_t *, vn_lookup_kind);
205tree vn_reference_lookup (tree, tree, vn_lookup_kind, vn_reference_t *);
4ec0a198 206vn_reference_t vn_reference_insert (tree, tree, tree, tree);
b45d2719 207vn_reference_t vn_reference_insert_pieces (tree, alias_set_type, tree,
c9145754
DB
208 VEC (vn_reference_op_s, heap) *,
209 tree, unsigned int);
210
211hashval_t vn_nary_op_compute_hash (const vn_nary_op_t);
212int vn_nary_op_eq (const void *, const void *);
890065bf 213bool vn_nary_may_trap (vn_nary_op_t);
c9145754
DB
214hashval_t vn_reference_compute_hash (const vn_reference_t);
215int vn_reference_eq (const void *, const void *);
216unsigned int get_max_value_id (void);
217unsigned int get_next_value_id (void);
bb9e4199 218unsigned int get_constant_value_id (tree);
c9145754
DB
219unsigned int get_or_alloc_constant_value_id (tree);
220bool value_id_constant_p (unsigned int);
12bd5a1e 221tree fully_constant_vn_reference_p (vn_reference_t);
c9e93168
TV
222
223/* Valueize NAME if it is an SSA name, otherwise just return it. */
224
225static inline tree
226vn_valueize (tree name)
227{
228 if (TREE_CODE (name) == SSA_NAME)
229 {
230 tree tem = VN_INFO (name)->valnum;
231 return tem == VN_TOP ? name : tem;
232 }
233 return name;
234}
235
89fb70a3 236#endif /* TREE_SSA_SCCVN_H */