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