GCC Middle and Back End API Reference
tree-ssa-sccvn.h
Go to the documentation of this file.
1 /* Tree SCC value numbering
2  Copyright (C) 2007-2013 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 */
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;
45  tree op[1];
46 } *vn_nary_op_t;
47 typedef const struct vn_nary_op_s *const_vn_nary_op_t;
48 
49 /* Return the size of a vn_nary_op_t with LENGTH operands. */
50 
51 static inline size_t
52 sizeof_vn_nary_op (unsigned int length)
53 {
54  return sizeof (struct vn_nary_op_s) + sizeof (tree) * length - sizeof (tree);
55 }
56 
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 
63 typedef 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;
72 } *vn_phi_t;
73 typedef const struct vn_phi_s *const_vn_phi_t;
74 
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. */
80 
81 typedef struct vn_reference_op_struct
82 {
84  /* Constant offset this op adds or -1 if it is variable. */
93 
94 
95 /* A reference operation in the hashtable is representation as
96  the vuse, representing the memory state at the time of
97  the operation, and a collection of operands that make up the
98  addressing calculation. If two vn_reference_t's have the same set
99  of operands, they access the same memory location. We also store
100  the resulting value number, and the hashcode. */
101 
102 typedef struct vn_reference_s
103 {
104  /* Unique identifier that all expressions with the same value have. */
105  unsigned int value_id;
106  hashval_t hashcode;
113 } *vn_reference_t;
114 typedef const struct vn_reference_s *const_vn_reference_t;
115 
116 typedef struct vn_constant_s
117 {
118  unsigned int value_id;
119  hashval_t hashcode;
121 } *vn_constant_t;
122 
125 
126 /* Hash the type TYPE using bits that distinguishes it in the
127  types_compatible_p sense. */
128 
129 static inline hashval_t
131 {
132  return (INTEGRAL_TYPE_P (type)
133  + (INTEGRAL_TYPE_P (type)
134  ? TYPE_PRECISION (type) + TYPE_UNSIGNED (type) : 0));
135 }
136 
137 /* Hash the constant CONSTANT with distinguishing type incompatible
138  constants in the types_compatible_p sense. */
139 
140 static inline hashval_t
142 {
143  return (iterative_hash_expr (constant, 0)
144  + vn_hash_type (TREE_TYPE (constant)));
145 }
146 
147 /* Compare the constants C1 and C2 with distinguishing type incompatible
148  constants in the types_compatible_p sense. */
149 
150 static inline bool
152 {
153  return (expressions_equal_p (c1, c2)
154  && types_compatible_p (TREE_TYPE (c1), TREE_TYPE (c2)));
155 }
156 
157 typedef struct vn_ssa_aux
158 {
159  /* Value number. This may be an SSA name or a constant. */
161  /* Representative expression, if not a direct constant. */
163 
164  /* Unique identifier that all expressions with the same value have. */
165  unsigned int value_id;
166 
167  /* SCC information. */
168  unsigned int dfsnum;
169  unsigned int low;
170  unsigned visited : 1;
171  unsigned on_sccstack : 1;
172 
173  /* Whether the representative expression contains constants. */
174  unsigned has_constants : 1;
175  /* Whether the SSA_NAME has been value numbered already. This is
176  only saying whether visit_use has been called on it at least
177  once. It cannot be used to avoid visitation for SSA_NAME's
178  involved in non-singleton SCC's. */
179  unsigned use_processed : 1;
180 
181  /* Whether the SSA_NAME has no defining statement and thus an
182  insertion of such with EXPR as definition is required before
183  a use can be created of it. */
184  unsigned needs_insertion : 1;
185 } *vn_ssa_aux_t;
186 
188 
189 /* Return the value numbering info for an SSA_NAME. */
190 extern vn_ssa_aux_t VN_INFO (tree);
191 extern vn_ssa_aux_t VN_INFO_GET (tree);
194 void free_scc_vn (void);
197 tree vn_nary_op_lookup_pieces (unsigned int, enum tree_code,
198  tree, tree *, vn_nary_op_t *);
202  tree, tree *, tree, unsigned int);
204  unsigned int *);
216  tree, unsigned int);
217 
218 hashval_t vn_nary_op_compute_hash (const vn_nary_op_t);
219 bool vn_nary_op_eq (const_vn_nary_op_t const vno1,
220  const_vn_nary_op_t const vno2);
222 hashval_t vn_reference_compute_hash (const vn_reference_t);
224 unsigned int get_max_value_id (void);
225 unsigned int get_next_value_id (void);
226 unsigned int get_constant_value_id (tree);
227 unsigned int get_or_alloc_constant_value_id (tree);
228 bool value_id_constant_p (unsigned int);
230 
231 /* Valueize NAME if it is an SSA name, otherwise just return it. */
232 
233 static inline tree
235 {
236  if (TREE_CODE (name) == SSA_NAME)
237  {
238  tree tem = VN_INFO (name)->valnum;
239  return tem == VN_TOP ? name : tem;
240  }
241  return name;
242 }
243 
244 #endif /* TREE_SSA_SCCVN_H */