annotate gcc/tree-ssa-scopedtables.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Header file for SSA dominator optimizations.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2013-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #ifndef GCC_TREE_SSA_SCOPED_TABLES_H
kono
parents:
diff changeset
21 #define GCC_TREE_SSA_SCOPED_TABLES_H
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 /* Representation of a "naked" right-hand-side expression, to be used
kono
parents:
diff changeset
24 in recording available expressions in the expression hash table. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 enum expr_kind
kono
parents:
diff changeset
27 {
kono
parents:
diff changeset
28 EXPR_SINGLE,
kono
parents:
diff changeset
29 EXPR_UNARY,
kono
parents:
diff changeset
30 EXPR_BINARY,
kono
parents:
diff changeset
31 EXPR_TERNARY,
kono
parents:
diff changeset
32 EXPR_CALL,
kono
parents:
diff changeset
33 EXPR_PHI
kono
parents:
diff changeset
34 };
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 struct hashable_expr
kono
parents:
diff changeset
37 {
kono
parents:
diff changeset
38 tree type;
kono
parents:
diff changeset
39 enum expr_kind kind;
kono
parents:
diff changeset
40 union {
kono
parents:
diff changeset
41 struct { tree rhs; } single;
kono
parents:
diff changeset
42 struct { enum tree_code op; tree opnd; } unary;
kono
parents:
diff changeset
43 struct { enum tree_code op; tree opnd0, opnd1; } binary;
kono
parents:
diff changeset
44 struct { enum tree_code op; tree opnd0, opnd1, opnd2; } ternary;
kono
parents:
diff changeset
45 struct { gcall *fn_from; bool pure; size_t nargs; tree *args; } call;
kono
parents:
diff changeset
46 struct { size_t nargs; tree *args; } phi;
kono
parents:
diff changeset
47 } ops;
kono
parents:
diff changeset
48 };
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 /* Structure for recording known value of a conditional expression.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Clients build vectors of these objects to record known values
kono
parents:
diff changeset
53 that occur on edges. */
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 struct cond_equivalence
kono
parents:
diff changeset
56 {
kono
parents:
diff changeset
57 /* The condition, in a HASHABLE_EXPR form. */
kono
parents:
diff changeset
58 struct hashable_expr cond;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 /* The result of the condition (true or false. */
kono
parents:
diff changeset
61 tree value;
kono
parents:
diff changeset
62 };
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 /* Structure for entries in the expression hash table. */
kono
parents:
diff changeset
65
kono
parents:
diff changeset
66 typedef class expr_hash_elt * expr_hash_elt_t;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 class expr_hash_elt
kono
parents:
diff changeset
69 {
kono
parents:
diff changeset
70 public:
kono
parents:
diff changeset
71 expr_hash_elt (gimple *, tree);
kono
parents:
diff changeset
72 expr_hash_elt (tree);
kono
parents:
diff changeset
73 expr_hash_elt (struct hashable_expr *, tree);
kono
parents:
diff changeset
74 expr_hash_elt (class expr_hash_elt &);
kono
parents:
diff changeset
75 ~expr_hash_elt ();
kono
parents:
diff changeset
76 void print (FILE *);
kono
parents:
diff changeset
77 tree vop (void) { return m_vop; }
kono
parents:
diff changeset
78 tree lhs (void) { return m_lhs; }
kono
parents:
diff changeset
79 struct hashable_expr *expr (void) { return &m_expr; }
kono
parents:
diff changeset
80 expr_hash_elt *stamp (void) { return m_stamp; }
kono
parents:
diff changeset
81 hashval_t hash (void) { return m_hash; }
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 private:
kono
parents:
diff changeset
84 /* The expression (rhs) we want to record. */
kono
parents:
diff changeset
85 struct hashable_expr m_expr;
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /* The value (lhs) of this expression. */
kono
parents:
diff changeset
88 tree m_lhs;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 /* The virtual operand associated with the nearest dominating stmt
kono
parents:
diff changeset
91 loading from or storing to expr. */
kono
parents:
diff changeset
92 tree m_vop;
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 /* The hash value for RHS. */
kono
parents:
diff changeset
95 hashval_t m_hash;
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 /* A unique stamp, typically the address of the hash
kono
parents:
diff changeset
98 element itself, used in removing entries from the table. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
99 class expr_hash_elt *m_stamp;
111
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /* We should never be making assignments between objects in this class.
kono
parents:
diff changeset
102 Though it might allow us to exploit C++11 move semantics if we
kono
parents:
diff changeset
103 defined the move constructor and move assignment operator. */
kono
parents:
diff changeset
104 expr_hash_elt& operator= (const expr_hash_elt&);
kono
parents:
diff changeset
105 };
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 /* Hashtable helpers. */
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 struct expr_elt_hasher : pointer_hash <expr_hash_elt>
kono
parents:
diff changeset
110 {
kono
parents:
diff changeset
111 static inline hashval_t hash (const value_type &p)
kono
parents:
diff changeset
112 { return p->hash (); }
kono
parents:
diff changeset
113 static bool equal (const value_type &, const compare_type &);
kono
parents:
diff changeset
114 static inline void remove (value_type &element)
kono
parents:
diff changeset
115 { delete element; }
kono
parents:
diff changeset
116 };
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 /* This class defines a unwindable expression equivalence table
kono
parents:
diff changeset
120 layered on top of the expression hash table.
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 Essentially it's just a stack of available expression value pairs with
kono
parents:
diff changeset
123 a special marker (NULL, NULL) to indicate unwind points. */
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 class avail_exprs_stack
kono
parents:
diff changeset
126 {
kono
parents:
diff changeset
127 public:
kono
parents:
diff changeset
128 /* We need access to the AVAIL_EXPR hash table so that we can
kono
parents:
diff changeset
129 remove entries from the hash table when unwinding the stack. */
kono
parents:
diff changeset
130 avail_exprs_stack (hash_table<expr_elt_hasher> *table)
kono
parents:
diff changeset
131 { m_stack.create (20); m_avail_exprs = table; }
kono
parents:
diff changeset
132 ~avail_exprs_stack (void) { m_stack.release (); }
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 /* Push the unwinding marker onto the stack. */
kono
parents:
diff changeset
135 void push_marker (void) { record_expr (NULL, NULL, 'M'); }
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 /* Restore the AVAIL_EXPRs table to its state when the last marker
kono
parents:
diff changeset
138 was pushed. */
kono
parents:
diff changeset
139 void pop_to_marker (void);
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 /* Record a single available expression that can be unwound. */
kono
parents:
diff changeset
142 void record_expr (expr_hash_elt_t, expr_hash_elt_t, char);
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 /* Get the underlying hash table. Would this be better as
kono
parents:
diff changeset
145 class inheritance? */
kono
parents:
diff changeset
146 hash_table<expr_elt_hasher> *avail_exprs (void)
kono
parents:
diff changeset
147 { return m_avail_exprs; }
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /* Lookup and conditionally insert an expression into the table,
kono
parents:
diff changeset
150 recording enough information to unwind as needed. */
kono
parents:
diff changeset
151 tree lookup_avail_expr (gimple *, bool, bool);
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 void record_cond (cond_equivalence *);
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 private:
kono
parents:
diff changeset
156 vec<std::pair<expr_hash_elt_t, expr_hash_elt_t> > m_stack;
kono
parents:
diff changeset
157 hash_table<expr_elt_hasher> *m_avail_exprs;
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 /* For some assignments where the RHS is a binary operator, if we know
kono
parents:
diff changeset
160 a equality relationship between the operands, we may be able to compute
kono
parents:
diff changeset
161 a result, even if we don't know the exact value of the operands. */
kono
parents:
diff changeset
162 tree simplify_binary_operation (gimple *, class expr_hash_elt);
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 /* We do not allow copying this object or initializing one
kono
parents:
diff changeset
165 from another. */
kono
parents:
diff changeset
166 avail_exprs_stack& operator= (const avail_exprs_stack&);
kono
parents:
diff changeset
167 avail_exprs_stack (class avail_exprs_stack &);
kono
parents:
diff changeset
168 };
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 /* This class defines an unwindable const/copy equivalence table
kono
parents:
diff changeset
171 layered on top of SSA_NAME_VALUE/set_ssa_name_value.
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 Essentially it's just a stack of name,prev value pairs with a
kono
parents:
diff changeset
174 special marker (NULL) to indicate unwind points. */
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 class const_and_copies
kono
parents:
diff changeset
177 {
kono
parents:
diff changeset
178 public:
kono
parents:
diff changeset
179 const_and_copies (void) { m_stack.create (20); };
kono
parents:
diff changeset
180 ~const_and_copies (void) { m_stack.release (); }
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 /* Push the unwinding marker onto the stack. */
kono
parents:
diff changeset
183 void push_marker (void) { m_stack.safe_push (NULL_TREE); }
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 /* Restore the const/copies table to its state when the last marker
kono
parents:
diff changeset
186 was pushed. */
kono
parents:
diff changeset
187 void pop_to_marker (void);
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 /* Record a single const/copy pair that can be unwound. This version
kono
parents:
diff changeset
190 may follow the value chain for the RHS. */
kono
parents:
diff changeset
191 void record_const_or_copy (tree, tree);
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 /* Special entry point when we want to provide an explicit previous
kono
parents:
diff changeset
194 value for the first argument. Try to get rid of this in the future.
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 This version may also follow the value chain for the RHS. */
kono
parents:
diff changeset
197 void record_const_or_copy (tree, tree, tree);
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 private:
kono
parents:
diff changeset
200 /* Record a single const/copy pair that can be unwound. This version
kono
parents:
diff changeset
201 does not follow the value chain for the RHS. */
kono
parents:
diff changeset
202 void record_const_or_copy_raw (tree, tree, tree);
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 vec<tree> m_stack;
kono
parents:
diff changeset
205 const_and_copies& operator= (const const_and_copies&);
kono
parents:
diff changeset
206 const_and_copies (class const_and_copies &);
kono
parents:
diff changeset
207 };
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 void initialize_expr_from_cond (tree cond, struct hashable_expr *expr);
kono
parents:
diff changeset
210 void record_conditions (vec<cond_equivalence> *p, tree, tree);
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 #endif /* GCC_TREE_SSA_SCOPED_TABLES_H */