1 /* 2 * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_OPTO_PHASEX_HPP 26 #define SHARE_OPTO_PHASEX_HPP 27 28 #include "libadt/dict.hpp" 29 #include "libadt/vectset.hpp" 30 #include "memory/resourceArea.hpp" 31 #include "opto/memnode.hpp" 32 #include "opto/node.hpp" 33 #include "opto/phase.hpp" 34 #include "opto/type.hpp" 35 36 class BarrierSetC2; 37 class Compile; 38 class ConINode; 39 class ConLNode; 40 class Node; 41 class Type; 42 class PhaseTransform; 43 class PhaseGVN; 44 class PhaseIterGVN; 45 class PhaseCCP; 46 class PhasePeephole; 47 class PhaseRegAlloc; 48 49 50 //----------------------------------------------------------------------------- 51 // Expandable closed hash-table of nodes, initialized to null. 52 // Note that the constructor just zeros things 53 // Storage is reclaimed when the Arena's lifetime is over. 54 class NodeHash : public StackObj { 55 protected: 56 Arena *_a; // Arena to allocate in 57 uint _max; // Size of table (power of 2) 58 uint _inserts; // For grow and debug, count of hash_inserts 59 uint _insert_limit; // 'grow' when _inserts reaches _insert_limit 60 Node **_table; // Hash table of Node pointers 61 Node *_sentinel; // Replaces deleted entries in hash table 62 63 public: 64 NodeHash(uint est_max_size); 65 NodeHash(Arena *arena, uint est_max_size); 66 NodeHash(NodeHash *use_this_state); 67 #ifdef ASSERT 68 ~NodeHash(); // Unlock all nodes upon destruction of table. 69 void operator=(const NodeHash&); // Unlock all nodes upon replacement of table. 70 #endif 71 Node *hash_find(const Node*);// Find an equivalent version in hash table 72 Node *hash_find_insert(Node*);// If not in table insert else return found node 73 void hash_insert(Node*); // Insert into hash table 74 bool hash_delete(const Node*);// Replace with _sentinel in hash table 75 void check_grow() { 76 _inserts++; 77 if( _inserts == _insert_limit ) { grow(); } 78 assert( _inserts <= _insert_limit, "hash table overflow"); 79 assert( _inserts < _max, "hash table overflow" ); 80 } 81 static uint round_up(uint); // Round up to nearest power of 2 82 void grow(); // Grow _table to next power of 2 and rehash 83 // Return 75% of _max, rounded up. 84 uint insert_limit() const { return _max - (_max>>2); } 85 86 void clear(); // Set all entries to null, keep storage. 87 // Size of hash table 88 uint size() const { return _max; } 89 // Return Node* at index in table 90 Node *at(uint table_index) { 91 assert(table_index < _max, "Must be within table"); 92 return _table[table_index]; 93 } 94 95 void remove_useless_nodes(VectorSet& useful); // replace with sentinel 96 void replace_with(NodeHash* nh); 97 void check_no_speculative_types(); // Check no speculative part for type nodes in table 98 99 Node *sentinel() { return _sentinel; } 100 101 #ifndef PRODUCT 102 Node *find_index(uint idx); // For debugging 103 void dump(); // For debugging, dump statistics 104 uint _grows; // For debugging, count of table grow()s 105 uint _look_probes; // For debugging, count of hash probes 106 uint _lookup_hits; // For debugging, count of hash_finds 107 uint _lookup_misses; // For debugging, count of hash_finds 108 uint _insert_probes; // For debugging, count of hash probes 109 uint _delete_probes; // For debugging, count of hash probes for deletes 110 uint _delete_hits; // For debugging, count of hash probes for deletes 111 uint _delete_misses; // For debugging, count of hash probes for deletes 112 uint _total_inserts; // For debugging, total inserts into hash table 113 uint _total_insert_probes; // For debugging, total probes while inserting 114 #endif 115 }; 116 117 118 //----------------------------------------------------------------------------- 119 // Map dense integer indices to Types. Uses classic doubling-array trick. 120 // Abstractly provides an infinite array of Type*'s, initialized to null. 121 // Note that the constructor just zeros things, and since I use Arena 122 // allocation I do not need a destructor to reclaim storage. 123 // Despite the general name, this class is customized for use by PhaseTransform. 124 class Type_Array : public StackObj { 125 Arena *_a; // Arena to allocate in 126 uint _max; 127 const Type **_types; 128 void grow( uint i ); // Grow array node to fit 129 const Type *operator[] ( uint i ) const // Lookup, or null for not mapped 130 { return (i<_max) ? _types[i] : (Type*)nullptr; } 131 friend class PhaseTransform; 132 public: 133 Type_Array(Arena *a) : _a(a), _max(0), _types(0) {} 134 Type_Array(Type_Array *ta) : _a(ta->_a), _max(ta->_max), _types(ta->_types) { } 135 const Type *fast_lookup(uint i) const{assert(i<_max,"oob");return _types[i];} 136 // Extend the mapping: index i maps to Type *n. 137 void map( uint i, const Type *n ) { if( i>=_max ) grow(i); _types[i] = n; } 138 uint Size() const { return _max; } 139 #ifndef PRODUCT 140 void dump() const; 141 #endif 142 }; 143 144 145 //------------------------------PhaseRemoveUseless----------------------------- 146 // Remove useless nodes from GVN hash-table, worklist, and graph 147 class PhaseRemoveUseless : public Phase { 148 protected: 149 Unique_Node_List _useful; // Nodes reachable from root 150 // list is allocated from current resource area 151 public: 152 PhaseRemoveUseless(PhaseGVN *gvn, Unique_Node_List *worklist, PhaseNumber phase_num = Remove_Useless); 153 154 Unique_Node_List *get_useful() { return &_useful; } 155 }; 156 157 //------------------------------PhaseRenumber---------------------------------- 158 // Phase that first performs a PhaseRemoveUseless, then it renumbers compiler 159 // structures accordingly. 160 class PhaseRenumberLive : public PhaseRemoveUseless { 161 protected: 162 Type_Array _new_type_array; // Storage for the updated type information. 163 GrowableArray<int> _old2new_map; 164 Node_List _delayed; 165 bool _is_pass_finished; 166 uint _live_node_count; 167 168 int update_embedded_ids(Node* n); 169 int new_index(int old_idx); 170 171 public: 172 PhaseRenumberLive(PhaseGVN* gvn, 173 Unique_Node_List* worklist, Unique_Node_List* new_worklist, 174 PhaseNumber phase_num = Remove_Useless_And_Renumber_Live); 175 }; 176 177 178 //------------------------------PhaseTransform--------------------------------- 179 // Phases that analyze, then transform. Constructing the Phase object does any 180 // global or slow analysis. The results are cached later for a fast 181 // transformation pass. When the Phase object is deleted the cached analysis 182 // results are deleted. 183 class PhaseTransform : public Phase { 184 protected: 185 Arena* _arena; 186 Node_List _nodes; // Map old node indices to new nodes. 187 Type_Array _types; // Map old node indices to Types. 188 189 // ConNode caches: 190 enum { _icon_min = -1 * HeapWordSize, 191 _icon_max = 16 * HeapWordSize, 192 _lcon_min = _icon_min, 193 _lcon_max = _icon_max, 194 _zcon_max = (uint)T_CONFLICT 195 }; 196 ConINode* _icons[_icon_max - _icon_min + 1]; // cached jint constant nodes 197 ConLNode* _lcons[_lcon_max - _lcon_min + 1]; // cached jlong constant nodes 198 ConNode* _zcons[_zcon_max + 1]; // cached is_zero_type nodes 199 void init_con_caches(); 200 201 // Support both int and long caches because either might be an intptr_t, 202 // so they show up frequently in address computations. 203 204 public: 205 PhaseTransform( PhaseNumber pnum ); 206 PhaseTransform( Arena *arena, PhaseNumber pnum ); 207 PhaseTransform( PhaseTransform *phase, PhaseNumber pnum ); 208 209 Arena* arena() { return _arena; } 210 Type_Array& types() { return _types; } 211 void replace_types(Type_Array new_types) { 212 _types = new_types; 213 } 214 // _nodes is used in varying ways by subclasses, which define local accessors 215 uint nodes_size() { 216 return _nodes.size(); 217 } 218 219 public: 220 // Get a previously recorded type for the node n. 221 // This type must already have been recorded. 222 // If you want the type of a very new (untransformed) node, 223 // you must use type_or_null, and test the result for null. 224 const Type* type(const Node* n) const { 225 assert(_pnum != Ideal_Loop, "should not be used from PhaseIdealLoop"); 226 assert(n != nullptr, "must not be null"); 227 const Type* t = _types.fast_lookup(n->_idx); 228 assert(t != nullptr, "must set before get"); 229 return t; 230 } 231 // Get a previously recorded type for the node n, 232 // or else return null if there is none. 233 const Type* type_or_null(const Node* n) const { 234 assert(_pnum != Ideal_Loop, "should not be used from PhaseIdealLoop"); 235 return _types.fast_lookup(n->_idx); 236 } 237 // Record a type for a node. 238 void set_type(const Node* n, const Type *t) { 239 assert(t != nullptr, "type must not be null"); 240 _types.map(n->_idx, t); 241 } 242 void clear_type(const Node* n) { 243 if (n->_idx < _types.Size()) { 244 _types.map(n->_idx, nullptr); 245 } 246 } 247 // Record an initial type for a node, the node's bottom type. 248 void set_type_bottom(const Node* n) { 249 // Use this for initialization when bottom_type() (or better) is not handy. 250 // Usually the initialization should be to n->Value(this) instead, 251 // or a hand-optimized value like Type::MEMORY or Type::CONTROL. 252 assert(_types[n->_idx] == nullptr, "must set the initial type just once"); 253 _types.map(n->_idx, n->bottom_type()); 254 } 255 // Make sure the types array is big enough to record a size for the node n. 256 // (In product builds, we never want to do range checks on the types array!) 257 void ensure_type_or_null(const Node* n) { 258 if (n->_idx >= _types.Size()) 259 _types.map(n->_idx, nullptr); // Grow the types array as needed. 260 } 261 262 // Utility functions: 263 const TypeInt* find_int_type( Node* n); 264 const TypeLong* find_long_type(Node* n); 265 jint find_int_con( Node* n, jint value_if_unknown) { 266 const TypeInt* t = find_int_type(n); 267 return (t != nullptr && t->is_con()) ? t->get_con() : value_if_unknown; 268 } 269 jlong find_long_con(Node* n, jlong value_if_unknown) { 270 const TypeLong* t = find_long_type(n); 271 return (t != nullptr && t->is_con()) ? t->get_con() : value_if_unknown; 272 } 273 274 // Make an idealized constant, i.e., one of ConINode, ConPNode, ConFNode, etc. 275 // Same as transform(ConNode::make(t)). 276 ConNode* makecon(const Type* t); 277 virtual ConNode* uncached_makecon(const Type* t) // override in PhaseValues 278 { ShouldNotCallThis(); return nullptr; } 279 280 // Fast int or long constant. Same as TypeInt::make(i) or TypeLong::make(l). 281 ConINode* intcon(jint i); 282 ConLNode* longcon(jlong l); 283 ConNode* integercon(jlong l, BasicType bt); 284 285 // Fast zero or null constant. Same as makecon(Type::get_zero_type(bt)). 286 ConNode* zerocon(BasicType bt); 287 288 // Return a node which computes the same function as this node, but 289 // in a faster or cheaper fashion. 290 virtual Node *transform( Node *n ) = 0; 291 292 // For pessimistic passes, the return type must monotonically narrow. 293 // For optimistic passes, the return type must monotonically widen. 294 // It is possible to get into a "death march" in either type of pass, 295 // where the types are continually moving but it will take 2**31 or 296 // more steps to converge. This doesn't happen on most normal loops. 297 // 298 // Here is an example of a deadly loop for an optimistic pass, along 299 // with a partial trace of inferred types: 300 // x = phi(0,x'); L: x' = x+1; if (x' >= 0) goto L; 301 // 0 1 join([0..max], 1) 302 // [0..1] [1..2] join([0..max], [1..2]) 303 // [0..2] [1..3] join([0..max], [1..3]) 304 // ... ... ... 305 // [0..max] [min]u[1..max] join([0..max], [min..max]) 306 // [0..max] ==> fixpoint 307 // We would have proven, the hard way, that the iteration space is all 308 // non-negative ints, with the loop terminating due to 32-bit overflow. 309 // 310 // Here is the corresponding example for a pessimistic pass: 311 // x = phi(0,x'); L: x' = x-1; if (x' >= 0) goto L; 312 // int int join([0..max], int) 313 // [0..max] [-1..max-1] join([0..max], [-1..max-1]) 314 // [0..max-1] [-1..max-2] join([0..max], [-1..max-2]) 315 // ... ... ... 316 // [0..1] [-1..0] join([0..max], [-1..0]) 317 // 0 -1 join([0..max], -1) 318 // 0 == fixpoint 319 // We would have proven, the hard way, that the iteration space is {0}. 320 // (Usually, other optimizations will make the "if (x >= 0)" fold up 321 // before we get into trouble. But not always.) 322 // 323 // It's a pleasant thing to observe that the pessimistic pass 324 // will make short work of the optimistic pass's deadly loop, 325 // and vice versa. That is a good example of the complementary 326 // purposes of the CCP (optimistic) vs. GVN (pessimistic) phases. 327 // 328 // In any case, only widen or narrow a few times before going to the 329 // correct flavor of top or bottom. 330 // 331 // This call only needs to be made once as the data flows around any 332 // given cycle. We do it at Phis, and nowhere else. 333 // The types presented are the new type of a phi (computed by PhiNode::Value) 334 // and the previously computed type, last time the phi was visited. 335 // 336 // The third argument is upper limit for the saturated value, 337 // if the phase wishes to widen the new_type. 338 // If the phase is narrowing, the old type provides a lower limit. 339 // Caller guarantees that old_type and new_type are no higher than limit_type. 340 virtual const Type* saturate(const Type* new_type, const Type* old_type, 341 const Type* limit_type) const 342 { ShouldNotCallThis(); return nullptr; } 343 virtual const Type* saturate_and_maybe_push_to_igvn_worklist(const TypeNode* n, const Type* new_type) { 344 return saturate(new_type, type_or_null(n), n->type()); 345 } 346 347 // true if CFG node d dominates CFG node n 348 virtual bool is_dominator(Node *d, Node *n) { fatal("unimplemented for this pass"); return false; }; 349 350 #ifndef PRODUCT 351 void dump_old2new_map() const; 352 void dump_new( uint new_lidx ) const; 353 void dump_types() const; 354 void dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl = true); 355 void dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited); 356 357 uint _count_progress; // For profiling, count transforms that make progress 358 void set_progress() { ++_count_progress; assert( allow_progress(),"No progress allowed during verification"); } 359 void clear_progress() { _count_progress = 0; } 360 uint made_progress() const { return _count_progress; } 361 362 uint _count_transforms; // For profiling, count transforms performed 363 void set_transforms() { ++_count_transforms; } 364 void clear_transforms() { _count_transforms = 0; } 365 uint made_transforms() const{ return _count_transforms; } 366 367 bool _allow_progress; // progress not allowed during verification pass 368 void set_allow_progress(bool allow) { _allow_progress = allow; } 369 bool allow_progress() { return _allow_progress; } 370 #endif 371 }; 372 373 //------------------------------PhaseValues------------------------------------ 374 // Phase infrastructure to support values 375 class PhaseValues : public PhaseTransform { 376 protected: 377 NodeHash _table; // Hash table for value-numbering 378 bool _iterGVN; 379 public: 380 PhaseValues(Arena* arena, uint est_max_size); 381 PhaseValues(PhaseValues* pt); 382 NOT_PRODUCT(~PhaseValues();) 383 PhaseIterGVN* is_IterGVN() { return (_iterGVN) ? (PhaseIterGVN*)this : nullptr; } 384 385 // Some Ideal and other transforms delete --> modify --> insert values 386 bool hash_delete(Node* n) { return _table.hash_delete(n); } 387 void hash_insert(Node* n) { _table.hash_insert(n); } 388 Node* hash_find_insert(Node* n){ return _table.hash_find_insert(n); } 389 Node* hash_find(const Node* n) { return _table.hash_find(n); } 390 391 // Used after parsing to eliminate values that are no longer in program 392 void remove_useless_nodes(VectorSet &useful) { 393 _table.remove_useless_nodes(useful); 394 // this may invalidate cached cons so reset the cache 395 init_con_caches(); 396 } 397 398 virtual ConNode* uncached_makecon(const Type* t); // override from PhaseTransform 399 400 const Type* saturate(const Type* new_type, const Type* old_type, 401 const Type* limit_type) const 402 { return new_type; } 403 404 #ifndef PRODUCT 405 uint _count_new_values; // For profiling, count new values produced 406 void inc_new_values() { ++_count_new_values; } 407 void clear_new_values() { _count_new_values = 0; } 408 uint made_new_values() const { return _count_new_values; } 409 #endif 410 }; 411 412 413 //------------------------------PhaseGVN--------------------------------------- 414 // Phase for performing local, pessimistic GVN-style optimizations. 415 class PhaseGVN : public PhaseValues { 416 protected: 417 bool is_dominator_helper(Node *d, Node *n, bool linear_only); 418 419 public: 420 PhaseGVN( Arena *arena, uint est_max_size ) : PhaseValues( arena, est_max_size ) {} 421 PhaseGVN( PhaseGVN *gvn ) : PhaseValues( gvn ) {} 422 423 // Return a node which computes the same function as this node, but 424 // in a faster or cheaper fashion. 425 Node *transform( Node *n ); 426 Node *transform_no_reclaim( Node *n ); 427 virtual void record_for_igvn(Node *n) { 428 C->record_for_igvn(n); 429 } 430 431 void replace_with(PhaseGVN* gvn) { 432 _table.replace_with(&gvn->_table); 433 _types = gvn->_types; 434 } 435 436 bool is_dominator(Node *d, Node *n) { return is_dominator_helper(d, n, true); } 437 438 // Helper to call Node::Ideal() and BarrierSetC2::ideal_node(). 439 Node* apply_ideal(Node* i, bool can_reshape); 440 441 #ifdef ASSERT 442 void dump_infinite_loop_info(Node* n, const char* where); 443 // Check for a simple dead loop when a data node references itself. 444 void dead_loop_check(Node *n); 445 #endif 446 }; 447 448 //------------------------------PhaseIterGVN----------------------------------- 449 // Phase for iteratively performing local, pessimistic GVN-style optimizations. 450 // and ideal transformations on the graph. 451 class PhaseIterGVN : public PhaseGVN { 452 private: 453 bool _delay_transform; // When true simply register the node when calling transform 454 // instead of actually optimizing it 455 456 // Idealize old Node 'n' with respect to its inputs and its value 457 virtual Node *transform_old( Node *a_node ); 458 459 // Subsume users of node 'old' into node 'nn' 460 void subsume_node( Node *old, Node *nn ); 461 462 Node_Stack _stack; // Stack used to avoid recursion 463 protected: 464 465 // Shuffle worklist, for stress testing 466 void shuffle_worklist(); 467 468 virtual const Type* saturate(const Type* new_type, const Type* old_type, 469 const Type* limit_type) const; 470 // Usually returns new_type. Returns old_type if new_type is only a slight 471 // improvement, such that it would take many (>>10) steps to reach 2**32. 472 473 public: 474 PhaseIterGVN(PhaseIterGVN* igvn); // Used by CCP constructor 475 PhaseIterGVN(PhaseGVN* gvn); // Used after Parser 476 477 // Idealize new Node 'n' with respect to its inputs and its value 478 virtual Node *transform( Node *a_node ); 479 virtual void record_for_igvn(Node *n) { _worklist.push(n); } 480 481 Unique_Node_List _worklist; // Iterative worklist 482 483 // Given def-use info and an initial worklist, apply Node::Ideal, 484 // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU 485 // and dominator info to a fixed point. 486 void optimize(); 487 #ifdef ASSERT 488 void verify_optimize(); 489 bool verify_node_value(Node* n); 490 #endif 491 492 #ifndef PRODUCT 493 void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type); 494 void init_verifyPhaseIterGVN(); 495 void verify_PhaseIterGVN(); 496 #endif 497 498 #ifdef ASSERT 499 void dump_infinite_loop_info(Node* n, const char* where); 500 void trace_PhaseIterGVN_verbose(Node* n, int num_processed); 501 #endif 502 503 // Register a new node with the iter GVN pass without transforming it. 504 // Used when we need to restructure a Region/Phi area and all the Regions 505 // and Phis need to complete this one big transform before any other 506 // transforms can be triggered on the region. 507 // Optional 'orig' is an earlier version of this node. 508 // It is significant only for debugging and profiling. 509 Node* register_new_node_with_optimizer(Node* n, Node* orig = nullptr); 510 511 // Kill a globally dead Node. All uses are also globally dead and are 512 // aggressively trimmed. 513 void remove_globally_dead_node( Node *dead ); 514 515 // Kill all inputs to a dead node, recursively making more dead nodes. 516 // The Node must be dead locally, i.e., have no uses. 517 void remove_dead_node( Node *dead ) { 518 assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead"); 519 remove_globally_dead_node(dead); 520 } 521 522 // Add users of 'n' to worklist 523 void add_users_to_worklist0( Node *n ); 524 void add_users_to_worklist ( Node *n ); 525 526 // Replace old node with new one. 527 void replace_node( Node *old, Node *nn ) { 528 add_users_to_worklist(old); 529 hash_delete(old); // Yank from hash before hacking edges 530 subsume_node(old, nn); 531 } 532 533 void replace_in_uses(Node* n, Node* m); 534 535 // Delayed node rehash: remove a node from the hash table and rehash it during 536 // next optimizing pass 537 void rehash_node_delayed(Node* n) { 538 hash_delete(n); 539 _worklist.push(n); 540 } 541 542 // Replace ith edge of "n" with "in" 543 void replace_input_of(Node* n, int i, Node* in) { 544 rehash_node_delayed(n); 545 n->set_req_X(i, in, this); 546 } 547 548 // Add "in" as input (req) of "n" 549 void add_input_to(Node* n, Node* in) { 550 rehash_node_delayed(n); 551 n->add_req(in); 552 } 553 554 // Delete ith edge of "n" 555 void delete_input_of(Node* n, int i) { 556 rehash_node_delayed(n); 557 n->del_req(i); 558 } 559 560 // Delete precedence edge i of "n" 561 void delete_precedence_of(Node* n, int i) { 562 rehash_node_delayed(n); 563 n->rm_prec(i); 564 } 565 566 bool delay_transform() const { return _delay_transform; } 567 568 void set_delay_transform(bool delay) { 569 _delay_transform = delay; 570 } 571 572 void remove_speculative_types(); 573 void check_no_speculative_types() { 574 _table.check_no_speculative_types(); 575 } 576 577 bool is_dominator(Node *d, Node *n) { return is_dominator_helper(d, n, false); } 578 bool no_dependent_zero_check(Node* n) const; 579 580 #ifndef PRODUCT 581 static bool is_verify_def_use() { 582 // '-XX:VerifyIterativeGVN=1' 583 return (VerifyIterativeGVN % 10) == 1; 584 } 585 static bool is_verify_Value() { 586 // '-XX:VerifyIterativeGVN=10' 587 return ((VerifyIterativeGVN % 100) / 10) == 1; 588 } 589 protected: 590 // Sub-quadratic implementation of '-XX:VerifyIterativeGVN=1' (Use-Def verification). 591 julong _verify_counter; 592 julong _verify_full_passes; 593 enum { _verify_window_size = 30 }; 594 Node* _verify_window[_verify_window_size]; 595 void verify_step(Node* n); 596 #endif 597 }; 598 599 //------------------------------PhaseCCP--------------------------------------- 600 // Phase for performing global Conditional Constant Propagation. 601 // Should be replaced with combined CCP & GVN someday. 602 class PhaseCCP : public PhaseIterGVN { 603 Unique_Node_List _root_and_safepoints; 604 // Non-recursive. Use analysis to transform single Node. 605 virtual Node* transform_once(Node* n); 606 607 Node* fetch_next_node(Unique_Node_List& worklist); 608 static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN; 609 610 void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const; 611 void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const; 612 void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const; 613 void push_phis(Unique_Node_List& worklist, const Node* use) const; 614 static void push_catch(Unique_Node_List& worklist, const Node* use); 615 void push_cmpu(Unique_Node_List& worklist, const Node* use) const; 616 static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use); 617 static void push_cast(Unique_Node_List& worklist, const Node* use); 618 void push_loadp(Unique_Node_List& worklist, const Node* use) const; 619 static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use); 620 void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const; 621 void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const; 622 void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const; 623 624 public: 625 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants 626 NOT_PRODUCT( ~PhaseCCP(); ) 627 628 // Worklist algorithm identifies constants 629 void analyze(); 630 #ifdef ASSERT 631 void verify_type(Node* n, const Type* tnew, const Type* told); 632 // For every node n on verify list, check if type(n) == n->Value() 633 void verify_analyze(Unique_Node_List& worklist_verify); 634 #endif 635 // Recursive traversal of program. Used analysis to modify program. 636 virtual Node *transform( Node *n ); 637 // Do any transformation after analysis 638 void do_transform(); 639 640 virtual const Type* saturate(const Type* new_type, const Type* old_type, 641 const Type* limit_type) const; 642 // Returns new_type->widen(old_type), which increments the widen bits until 643 // giving up with TypeInt::INT or TypeLong::LONG. 644 // Result is clipped to limit_type if necessary. 645 virtual const Type* saturate_and_maybe_push_to_igvn_worklist(const TypeNode* n, const Type* new_type) { 646 const Type* t = saturate(new_type, type_or_null(n), n->type()); 647 if (t != new_type) { 648 // Type was widened in CCP, but IGVN may be able to make it narrower. 649 _worklist.push((Node*)n); 650 } 651 return t; 652 } 653 654 #ifndef PRODUCT 655 static uint _total_invokes; // For profiling, count invocations 656 void inc_invokes() { ++PhaseCCP::_total_invokes; } 657 658 static uint _total_constants; // For profiling, count constants found 659 uint _count_constants; 660 void clear_constants() { _count_constants = 0; } 661 void inc_constants() { ++_count_constants; } 662 uint count_constants() const { return _count_constants; } 663 664 static void print_statistics(); 665 #endif 666 }; 667 668 669 //------------------------------PhasePeephole---------------------------------- 670 // Phase for performing peephole optimizations on register allocated basic blocks. 671 class PhasePeephole : public PhaseTransform { 672 PhaseRegAlloc *_regalloc; 673 PhaseCFG &_cfg; 674 // Recursive traversal of program. Pure function is unused in this phase 675 virtual Node *transform( Node *n ); 676 677 public: 678 PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg ); 679 NOT_PRODUCT( ~PhasePeephole(); ) 680 681 // Do any transformation after analysis 682 void do_transform(); 683 684 #ifndef PRODUCT 685 static uint _total_peepholes; // For profiling, count peephole rules applied 686 uint _count_peepholes; 687 void clear_peepholes() { _count_peepholes = 0; } 688 void inc_peepholes() { ++_count_peepholes; } 689 uint count_peepholes() const { return _count_peepholes; } 690 691 static void print_statistics(); 692 #endif 693 }; 694 695 #endif // SHARE_OPTO_PHASEX_HPP