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