1 /*
  2  * Copyright (c) 1997, 2021, 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*)NULL; }
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 != NULL, "must not be null");
227     const Type* t = _types.fast_lookup(n->_idx);
228     assert(t != NULL, "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 != NULL, "type must not be null");
240     _types.map(n->_idx, t);
241   }
242   // Record an initial type for a node, the node's bottom type.
243   void    set_type_bottom(const Node* n) {
244     // Use this for initialization when bottom_type() (or better) is not handy.
245     // Usually the initialization should be to n->Value(this) instead,
246     // or a hand-optimized value like Type::MEMORY or Type::CONTROL.
247     assert(_types[n->_idx] == NULL, "must set the initial type just once");
248     _types.map(n->_idx, n->bottom_type());
249   }
250   // Make sure the types array is big enough to record a size for the node n.
251   // (In product builds, we never want to do range checks on the types array!)
252   void ensure_type_or_null(const Node* n) {
253     if (n->_idx >= _types.Size())
254       _types.map(n->_idx, NULL);   // Grow the types array as needed.
255   }
256 
257   // Utility functions:
258   const TypeInt*  find_int_type( Node* n);
259   const TypeLong* find_long_type(Node* n);
260   jint  find_int_con( Node* n, jint  value_if_unknown) {
261     const TypeInt* t = find_int_type(n);
262     return (t != NULL && t->is_con()) ? t->get_con() : value_if_unknown;
263   }
264   jlong find_long_con(Node* n, jlong value_if_unknown) {
265     const TypeLong* t = find_long_type(n);
266     return (t != NULL && t->is_con()) ? t->get_con() : value_if_unknown;
267   }
268 
269   // Make an idealized constant, i.e., one of ConINode, ConPNode, ConFNode, etc.
270   // Same as transform(ConNode::make(t)).
271   ConNode* makecon(const Type* t);
272   virtual ConNode* uncached_makecon(const Type* t)  // override in PhaseValues
273   { ShouldNotCallThis(); return NULL; }
274 
275   // Fast int or long constant.  Same as TypeInt::make(i) or TypeLong::make(l).
276   ConINode* intcon(jint i);
277   ConLNode* longcon(jlong l);
278   ConNode* integercon(jlong l, BasicType bt);
279 
280   // Fast zero or null constant.  Same as makecon(Type::get_zero_type(bt)).
281   ConNode* zerocon(BasicType bt);
282 
283   // Return a node which computes the same function as this node, but
284   // in a faster or cheaper fashion.
285   virtual Node *transform( Node *n ) = 0;
286 
287   // For pessimistic passes, the return type must monotonically narrow.
288   // For optimistic  passes, the return type must monotonically widen.
289   // It is possible to get into a "death march" in either type of pass,
290   // where the types are continually moving but it will take 2**31 or
291   // more steps to converge.  This doesn't happen on most normal loops.
292   //
293   // Here is an example of a deadly loop for an optimistic pass, along
294   // with a partial trace of inferred types:
295   //    x = phi(0,x'); L: x' = x+1; if (x' >= 0) goto L;
296   //    0                 1                join([0..max], 1)
297   //    [0..1]            [1..2]           join([0..max], [1..2])
298   //    [0..2]            [1..3]           join([0..max], [1..3])
299   //      ... ... ...
300   //    [0..max]          [min]u[1..max]   join([0..max], [min..max])
301   //    [0..max] ==> fixpoint
302   // We would have proven, the hard way, that the iteration space is all
303   // non-negative ints, with the loop terminating due to 32-bit overflow.
304   //
305   // Here is the corresponding example for a pessimistic pass:
306   //    x = phi(0,x'); L: x' = x-1; if (x' >= 0) goto L;
307   //    int               int              join([0..max], int)
308   //    [0..max]          [-1..max-1]      join([0..max], [-1..max-1])
309   //    [0..max-1]        [-1..max-2]      join([0..max], [-1..max-2])
310   //      ... ... ...
311   //    [0..1]            [-1..0]          join([0..max], [-1..0])
312   //    0                 -1               join([0..max], -1)
313   //    0 == fixpoint
314   // We would have proven, the hard way, that the iteration space is {0}.
315   // (Usually, other optimizations will make the "if (x >= 0)" fold up
316   // before we get into trouble.  But not always.)
317   //
318   // It's a pleasant thing to observe that the pessimistic pass
319   // will make short work of the optimistic pass's deadly loop,
320   // and vice versa.  That is a good example of the complementary
321   // purposes of the CCP (optimistic) vs. GVN (pessimistic) phases.
322   //
323   // In any case, only widen or narrow a few times before going to the
324   // correct flavor of top or bottom.
325   //
326   // This call only needs to be made once as the data flows around any
327   // given cycle.  We do it at Phis, and nowhere else.
328   // The types presented are the new type of a phi (computed by PhiNode::Value)
329   // and the previously computed type, last time the phi was visited.
330   //
331   // The third argument is upper limit for the saturated value,
332   // if the phase wishes to widen the new_type.
333   // If the phase is narrowing, the old type provides a lower limit.
334   // Caller guarantees that old_type and new_type are no higher than limit_type.
335   virtual const Type* saturate(const Type* new_type, const Type* old_type,
336                                const Type* limit_type) const
337   { ShouldNotCallThis(); return NULL; }
338 
339   // true if CFG node d dominates CFG node n
340   virtual bool is_dominator(Node *d, Node *n) { fatal("unimplemented for this pass"); return false; };
341 
342 #ifndef PRODUCT
343   void dump_old2new_map() const;
344   void dump_new( uint new_lidx ) const;
345   void dump_types() const;
346   void dump_nodes_and_types(const Node *root, uint depth, bool only_ctrl = true);
347   void dump_nodes_and_types_recur( const Node *n, uint depth, bool only_ctrl, VectorSet &visited);
348 
349   uint   _count_progress;       // For profiling, count transforms that make progress
350   void   set_progress()        { ++_count_progress; assert( allow_progress(),"No progress allowed during verification"); }
351   void   clear_progress()      { _count_progress = 0; }
352   uint   made_progress() const { return _count_progress; }
353 
354   uint   _count_transforms;     // For profiling, count transforms performed
355   void   set_transforms()      { ++_count_transforms; }
356   void   clear_transforms()    { _count_transforms = 0; }
357   uint   made_transforms() const{ return _count_transforms; }
358 
359   bool   _allow_progress;      // progress not allowed during verification pass
360   void   set_allow_progress(bool allow) { _allow_progress = allow; }
361   bool   allow_progress()               { return _allow_progress; }
362 #endif
363 };
364 
365 //------------------------------PhaseValues------------------------------------
366 // Phase infrastructure to support values
367 class PhaseValues : public PhaseTransform {
368 protected:
369   NodeHash  _table;             // Hash table for value-numbering
370   bool      _iterGVN;
371 public:
372   PhaseValues(Arena* arena, uint est_max_size);
373   PhaseValues(PhaseValues* pt);
374   NOT_PRODUCT(~PhaseValues();)
375   PhaseIterGVN* is_IterGVN() { return (_iterGVN) ? (PhaseIterGVN*)this : NULL; }
376 
377   // Some Ideal and other transforms delete --> modify --> insert values
378   bool   hash_delete(Node* n)     { return _table.hash_delete(n); }
379   void   hash_insert(Node* n)     { _table.hash_insert(n); }
380   Node*  hash_find_insert(Node* n){ return _table.hash_find_insert(n); }
381   Node*  hash_find(const Node* n) { return _table.hash_find(n); }
382 
383   // Used after parsing to eliminate values that are no longer in program
384   void   remove_useless_nodes(VectorSet &useful) {
385     _table.remove_useless_nodes(useful);
386     // this may invalidate cached cons so reset the cache
387     init_con_caches();
388   }
389 
390   virtual ConNode* uncached_makecon(const Type* t);  // override from PhaseTransform
391 
392   const Type* saturate(const Type* new_type, const Type* old_type,
393                        const Type* limit_type) const
394   { return new_type; }
395 
396 #ifndef PRODUCT
397   uint   _count_new_values;     // For profiling, count new values produced
398   void    inc_new_values()        { ++_count_new_values; }
399   void    clear_new_values()      { _count_new_values = 0; }
400   uint    made_new_values() const { return _count_new_values; }
401 #endif
402 };
403 
404 
405 //------------------------------PhaseGVN---------------------------------------
406 // Phase for performing local, pessimistic GVN-style optimizations.
407 class PhaseGVN : public PhaseValues {
408 protected:
409   bool is_dominator_helper(Node *d, Node *n, bool linear_only);
410 
411 public:
412   PhaseGVN( Arena *arena, uint est_max_size ) : PhaseValues( arena, est_max_size ) {}
413   PhaseGVN( PhaseGVN *gvn ) : PhaseValues( gvn ) {}
414 
415   // Return a node which computes the same function as this node, but
416   // in a faster or cheaper fashion.
417   Node  *transform( Node *n );
418   Node  *transform_no_reclaim( Node *n );
419   virtual void record_for_igvn(Node *n) {
420     C->record_for_igvn(n);
421   }
422 
423   void replace_with(PhaseGVN* gvn) {
424     _table.replace_with(&gvn->_table);
425     _types = gvn->_types;
426   }
427 
428   bool is_dominator(Node *d, Node *n) { return is_dominator_helper(d, n, true); }
429 
430   // Helper to call Node::Ideal() and BarrierSetC2::ideal_node().
431   Node* apply_ideal(Node* i, bool can_reshape);
432 
433 #ifdef ASSERT
434   void dump_infinite_loop_info(Node* n, const char* where);
435   // Check for a simple dead loop when a data node references itself.
436   void dead_loop_check(Node *n);
437 #endif
438 };
439 
440 //------------------------------PhaseIterGVN-----------------------------------
441 // Phase for iteratively performing local, pessimistic GVN-style optimizations.
442 // and ideal transformations on the graph.
443 class PhaseIterGVN : public PhaseGVN {
444 private:
445   bool _delay_transform;  // When true simply register the node when calling transform
446                           // instead of actually optimizing it
447 
448   // Idealize old Node 'n' with respect to its inputs and its value
449   virtual Node *transform_old( Node *a_node );
450 
451   // Subsume users of node 'old' into node 'nn'
452   void subsume_node( Node *old, Node *nn );
453 
454   Node_Stack _stack;      // Stack used to avoid recursion
455 protected:
456 
457   // Shuffle worklist, for stress testing
458   void shuffle_worklist();
459 
460   virtual const Type* saturate(const Type* new_type, const Type* old_type,
461                                const Type* limit_type) const;
462   // Usually returns new_type.  Returns old_type if new_type is only a slight
463   // improvement, such that it would take many (>>10) steps to reach 2**32.
464 
465 public:
466   PhaseIterGVN(PhaseIterGVN* igvn); // Used by CCP constructor
467   PhaseIterGVN(PhaseGVN* gvn); // Used after Parser
468 
469   // Idealize new Node 'n' with respect to its inputs and its value
470   virtual Node *transform( Node *a_node );
471   virtual void record_for_igvn(Node *n) { }
472 
473   Unique_Node_List _worklist;       // Iterative worklist
474 
475   // Given def-use info and an initial worklist, apply Node::Ideal,
476   // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU
477   // and dominator info to a fixed point.
478   void optimize();
479 
480 #ifndef PRODUCT
481   void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type);
482   void init_verifyPhaseIterGVN();
483   void verify_PhaseIterGVN();
484 #endif
485 
486 #ifdef ASSERT
487   void dump_infinite_loop_info(Node* n, const char* where);
488   void trace_PhaseIterGVN_verbose(Node* n, int num_processed);
489 #endif
490 
491   // Register a new node with the iter GVN pass without transforming it.
492   // Used when we need to restructure a Region/Phi area and all the Regions
493   // and Phis need to complete this one big transform before any other
494   // transforms can be triggered on the region.
495   // Optional 'orig' is an earlier version of this node.
496   // It is significant only for debugging and profiling.
497   Node* register_new_node_with_optimizer(Node* n, Node* orig = NULL);
498 
499   // Kill a globally dead Node.  All uses are also globally dead and are
500   // aggressively trimmed.
501   void remove_globally_dead_node( Node *dead );
502 
503   // Kill all inputs to a dead node, recursively making more dead nodes.
504   // The Node must be dead locally, i.e., have no uses.
505   void remove_dead_node( Node *dead ) {
506     assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead");
507     remove_globally_dead_node(dead);
508   }
509 
510   // Add users of 'n' to worklist
511   void add_users_to_worklist0( Node *n );
512   void add_users_to_worklist ( Node *n );
513 
514   // Replace old node with new one.
515   void replace_node( Node *old, Node *nn ) {
516     add_users_to_worklist(old);
517     hash_delete(old); // Yank from hash before hacking edges
518     subsume_node(old, nn);
519   }
520 
521   // Delayed node rehash: remove a node from the hash table and rehash it during
522   // next optimizing pass
523   void rehash_node_delayed(Node* n) {
524     hash_delete(n);
525     _worklist.push(n);
526   }
527 
528   // Replace ith edge of "n" with "in"
529   void replace_input_of(Node* n, int i, Node* in) {
530     rehash_node_delayed(n);
531     n->set_req_X(i, in, this);
532   }
533 
534   // Add "in" as input (req) of "n"
535   void add_input_to(Node* n, Node* in) {
536     rehash_node_delayed(n);
537     n->add_req(in);
538   }
539 
540   // Delete ith edge of "n"
541   void delete_input_of(Node* n, int i) {
542     rehash_node_delayed(n);
543     n->del_req(i);
544   }
545 
546   // Delete precedence edge i of "n"
547   void delete_precedence_of(Node* n, int i) {
548     rehash_node_delayed(n);
549     n->rm_prec(i);
550   }
551 
552   bool delay_transform() const { return _delay_transform; }
553 
554   void set_delay_transform(bool delay) {
555     _delay_transform = delay;
556   }
557 
558   void remove_speculative_types();
559   void check_no_speculative_types() {
560     _table.check_no_speculative_types();
561   }
562 
563   bool is_dominator(Node *d, Node *n) { return is_dominator_helper(d, n, false); }
564   bool no_dependent_zero_check(Node* n) const;
565 
566 #ifndef PRODUCT
567 protected:
568   // Sub-quadratic implementation of VerifyIterativeGVN.
569   julong _verify_counter;
570   julong _verify_full_passes;
571   enum { _verify_window_size = 30 };
572   Node* _verify_window[_verify_window_size];
573   void verify_step(Node* n);
574 #endif
575 };
576 
577 //------------------------------PhaseCCP---------------------------------------
578 // Phase for performing global Conditional Constant Propagation.
579 // Should be replaced with combined CCP & GVN someday.
580 class PhaseCCP : public PhaseIterGVN {
581   Unique_Node_List _root_and_safepoints;
582   // Non-recursive.  Use analysis to transform single Node.
583   virtual Node* transform_once(Node* n);
584 
585   Node* fetch_next_node(Unique_Node_List& worklist);
586   static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN;
587 
588   void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const;
589   void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const;
590   void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const;
591   void push_phis(Unique_Node_List& worklist, const Node* use) const;
592   static void push_catch(Unique_Node_List& worklist, const Node* use);
593   void push_cmpu(Unique_Node_List& worklist, const Node* use) const;
594   static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use);
595   void push_loadp(Unique_Node_List& worklist, const Node* use) const;
596   static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use);
597   void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
598 
599  public:
600   PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
601   NOT_PRODUCT( ~PhaseCCP(); )
602 
603   // Worklist algorithm identifies constants
604   void analyze();
605   // Recursive traversal of program.  Used analysis to modify program.
606   virtual Node *transform( Node *n );
607   // Do any transformation after analysis
608   void          do_transform();
609 
610   virtual const Type* saturate(const Type* new_type, const Type* old_type,
611                                const Type* limit_type) const;
612   // Returns new_type->widen(old_type), which increments the widen bits until
613   // giving up with TypeInt::INT or TypeLong::LONG.
614   // Result is clipped to limit_type if necessary.
615 
616 #ifndef PRODUCT
617   static uint _total_invokes;    // For profiling, count invocations
618   void    inc_invokes()          { ++PhaseCCP::_total_invokes; }
619 
620   static uint _total_constants;  // For profiling, count constants found
621   uint   _count_constants;
622   void    clear_constants()      { _count_constants = 0; }
623   void    inc_constants()        { ++_count_constants; }
624   uint    count_constants() const { return _count_constants; }
625 
626   static void print_statistics();
627 #endif
628 };
629 
630 
631 //------------------------------PhasePeephole----------------------------------
632 // Phase for performing peephole optimizations on register allocated basic blocks.
633 class PhasePeephole : public PhaseTransform {
634   PhaseRegAlloc *_regalloc;
635   PhaseCFG     &_cfg;
636   // Recursive traversal of program.  Pure function is unused in this phase
637   virtual Node *transform( Node *n );
638 
639 public:
640   PhasePeephole( PhaseRegAlloc *regalloc, PhaseCFG &cfg );
641   NOT_PRODUCT( ~PhasePeephole(); )
642 
643   // Do any transformation after analysis
644   void          do_transform();
645 
646 #ifndef PRODUCT
647   static uint _total_peepholes;  // For profiling, count peephole rules applied
648   uint   _count_peepholes;
649   void    clear_peepholes()      { _count_peepholes = 0; }
650   void    inc_peepholes()        { ++_count_peepholes; }
651   uint    count_peepholes() const { return _count_peepholes; }
652 
653   static void print_statistics();
654 #endif
655 };
656 
657 #endif // SHARE_OPTO_PHASEX_HPP