1 /* Header file for SSA dominator optimizations.
2 Copyright (C) 2013-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_TREE_SSA_SCOPED_TABLES_H
21 #define GCC_TREE_SSA_SCOPED_TABLES_H
23 /* Representation of a "naked" right-hand-side expression, to be used
24 in recording available expressions in the expression hash table. */
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
;
50 /* Structure for entries in the expression hash table. */
52 typedef class expr_hash_elt
* expr_hash_elt_t
;
57 expr_hash_elt (gimple
*, tree
);
59 expr_hash_elt (struct hashable_expr
*, tree
);
60 expr_hash_elt (class expr_hash_elt
&);
63 tree
vop (void) { return m_vop
; }
64 tree
lhs (void) { return m_lhs
; }
65 struct hashable_expr
*expr (void) { return &m_expr
; }
66 expr_hash_elt
*stamp (void) { return m_stamp
; }
67 hashval_t
hash (void) { return m_hash
; }
70 /* The expression (rhs) we want to record. */
71 struct hashable_expr m_expr
;
73 /* The value (lhs) of this expression. */
76 /* The virtual operand associated with the nearest dominating stmt
77 loading from or storing to expr. */
80 /* The hash value for RHS. */
83 /* A unique stamp, typically the address of the hash
84 element itself, used in removing entries from the table. */
85 struct expr_hash_elt
*m_stamp
;
87 /* We should never be making assignments between objects in this class.
88 Though it might allow us to exploit C++11 move semantics if we
89 defined the move constructor and move assignment operator. */
90 expr_hash_elt
& operator= (const expr_hash_elt
&);
93 /* Hashtable helpers. */
95 struct expr_elt_hasher
: pointer_hash
<expr_hash_elt
>
97 static inline hashval_t
hash (const value_type
&p
)
98 { return p
->hash (); }
99 static bool equal (const value_type
&, const compare_type
&);
100 static inline void remove (value_type
&element
)
105 /* This class defines a unwindable expression equivalence table
106 layered on top of the expression hash table.
108 Essentially it's just a stack of available expression value pairs with
109 a special marker (NULL, NULL) to indicate unwind points. */
111 class avail_exprs_stack
114 /* We need access to the AVAIL_EXPR hash table so that we can
115 remove entries from the hash table when unwinding the stack. */
116 avail_exprs_stack (hash_table
<expr_elt_hasher
> *table
)
117 { m_stack
.create (20); m_avail_exprs
= table
; }
118 ~avail_exprs_stack (void) { m_stack
.release (); }
120 /* Push the unwinding marker onto the stack. */
121 void push_marker (void) { record_expr (NULL
, NULL
, 'M'); }
123 /* Restore the AVAIL_EXPRs table to its state when the last marker
125 void pop_to_marker (void);
127 /* Record a single available expression that can be unwound. */
128 void record_expr (expr_hash_elt_t
, expr_hash_elt_t
, char);
130 /* Get the underlying hash table. Would this be better as
131 class inheritance? */
132 hash_table
<expr_elt_hasher
> *avail_exprs (void)
133 { return m_avail_exprs
; }
136 vec
<std::pair
<expr_hash_elt_t
, expr_hash_elt_t
> > m_stack
;
137 hash_table
<expr_elt_hasher
> *m_avail_exprs
;
139 /* We do not allow copying this object or initializing one
141 avail_exprs_stack
& operator= (const avail_exprs_stack
&);
142 avail_exprs_stack (class avail_exprs_stack
&);
145 /* This class defines an unwindable const/copy equivalence table
146 layered on top of SSA_NAME_VALUE/set_ssa_name_value.
148 Essentially it's just a stack of name,prev value pairs with a
149 special marker (NULL) to indicate unwind points. */
151 class const_and_copies
154 const_and_copies (void) { m_stack
.create (20); };
155 ~const_and_copies (void) { m_stack
.release (); }
157 /* Push the unwinding marker onto the stack. */
158 void push_marker (void) { m_stack
.safe_push (NULL_TREE
); }
160 /* Restore the const/copies table to its state when the last marker
162 void pop_to_marker (void);
164 /* Record a single const/copy pair that can be unwound. */
165 void record_const_or_copy (tree
, tree
);
167 /* Special entry point when we want to provide an explicit previous
168 value for the first argument. Try to get rid of this in the future. */
169 void record_const_or_copy (tree
, tree
, tree
);
173 const_and_copies
& operator= (const const_and_copies
&);
174 const_and_copies (class const_and_copies
&);
177 void initialize_expr_from_cond (tree cond
, struct hashable_expr
*expr
);
179 #endif /* GCC_TREE_SSA_SCOPED_TABLES_H */