annotate src/share/vm/opto/phaseX.hpp @ 9126:bc26f978b0ce

HotSpotResolvedObjectType: implement hasFinalizeSubclass() correctly don't use the (wrong) cached value, but ask the runtime on each request. Fixes regression on xml.* benchmarks @ specjvm2008. The problem was: After the constructor of Object was deoptimized due to an assumption violation, it was recompiled again after some time. However, on recompilation, the value of hasFinalizeSubclass for the class was not updated and it was compiled again with a, now wrong, assumption, which then triggers deoptimization again. This was repeated until it hit the recompilation limit (defined by PerMethodRecompilationCutoff), and therefore only executed by the interpreter from now on, causing the performance regression.
author Bernhard Urban <bernhard.urban@jku.at>
date Mon, 15 Apr 2013 19:54:58 +0200
parents d092d1b31229
children b2ee5dc63353
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 6272
diff changeset
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1489
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
25 #ifndef SHARE_VM_OPTO_PHASEX_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
26 #define SHARE_VM_OPTO_PHASEX_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
28 #include "libadt/dict.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
29 #include "libadt/vectset.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
30 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
31 #include "opto/memnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
32 #include "opto/node.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
33 #include "opto/phase.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
34 #include "opto/type.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
35
0
a61af66fc99e Initial load
duke
parents:
diff changeset
36 class Compile;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 class ConINode;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 class ConLNode;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 class Node;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 class Type;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class PhaseTransform;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class PhaseGVN;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 class PhaseIterGVN;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 class PhaseCCP;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 class PhasePeephole;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 class PhaseRegAlloc;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 //-----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Expandable closed hash-table of nodes, initialized to NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // Note that the constructor just zeros things
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Storage is reclaimed when the Arena's lifetime is over.
a61af66fc99e Initial load
duke
parents:
diff changeset
53 class NodeHash : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
55 Arena *_a; // Arena to allocate in
a61af66fc99e Initial load
duke
parents:
diff changeset
56 uint _max; // Size of table (power of 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
57 uint _inserts; // For grow and debug, count of hash_inserts
a61af66fc99e Initial load
duke
parents:
diff changeset
58 uint _insert_limit; // 'grow' when _inserts reaches _insert_limit
a61af66fc99e Initial load
duke
parents:
diff changeset
59 Node **_table; // Hash table of Node pointers
a61af66fc99e Initial load
duke
parents:
diff changeset
60 Node *_sentinel; // Replaces deleted entries in hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
63 NodeHash(uint est_max_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 NodeHash(Arena *arena, uint est_max_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 NodeHash(NodeHash *use_this_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
67 ~NodeHash(); // Unlock all nodes upon destruction of table.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 void operator=(const NodeHash&); // Unlock all nodes upon replacement of table.
a61af66fc99e Initial load
duke
parents:
diff changeset
69 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
70 Node *hash_find(const Node*);// Find an equivalent version in hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
71 Node *hash_find_insert(Node*);// If not in table insert else return found node
a61af66fc99e Initial load
duke
parents:
diff changeset
72 void hash_insert(Node*); // Insert into hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
73 bool hash_delete(const Node*);// Replace with _sentinel in hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void check_grow() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 _inserts++;
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if( _inserts == _insert_limit ) { grow(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 assert( _inserts <= _insert_limit, "hash table overflow");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 assert( _inserts < _max, "hash table overflow" );
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 static uint round_up(uint); // Round up to nearest power of 2
a61af66fc99e Initial load
duke
parents:
diff changeset
81 void grow(); // Grow _table to next power of 2 and rehash
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // Return 75% of _max, rounded up.
a61af66fc99e Initial load
duke
parents:
diff changeset
83 uint insert_limit() const { return _max - (_max>>2); }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void clear(); // Set all entries to NULL, keep storage.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Size of hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
87 uint size() const { return _max; }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 // Return Node* at index in table
a61af66fc99e Initial load
duke
parents:
diff changeset
89 Node *at(uint table_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 assert(table_index < _max, "Must be within table");
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return _table[table_index];
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 void remove_useless_nodes(VectorSet &useful); // replace with sentinel
7473
d092d1b31229 8005071: Incremental inlining for JSR 292
roland
parents: 6853
diff changeset
95 void replace_with(NodeHash* nh);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 Node *sentinel() { return _sentinel; }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
100 Node *find_index(uint idx); // For debugging
a61af66fc99e Initial load
duke
parents:
diff changeset
101 void dump(); // For debugging, dump statistics
a61af66fc99e Initial load
duke
parents:
diff changeset
102 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
103 uint _grows; // For debugging, count of table grow()s
a61af66fc99e Initial load
duke
parents:
diff changeset
104 uint _look_probes; // For debugging, count of hash probes
a61af66fc99e Initial load
duke
parents:
diff changeset
105 uint _lookup_hits; // For debugging, count of hash_finds
a61af66fc99e Initial load
duke
parents:
diff changeset
106 uint _lookup_misses; // For debugging, count of hash_finds
a61af66fc99e Initial load
duke
parents:
diff changeset
107 uint _insert_probes; // For debugging, count of hash probes
a61af66fc99e Initial load
duke
parents:
diff changeset
108 uint _delete_probes; // For debugging, count of hash probes for deletes
a61af66fc99e Initial load
duke
parents:
diff changeset
109 uint _delete_hits; // For debugging, count of hash probes for deletes
a61af66fc99e Initial load
duke
parents:
diff changeset
110 uint _delete_misses; // For debugging, count of hash probes for deletes
a61af66fc99e Initial load
duke
parents:
diff changeset
111 uint _total_inserts; // For debugging, total inserts into hash table
a61af66fc99e Initial load
duke
parents:
diff changeset
112 uint _total_insert_probes; // For debugging, total probes while inserting
a61af66fc99e Initial load
duke
parents:
diff changeset
113 };
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 //-----------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
117 // Map dense integer indices to Types. Uses classic doubling-array trick.
a61af66fc99e Initial load
duke
parents:
diff changeset
118 // Abstractly provides an infinite array of Type*'s, initialized to NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Note that the constructor just zeros things, and since I use Arena
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // allocation I do not need a destructor to reclaim storage.
a61af66fc99e Initial load
duke
parents:
diff changeset
121 // Despite the general name, this class is customized for use by PhaseTransform.
a61af66fc99e Initial load
duke
parents:
diff changeset
122 class Type_Array : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 Arena *_a; // Arena to allocate in
a61af66fc99e Initial load
duke
parents:
diff changeset
124 uint _max;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 const Type **_types;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void grow( uint i ); // Grow array node to fit
a61af66fc99e Initial load
duke
parents:
diff changeset
127 const Type *operator[] ( uint i ) const // Lookup, or NULL for not mapped
a61af66fc99e Initial load
duke
parents:
diff changeset
128 { return (i<_max) ? _types[i] : (Type*)NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
129 friend class PhaseTransform;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
131 Type_Array(Arena *a) : _a(a), _max(0), _types(0) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
132 Type_Array(Type_Array *ta) : _a(ta->_a), _max(ta->_max), _types(ta->_types) { }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 const Type *fast_lookup(uint i) const{assert(i<_max,"oob");return _types[i];}
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Extend the mapping: index i maps to Type *n.
a61af66fc99e Initial load
duke
parents:
diff changeset
135 void map( uint i, const Type *n ) { if( i>=_max ) grow(i); _types[i] = n; }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 uint Size() const { return _max; }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
138 void dump() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
140 };
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 //------------------------------PhaseRemoveUseless-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
144 // Remove useless nodes from GVN hash-table, worklist, and graph
a61af66fc99e Initial load
duke
parents:
diff changeset
145 class PhaseRemoveUseless : public Phase {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
147 Unique_Node_List _useful; // Nodes reachable from root
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // list is allocated from current resource area
a61af66fc99e Initial load
duke
parents:
diff changeset
149 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
150 PhaseRemoveUseless( PhaseGVN *gvn, Unique_Node_List *worklist );
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 Unique_Node_List *get_useful() { return &_useful; }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 };
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 //------------------------------PhaseTransform---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // Phases that analyze, then transform. Constructing the Phase object does any
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // global or slow analysis. The results are cached later for a fast
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // transformation pass. When the Phase object is deleted the cached analysis
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // results are deleted.
a61af66fc99e Initial load
duke
parents:
diff changeset
161 class PhaseTransform : public Phase {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
163 Arena* _arena;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 Node_Array _nodes; // Map old node indices to new nodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
165 Type_Array _types; // Map old node indices to Types.
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // ConNode caches:
a61af66fc99e Initial load
duke
parents:
diff changeset
168 enum { _icon_min = -1 * HeapWordSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
169 _icon_max = 16 * HeapWordSize,
a61af66fc99e Initial load
duke
parents:
diff changeset
170 _lcon_min = _icon_min,
a61af66fc99e Initial load
duke
parents:
diff changeset
171 _lcon_max = _icon_max,
a61af66fc99e Initial load
duke
parents:
diff changeset
172 _zcon_max = (uint)T_CONFLICT
a61af66fc99e Initial load
duke
parents:
diff changeset
173 };
a61af66fc99e Initial load
duke
parents:
diff changeset
174 ConINode* _icons[_icon_max - _icon_min + 1]; // cached jint constant nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
175 ConLNode* _lcons[_lcon_max - _lcon_min + 1]; // cached jlong constant nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
176 ConNode* _zcons[_zcon_max + 1]; // cached is_zero_type nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
177 void init_con_caches();
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // Support both int and long caches because either might be an intptr_t,
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // so they show up frequently in address computations.
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
183 PhaseTransform( PhaseNumber pnum );
a61af66fc99e Initial load
duke
parents:
diff changeset
184 PhaseTransform( Arena *arena, PhaseNumber pnum );
a61af66fc99e Initial load
duke
parents:
diff changeset
185 PhaseTransform( PhaseTransform *phase, PhaseNumber pnum );
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 Arena* arena() { return _arena; }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 Type_Array& types() { return _types; }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // _nodes is used in varying ways by subclasses, which define local accessors
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // Get a previously recorded type for the node n.
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // This type must already have been recorded.
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // If you want the type of a very new (untransformed) node,
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // you must use type_or_null, and test the result for NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
196 const Type* type(const Node* n) const {
6266
1d7922586cf6 7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents: 6144
diff changeset
197 assert(n != NULL, "must not be null");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
198 const Type* t = _types.fast_lookup(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 assert(t != NULL, "must set before get");
a61af66fc99e Initial load
duke
parents:
diff changeset
200 return t;
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // Get a previously recorded type for the node n,
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // or else return NULL if there is none.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 const Type* type_or_null(const Node* n) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
205 return _types.fast_lookup(n->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // Record a type for a node.
a61af66fc99e Initial load
duke
parents:
diff changeset
208 void set_type(const Node* n, const Type *t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert(t != NULL, "type must not be null");
a61af66fc99e Initial load
duke
parents:
diff changeset
210 _types.map(n->_idx, t);
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // Record an initial type for a node, the node's bottom type.
a61af66fc99e Initial load
duke
parents:
diff changeset
213 void set_type_bottom(const Node* n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Use this for initialization when bottom_type() (or better) is not handy.
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // Usually the initialization shoudl be to n->Value(this) instead,
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // or a hand-optimized value like Type::MEMORY or Type::CONTROL.
a61af66fc99e Initial load
duke
parents:
diff changeset
217 assert(_types[n->_idx] == NULL, "must set the initial type just once");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 _types.map(n->_idx, n->bottom_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 // Make sure the types array is big enough to record a size for the node n.
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // (In product builds, we never want to do range checks on the types array!)
a61af66fc99e Initial load
duke
parents:
diff changeset
222 void ensure_type_or_null(const Node* n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
223 if (n->_idx >= _types.Size())
a61af66fc99e Initial load
duke
parents:
diff changeset
224 _types.map(n->_idx, NULL); // Grow the types array as needed.
a61af66fc99e Initial load
duke
parents:
diff changeset
225 }
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // Utility functions:
a61af66fc99e Initial load
duke
parents:
diff changeset
228 const TypeInt* find_int_type( Node* n);
a61af66fc99e Initial load
duke
parents:
diff changeset
229 const TypeLong* find_long_type(Node* n);
a61af66fc99e Initial load
duke
parents:
diff changeset
230 jint find_int_con( Node* n, jint value_if_unknown) {
a61af66fc99e Initial load
duke
parents:
diff changeset
231 const TypeInt* t = find_int_type(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
232 return (t != NULL && t->is_con()) ? t->get_con() : value_if_unknown;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
234 jlong find_long_con(Node* n, jlong value_if_unknown) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 const TypeLong* t = find_long_type(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 return (t != NULL && t->is_con()) ? t->get_con() : value_if_unknown;
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // Make an idealized constant, i.e., one of ConINode, ConPNode, ConFNode, etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // Same as transform(ConNode::make(t)).
a61af66fc99e Initial load
duke
parents:
diff changeset
241 ConNode* makecon(const Type* t);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 virtual ConNode* uncached_makecon(const Type* t) // override in PhaseValues
a61af66fc99e Initial load
duke
parents:
diff changeset
243 { ShouldNotCallThis(); return NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // Fast int or long constant. Same as TypeInt::make(i) or TypeLong::make(l).
a61af66fc99e Initial load
duke
parents:
diff changeset
246 ConINode* intcon(jint i);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 ConLNode* longcon(jlong l);
a61af66fc99e Initial load
duke
parents:
diff changeset
248
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // Fast zero or null constant. Same as makecon(Type::get_zero_type(bt)).
a61af66fc99e Initial load
duke
parents:
diff changeset
250 ConNode* zerocon(BasicType bt);
a61af66fc99e Initial load
duke
parents:
diff changeset
251
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // Return a node which computes the same function as this node, but
a61af66fc99e Initial load
duke
parents:
diff changeset
253 // in a faster or cheaper fashion.
a61af66fc99e Initial load
duke
parents:
diff changeset
254 virtual Node *transform( Node *n ) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
255
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // Return whether two Nodes are equivalent.
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // Must not be recursive, since the recursive version is built from this.
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // For pessimistic optimizations this is simply pointer equivalence.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 bool eqv(const Node* n1, const Node* n2) const { return n1 == n2; }
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // For pessimistic passes, the return type must monotonically narrow.
a61af66fc99e Initial load
duke
parents:
diff changeset
262 // For optimistic passes, the return type must monotonically widen.
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // It is possible to get into a "death march" in either type of pass,
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // where the types are continually moving but it will take 2**31 or
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // more steps to converge. This doesn't happen on most normal loops.
a61af66fc99e Initial load
duke
parents:
diff changeset
266 //
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // Here is an example of a deadly loop for an optimistic pass, along
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // with a partial trace of inferred types:
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // x = phi(0,x'); L: x' = x+1; if (x' >= 0) goto L;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // 0 1 join([0..max], 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // [0..1] [1..2] join([0..max], [1..2])
a61af66fc99e Initial load
duke
parents:
diff changeset
272 // [0..2] [1..3] join([0..max], [1..3])
a61af66fc99e Initial load
duke
parents:
diff changeset
273 // ... ... ...
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // [0..max] [min]u[1..max] join([0..max], [min..max])
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // [0..max] ==> fixpoint
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // We would have proven, the hard way, that the iteration space is all
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // non-negative ints, with the loop terminating due to 32-bit overflow.
a61af66fc99e Initial load
duke
parents:
diff changeset
278 //
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // Here is the corresponding example for a pessimistic pass:
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // x = phi(0,x'); L: x' = x-1; if (x' >= 0) goto L;
a61af66fc99e Initial load
duke
parents:
diff changeset
281 // int int join([0..max], int)
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // [0..max] [-1..max-1] join([0..max], [-1..max-1])
a61af66fc99e Initial load
duke
parents:
diff changeset
283 // [0..max-1] [-1..max-2] join([0..max], [-1..max-2])
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // ... ... ...
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // [0..1] [-1..0] join([0..max], [-1..0])
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // 0 -1 join([0..max], -1)
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // 0 == fixpoint
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // We would have proven, the hard way, that the iteration space is {0}.
a61af66fc99e Initial load
duke
parents:
diff changeset
289 // (Usually, other optimizations will make the "if (x >= 0)" fold up
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // before we get into trouble. But not always.)
a61af66fc99e Initial load
duke
parents:
diff changeset
291 //
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // It's a pleasant thing to observe that the pessimistic pass
a61af66fc99e Initial load
duke
parents:
diff changeset
293 // will make short work of the optimistic pass's deadly loop,
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // and vice versa. That is a good example of the complementary
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // purposes of the CCP (optimistic) vs. GVN (pessimistic) phases.
a61af66fc99e Initial load
duke
parents:
diff changeset
296 //
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // In any case, only widen or narrow a few times before going to the
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // correct flavor of top or bottom.
a61af66fc99e Initial load
duke
parents:
diff changeset
299 //
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // This call only needs to be made once as the data flows around any
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // given cycle. We do it at Phis, and nowhere else.
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // The types presented are the new type of a phi (computed by PhiNode::Value)
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // and the previously computed type, last time the phi was visited.
a61af66fc99e Initial load
duke
parents:
diff changeset
304 //
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // The third argument is upper limit for the saturated value,
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // if the phase wishes to widen the new_type.
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // If the phase is narrowing, the old type provides a lower limit.
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // Caller guarantees that old_type and new_type are no higher than limit_type.
a61af66fc99e Initial load
duke
parents:
diff changeset
309 virtual const Type* saturate(const Type* new_type, const Type* old_type,
a61af66fc99e Initial load
duke
parents:
diff changeset
310 const Type* limit_type) const
a61af66fc99e Initial load
duke
parents:
diff changeset
311 { ShouldNotCallThis(); return NULL; }
a61af66fc99e Initial load
duke
parents:
diff changeset
312
a61af66fc99e Initial load
duke
parents:
diff changeset
313 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
314 void dump_old2new_map() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
315 void dump_new( uint new_lidx ) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
316 void dump_types() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
317 void dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl = true);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 void dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited);
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 uint _count_progress; // For profiling, count transforms that make progress
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1080
diff changeset
321 void set_progress() { ++_count_progress; assert( allow_progress(),"No progress allowed during verification"); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
322 void clear_progress() { _count_progress = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
323 uint made_progress() const { return _count_progress; }
a61af66fc99e Initial load
duke
parents:
diff changeset
324
a61af66fc99e Initial load
duke
parents:
diff changeset
325 uint _count_transforms; // For profiling, count transforms performed
a61af66fc99e Initial load
duke
parents:
diff changeset
326 void set_transforms() { ++_count_transforms; }
a61af66fc99e Initial load
duke
parents:
diff changeset
327 void clear_transforms() { _count_transforms = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
328 uint made_transforms() const{ return _count_transforms; }
a61af66fc99e Initial load
duke
parents:
diff changeset
329
a61af66fc99e Initial load
duke
parents:
diff changeset
330 bool _allow_progress; // progress not allowed during verification pass
a61af66fc99e Initial load
duke
parents:
diff changeset
331 void set_allow_progress(bool allow) { _allow_progress = allow; }
a61af66fc99e Initial load
duke
parents:
diff changeset
332 bool allow_progress() { return _allow_progress; }
a61af66fc99e Initial load
duke
parents:
diff changeset
333 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
334 };
a61af66fc99e Initial load
duke
parents:
diff changeset
335
a61af66fc99e Initial load
duke
parents:
diff changeset
336 //------------------------------PhaseValues------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // Phase infrastructure to support values
a61af66fc99e Initial load
duke
parents:
diff changeset
338 class PhaseValues : public PhaseTransform {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
340 NodeHash _table; // Hash table for value-numbering
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
343 PhaseValues( Arena *arena, uint est_max_size );
a61af66fc99e Initial load
duke
parents:
diff changeset
344 PhaseValues( PhaseValues *pt );
a61af66fc99e Initial load
duke
parents:
diff changeset
345 PhaseValues( PhaseValues *ptv, const char *dummy );
a61af66fc99e Initial load
duke
parents:
diff changeset
346 NOT_PRODUCT( ~PhaseValues(); )
a61af66fc99e Initial load
duke
parents:
diff changeset
347 virtual PhaseIterGVN *is_IterGVN() { return 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 // Some Ideal and other transforms delete --> modify --> insert values
a61af66fc99e Initial load
duke
parents:
diff changeset
350 bool hash_delete(Node *n) { return _table.hash_delete(n); }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 void hash_insert(Node *n) { _table.hash_insert(n); }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 Node *hash_find_insert(Node *n){ return _table.hash_find_insert(n); }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 Node *hash_find(const Node *n) { return _table.hash_find(n); }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 // Used after parsing to eliminate values that are no longer in program
1080
7c57aead6d3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 948
diff changeset
356 void remove_useless_nodes(VectorSet &useful) {
7c57aead6d3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 948
diff changeset
357 _table.remove_useless_nodes(useful);
7c57aead6d3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 948
diff changeset
358 // this may invalidate cached cons so reset the cache
7c57aead6d3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 948
diff changeset
359 init_con_caches();
7c57aead6d3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 948
diff changeset
360 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 virtual ConNode* uncached_makecon(const Type* t); // override from PhaseTransform
a61af66fc99e Initial load
duke
parents:
diff changeset
363
a61af66fc99e Initial load
duke
parents:
diff changeset
364 virtual const Type* saturate(const Type* new_type, const Type* old_type,
a61af66fc99e Initial load
duke
parents:
diff changeset
365 const Type* limit_type) const
a61af66fc99e Initial load
duke
parents:
diff changeset
366 { return new_type; }
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
369 uint _count_new_values; // For profiling, count new values produced
a61af66fc99e Initial load
duke
parents:
diff changeset
370 void inc_new_values() { ++_count_new_values; }
a61af66fc99e Initial load
duke
parents:
diff changeset
371 void clear_new_values() { _count_new_values = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
372 uint made_new_values() const { return _count_new_values; }
a61af66fc99e Initial load
duke
parents:
diff changeset
373 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
374 };
a61af66fc99e Initial load
duke
parents:
diff changeset
375
a61af66fc99e Initial load
duke
parents:
diff changeset
376
a61af66fc99e Initial load
duke
parents:
diff changeset
377 //------------------------------PhaseGVN---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
378 // Phase for performing local, pessimistic GVN-style optimizations.
a61af66fc99e Initial load
duke
parents:
diff changeset
379 class PhaseGVN : public PhaseValues {
a61af66fc99e Initial load
duke
parents:
diff changeset
380 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
381 PhaseGVN( Arena *arena, uint est_max_size ) : PhaseValues( arena, est_max_size ) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
382 PhaseGVN( PhaseGVN *gvn ) : PhaseValues( gvn ) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
383 PhaseGVN( PhaseGVN *gvn, const char *dummy ) : PhaseValues( gvn, dummy ) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
384
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // Return a node which computes the same function as this node, but
a61af66fc99e Initial load
duke
parents:
diff changeset
386 // in a faster or cheaper fashion.
a61af66fc99e Initial load
duke
parents:
diff changeset
387 Node *transform( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
388 Node *transform_no_reclaim( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
389
7473
d092d1b31229 8005071: Incremental inlining for JSR 292
roland
parents: 6853
diff changeset
390 void replace_with(PhaseGVN* gvn) {
d092d1b31229 8005071: Incremental inlining for JSR 292
roland
parents: 6853
diff changeset
391 _table.replace_with(&gvn->_table);
d092d1b31229 8005071: Incremental inlining for JSR 292
roland
parents: 6853
diff changeset
392 _types = gvn->_types;
d092d1b31229 8005071: Incremental inlining for JSR 292
roland
parents: 6853
diff changeset
393 }
d092d1b31229 8005071: Incremental inlining for JSR 292
roland
parents: 6853
diff changeset
394
0
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // Check for a simple dead loop when a data node references itself.
a61af66fc99e Initial load
duke
parents:
diff changeset
396 DEBUG_ONLY(void dead_loop_check(Node *n);)
a61af66fc99e Initial load
duke
parents:
diff changeset
397 };
a61af66fc99e Initial load
duke
parents:
diff changeset
398
a61af66fc99e Initial load
duke
parents:
diff changeset
399 //------------------------------PhaseIterGVN-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // Phase for iteratively performing local, pessimistic GVN-style optimizations.
a61af66fc99e Initial load
duke
parents:
diff changeset
401 // and ideal transformations on the graph.
a61af66fc99e Initial load
duke
parents:
diff changeset
402 class PhaseIterGVN : public PhaseGVN {
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
403 private:
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
404 bool _delay_transform; // When true simply register the node when calling transform
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
405 // instead of actually optimizing it
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
406
0
a61af66fc99e Initial load
duke
parents:
diff changeset
407 // Idealize old Node 'n' with respect to its inputs and its value
a61af66fc99e Initial load
duke
parents:
diff changeset
408 virtual Node *transform_old( Node *a_node );
1621
6027dddc26c6 6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents: 1552
diff changeset
409
6027dddc26c6 6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents: 1552
diff changeset
410 // Subsume users of node 'old' into node 'nn'
6027dddc26c6 6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents: 1552
diff changeset
411 void subsume_node( Node *old, Node *nn );
6027dddc26c6 6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents: 1552
diff changeset
412
6244
611e8a669a2c 7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents: 6144
diff changeset
413 Node_Stack _stack; // Stack used to avoid recursion
611e8a669a2c 7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents: 6144
diff changeset
414
0
a61af66fc99e Initial load
duke
parents:
diff changeset
415 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // Idealize new Node 'n' with respect to its inputs and its value
a61af66fc99e Initial load
duke
parents:
diff changeset
418 virtual Node *transform( Node *a_node );
a61af66fc99e Initial load
duke
parents:
diff changeset
419
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // Warm up hash table, type table and initial worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
421 void init_worklist( Node *a_root );
a61af66fc99e Initial load
duke
parents:
diff changeset
422
a61af66fc99e Initial load
duke
parents:
diff changeset
423 virtual const Type* saturate(const Type* new_type, const Type* old_type,
a61af66fc99e Initial load
duke
parents:
diff changeset
424 const Type* limit_type) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
425 // Usually returns new_type. Returns old_type if new_type is only a slight
a61af66fc99e Initial load
duke
parents:
diff changeset
426 // improvement, such that it would take many (>>10) steps to reach 2**32.
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
429 PhaseIterGVN( PhaseIterGVN *igvn ); // Used by CCP constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
430 PhaseIterGVN( PhaseGVN *gvn ); // Used after Parser
a61af66fc99e Initial load
duke
parents:
diff changeset
431 PhaseIterGVN( PhaseIterGVN *igvn, const char *dummy ); // Used after +VerifyOpto
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 virtual PhaseIterGVN *is_IterGVN() { return this; }
a61af66fc99e Initial load
duke
parents:
diff changeset
434
a61af66fc99e Initial load
duke
parents:
diff changeset
435 Unique_Node_List _worklist; // Iterative worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
436
a61af66fc99e Initial load
duke
parents:
diff changeset
437 // Given def-use info and an initial worklist, apply Node::Ideal,
a61af66fc99e Initial load
duke
parents:
diff changeset
438 // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU
a61af66fc99e Initial load
duke
parents:
diff changeset
439 // and dominator info to a fixed point.
a61af66fc99e Initial load
duke
parents:
diff changeset
440 void optimize();
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 // Register a new node with the iter GVN pass without transforming it.
a61af66fc99e Initial load
duke
parents:
diff changeset
443 // Used when we need to restructure a Region/Phi area and all the Regions
a61af66fc99e Initial load
duke
parents:
diff changeset
444 // and Phis need to complete this one big transform before any other
a61af66fc99e Initial load
duke
parents:
diff changeset
445 // transforms can be triggered on the region.
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // Optional 'orig' is an earlier version of this node.
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // It is significant only for debugging and profiling.
a61af66fc99e Initial load
duke
parents:
diff changeset
448 Node* register_new_node_with_optimizer(Node* n, Node* orig = NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
449
6244
611e8a669a2c 7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents: 6144
diff changeset
450 // Kill a globally dead Node. All uses are also globally dead and are
611e8a669a2c 7147464: Java crashed while executing method with over 8k of dneg operations
dlong
parents: 6144
diff changeset
451 // aggressively trimmed.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
452 void remove_globally_dead_node( Node *dead );
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 // Kill all inputs to a dead node, recursively making more dead nodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // The Node must be dead locally, i.e., have no uses.
a61af66fc99e Initial load
duke
parents:
diff changeset
456 void remove_dead_node( Node *dead ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead");
a61af66fc99e Initial load
duke
parents:
diff changeset
458 remove_globally_dead_node(dead);
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // Add users of 'n' to worklist
a61af66fc99e Initial load
duke
parents:
diff changeset
462 void add_users_to_worklist0( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
463 void add_users_to_worklist ( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
464
73
a8880a78d355 6259129: (Escape Analysis) scalar replacement for not escaping objects
kvn
parents: 0
diff changeset
465 // Replace old node with new one.
a8880a78d355 6259129: (Escape Analysis) scalar replacement for not escaping objects
kvn
parents: 0
diff changeset
466 void replace_node( Node *old, Node *nn ) {
a8880a78d355 6259129: (Escape Analysis) scalar replacement for not escaping objects
kvn
parents: 0
diff changeset
467 add_users_to_worklist(old);
1621
6027dddc26c6 6677629: PhaseIterGVN::subsume_node() should call hash_delete() and add_users_to_worklist()
kvn
parents: 1552
diff changeset
468 hash_delete(old); // Yank from hash before hacking edges
73
a8880a78d355 6259129: (Escape Analysis) scalar replacement for not escaping objects
kvn
parents: 0
diff changeset
469 subsume_node(old, nn);
a8880a78d355 6259129: (Escape Analysis) scalar replacement for not escaping objects
kvn
parents: 0
diff changeset
470 }
a8880a78d355 6259129: (Escape Analysis) scalar replacement for not escaping objects
kvn
parents: 0
diff changeset
471
6144
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
472 // Delayed node rehash: remove a node from the hash table and rehash it during
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
473 // next optimizing pass
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
474 void rehash_node_delayed(Node* n) {
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
475 hash_delete(n);
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
476 _worklist.push(n);
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
477 }
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
478
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
479 // Replace ith edge of "n" with "in"
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
480 void replace_input_of(Node* n, int i, Node* in) {
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
481 rehash_node_delayed(n);
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
482 n->set_req(i, in);
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
483 }
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
484
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
485 // Delete ith edge of "n"
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
486 void delete_input_of(Node* n, int i) {
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
487 rehash_node_delayed(n);
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
488 n->del_req(i);
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
489 }
5e990493719e 7173340: C2: code cleanup: use PhaseIterGVN::replace_edge(Node*, int, Node*) where applicable
kvn
parents: 4778
diff changeset
490
851
fc4be448891f 6851742: (EA) allocation elimination doesn't work with UseG1GC
kvn
parents: 196
diff changeset
491 bool delay_transform() const { return _delay_transform; }
fc4be448891f 6851742: (EA) allocation elimination doesn't work with UseG1GC
kvn
parents: 196
diff changeset
492
113
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
493 void set_delay_transform(bool delay) {
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
494 _delay_transform = delay;
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
495 }
ba764ed4b6f2 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 73
diff changeset
496
2445
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
497 // Clone loop predicates. Defined in loopTransform.cpp.
3345
bad7ecd0b6ed 5091921: Sign flip issues in loop optimizer
kvn
parents: 2445
diff changeset
498 Node* clone_loop_predicates(Node* old_entry, Node* new_entry, bool clone_limit_check);
2445
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
499 // Create a new if below new_entry for the predicate to be cloned
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
500 ProjNode* create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
501 Deoptimization::DeoptReason reason);
08eb13460b3a 7004535: Clone loop predicate during loop unswitch
kvn
parents: 1972
diff changeset
502
0
a61af66fc99e Initial load
duke
parents:
diff changeset
503 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
504 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // Sub-quadratic implementation of VerifyIterativeGVN.
6846
377508648226 8000313: C2 should use jlong for 64bit values
vlivanov
parents: 6272
diff changeset
506 julong _verify_counter;
377508648226 8000313: C2 should use jlong for 64bit values
vlivanov
parents: 6272
diff changeset
507 julong _verify_full_passes;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
508 enum { _verify_window_size = 30 };
a61af66fc99e Initial load
duke
parents:
diff changeset
509 Node* _verify_window[_verify_window_size];
a61af66fc99e Initial load
duke
parents:
diff changeset
510 void verify_step(Node* n);
a61af66fc99e Initial load
duke
parents:
diff changeset
511 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
512 };
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 //------------------------------PhaseCCP---------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
515 // Phase for performing global Conditional Constant Propagation.
a61af66fc99e Initial load
duke
parents:
diff changeset
516 // Should be replaced with combined CCP & GVN someday.
a61af66fc99e Initial load
duke
parents:
diff changeset
517 class PhaseCCP : public PhaseIterGVN {
a61af66fc99e Initial load
duke
parents:
diff changeset
518 // Non-recursive. Use analysis to transform single Node.
a61af66fc99e Initial load
duke
parents:
diff changeset
519 virtual Node *transform_once( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
522 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
a61af66fc99e Initial load
duke
parents:
diff changeset
523 NOT_PRODUCT( ~PhaseCCP(); )
a61af66fc99e Initial load
duke
parents:
diff changeset
524
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // Worklist algorithm identifies constants
a61af66fc99e Initial load
duke
parents:
diff changeset
526 void analyze();
a61af66fc99e Initial load
duke
parents:
diff changeset
527 // Recursive traversal of program. Used analysis to modify program.
a61af66fc99e Initial load
duke
parents:
diff changeset
528 virtual Node *transform( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // Do any transformation after analysis
a61af66fc99e Initial load
duke
parents:
diff changeset
530 void do_transform();
a61af66fc99e Initial load
duke
parents:
diff changeset
531
a61af66fc99e Initial load
duke
parents:
diff changeset
532 virtual const Type* saturate(const Type* new_type, const Type* old_type,
a61af66fc99e Initial load
duke
parents:
diff changeset
533 const Type* limit_type) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // Returns new_type->widen(old_type), which increments the widen bits until
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // giving up with TypeInt::INT or TypeLong::LONG.
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // Result is clipped to limit_type if necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
539 static uint _total_invokes; // For profiling, count invocations
a61af66fc99e Initial load
duke
parents:
diff changeset
540 void inc_invokes() { ++PhaseCCP::_total_invokes; }
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 static uint _total_constants; // For profiling, count constants found
a61af66fc99e Initial load
duke
parents:
diff changeset
543 uint _count_constants;
a61af66fc99e Initial load
duke
parents:
diff changeset
544 void clear_constants() { _count_constants = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
545 void inc_constants() { ++_count_constants; }
a61af66fc99e Initial load
duke
parents:
diff changeset
546 uint count_constants() const { return _count_constants; }
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 static void print_statistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
549 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
550 };
a61af66fc99e Initial load
duke
parents:
diff changeset
551
a61af66fc99e Initial load
duke
parents:
diff changeset
552
a61af66fc99e Initial load
duke
parents:
diff changeset
553 //------------------------------PhasePeephole----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // Phase for performing peephole optimizations on register allocated basic blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
555 class PhasePeephole : public PhaseTransform {
a61af66fc99e Initial load
duke
parents:
diff changeset
556 PhaseRegAlloc *_regalloc;
a61af66fc99e Initial load
duke
parents:
diff changeset
557 PhaseCFG &_cfg;
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // Recursive traversal of program. Pure function is unused in this phase
a61af66fc99e Initial load
duke
parents:
diff changeset
559 virtual Node *transform( Node *n );
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
562 PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg );
a61af66fc99e Initial load
duke
parents:
diff changeset
563 NOT_PRODUCT( ~PhasePeephole(); )
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 // Do any transformation after analysis
a61af66fc99e Initial load
duke
parents:
diff changeset
566 void do_transform();
a61af66fc99e Initial load
duke
parents:
diff changeset
567
a61af66fc99e Initial load
duke
parents:
diff changeset
568 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
569 static uint _total_peepholes; // For profiling, count peephole rules applied
a61af66fc99e Initial load
duke
parents:
diff changeset
570 uint _count_peepholes;
a61af66fc99e Initial load
duke
parents:
diff changeset
571 void clear_peepholes() { _count_peepholes = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
572 void inc_peepholes() { ++_count_peepholes; }
a61af66fc99e Initial load
duke
parents:
diff changeset
573 uint count_peepholes() const { return _count_peepholes; }
a61af66fc99e Initial load
duke
parents:
diff changeset
574
a61af66fc99e Initial load
duke
parents:
diff changeset
575 static void print_statistics();
a61af66fc99e Initial load
duke
parents:
diff changeset
576 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
577 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
578
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1621
diff changeset
579 #endif // SHARE_VM_OPTO_PHASEX_HPP