1 /*
  2  * Copyright (c) 1997, 2026, 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_CFGNODE_HPP
 26 #define SHARE_OPTO_CFGNODE_HPP
 27 
 28 #include "opto/multnode.hpp"
 29 #include "opto/node.hpp"
 30 #include "opto/opcodes.hpp"
 31 #include "opto/predicates_enums.hpp"
 32 #include "opto/type.hpp"
 33 #include "runtime/arguments.hpp"
 34 
 35 // Portions of code courtesy of Clifford Click
 36 
 37 // Optimization - Graph Style
 38 
 39 class Matcher;
 40 class Node;
 41 class   RegionNode;
 42 class   TypeNode;
 43 class     PhiNode;
 44 class   GotoNode;
 45 class   MultiNode;
 46 class     MultiBranchNode;
 47 class       IfNode;
 48 class       PCTableNode;
 49 class         JumpNode;
 50 class         CatchNode;
 51 class       NeverBranchNode;
 52 class     BlackholeNode;
 53 class   ProjNode;
 54 class     CProjNode;
 55 class       IfTrueNode;
 56 class       IfFalseNode;
 57 class       CatchProjNode;
 58 class     JProjNode;
 59 class       JumpProjNode;
 60 class     SCMemProjNode;
 61 class PhaseIdealLoop;
 62 enum class AssertionPredicateType;
 63 enum class PredicateState;
 64 
 65 //------------------------------RegionNode-------------------------------------
 66 // The class of RegionNodes, which can be mapped to basic blocks in the
 67 // program.  Their inputs point to Control sources.  PhiNodes (described
 68 // below) have an input point to a RegionNode.  Merged data inputs to PhiNodes
 69 // correspond 1-to-1 with RegionNode inputs.  The zero input of a PhiNode is
 70 // the RegionNode, and the zero input of the RegionNode is itself.
 71 class RegionNode : public Node {
 72 public:
 73   enum LoopStatus {
 74     // No guarantee: the region may be an irreducible loop entry, thus we have to
 75     // be careful when removing entry control to it.
 76     MaybeIrreducibleEntry,
 77     // Limited guarantee: this region may be (nested) inside an irreducible loop,
 78     // but it will never be an irreducible loop entry.
 79     NeverIrreducibleEntry,
 80     // Strong guarantee: this region is not (nested) inside an irreducible loop.
 81     Reducible,
 82   };
 83 
 84 private:
 85   bool _is_unreachable_region;
 86   LoopStatus _loop_status;
 87 
 88   bool is_possible_unsafe_loop() const;
 89   bool is_unreachable_from_root(const PhaseGVN* phase) const;
 90 public:
 91   // Node layout (parallels PhiNode):
 92   enum { Region,                // Generally points to self.
 93          Control                // Control arcs are [1..len)
 94   };
 95 
 96   RegionNode(uint required)
 97     : Node(required),
 98       _is_unreachable_region(false),
 99       _loop_status(LoopStatus::NeverIrreducibleEntry)
100   {
101     init_class_id(Class_Region);
102     init_req(0, this);
103   }
104 
105   Node* is_copy() const {
106     const Node* r = _in[Region];
107     if (r == nullptr)
108       return nonnull_req();
109     return nullptr;  // not a copy!
110   }
111   PhiNode* has_phi() const;        // returns an arbitrary phi user, or null
112   PhiNode* has_unique_phi() const; // returns the unique phi user, or null
113   // Is this region node unreachable from root?
114   bool is_unreachable_region(const PhaseGVN* phase);
115 #ifdef ASSERT
116   bool is_in_infinite_subgraph();
117   static bool are_all_nodes_in_infinite_subgraph(Unique_Node_List& worklist);
118 #endif //ASSERT
119   LoopStatus loop_status() const { return _loop_status; };
120   void set_loop_status(LoopStatus status);
121   bool can_be_irreducible_entry() const;
122 
123   virtual int Opcode() const;
124   virtual uint size_of() const { return sizeof(*this); }
125   virtual bool pinned() const { return (const Node*)in(0) == this; }
126   virtual bool is_CFG() const { return true; }
127   virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash
128   virtual const Type* bottom_type() const { return Type::CONTROL; }
129   virtual const Type* Value(PhaseGVN* phase) const;
130   virtual Node* Identity(PhaseGVN* phase);
131   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
132   void remove_unreachable_subgraph(PhaseIterGVN* igvn);
133   virtual const RegMask &out_RegMask() const;
134   bool is_diamond() const;
135   void try_clean_mem_phis(PhaseIterGVN* phase);
136   bool optimize_trichotomy(PhaseIterGVN* igvn);
137   NOT_PRODUCT(virtual void dump_spec(outputStream* st) const;)
138 };
139 
140 //------------------------------JProjNode--------------------------------------
141 // jump projection for node that produces multiple control-flow paths
142 class JProjNode : public ProjNode {
143  public:
144   JProjNode( Node* ctrl, uint idx ) : ProjNode(ctrl,idx) {}
145   virtual int Opcode() const;
146   virtual bool  is_CFG() const { return true; }
147   virtual uint  hash() const { return NO_HASH; }  // CFG nodes do not hash
148   virtual const Node* is_block_proj() const { return in(0); }
149   virtual const RegMask& out_RegMask() const;
150   virtual uint  ideal_reg() const { return 0; }
151 };
152 
153 //------------------------------PhiNode----------------------------------------
154 // PhiNodes merge values from different Control paths.  Slot 0 points to the
155 // controlling RegionNode.  Other slots map 1-for-1 with incoming control flow
156 // paths to the RegionNode.
157 class PhiNode : public TypeNode {
158   friend class PhaseRenumberLive;
159 
160   const TypePtr* const _adr_type; // non-null only for Type::MEMORY nodes.
161   // The following fields are only used for data PhiNodes to indicate
162   // that the PhiNode represents the value of a known instance field.
163         int _inst_mem_id; // Instance memory id (node index of the memory Phi)
164         int _inst_id;     // Instance id of the memory slice.
165   const int _inst_index;  // Alias index of the instance memory slice.
166   // Array elements references have the same alias_idx but different offset.
167   const int _inst_offset; // Offset of the instance memory slice.
168   // Size is bigger to hold the _adr_type field.
169   virtual uint hash() const;    // Check the type
170   virtual bool cmp( const Node &n ) const;
171   virtual uint size_of() const { return sizeof(*this); }
172 
173   // Determine if CMoveNode::is_cmove_id can be used at this join point.
174   Node* is_cmove_id(PhaseTransform* phase, int true_path);
175   bool wait_for_region_igvn(PhaseGVN* phase);
176   bool is_data_loop(RegionNode* r, Node* uin, const PhaseGVN* phase);
177 
178   static Node* clone_through_phi(Node* root_phi, const Type* t, uint c, PhaseIterGVN* igvn);
179   static Node* merge_through_phi(Node* root_phi, PhaseIterGVN* igvn);
180 
181   bool must_wait_for_region_in_irreducible_loop(PhaseGVN* phase) const;
182 
183   bool can_push_inline_types_down(PhaseGVN* phase, bool can_reshape, ciInlineKlass*& inline_klass);
184   InlineTypeNode* push_inline_types_down(PhaseGVN* phase, bool can_reshape, ciInlineKlass* inline_klass);
185 
186   bool is_split_through_mergemem_terminating() const;
187 
188   void verify_type_stability(const PhaseGVN* phase, const Type* union_of_input_types, const Type* new_type) const NOT_DEBUG_RETURN;
189   bool wait_for_cast_input_igvn(const PhaseIterGVN* igvn) const;
190 
191 public:
192   // Node layout (parallels RegionNode):
193   enum { Region,                // Control input is the Phi's region.
194          Input                  // Input values are [1..len)
195   };
196 
197   PhiNode( Node *r, const Type *t, const TypePtr* at = nullptr,
198            const int imid = -1,
199            const int iid = TypeOopPtr::InstanceTop,
200            const int iidx = Compile::AliasIdxTop,
201            const int ioffs = Type::OffsetTop )
202     : TypeNode(t,r->req()),
203       _adr_type(at),
204       _inst_mem_id(imid),
205       _inst_id(iid),
206       _inst_index(iidx),
207       _inst_offset(ioffs)
208   {
209     init_class_id(Class_Phi);
210     init_req(0, r);
211     verify_adr_type();
212   }
213   // create a new phi with in edges matching r and set (initially) to x
214   static PhiNode* make( Node* r, Node* x );
215   // extra type arguments override the new phi's bottom_type and adr_type
216   static PhiNode* make( Node* r, Node* x, const Type *t, const TypePtr* at = nullptr );
217   // create a new phi with narrowed memory type
218   PhiNode* slice_memory(const TypePtr* adr_type) const;
219   PhiNode* split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const;
220   // like make(r, x), but does not initialize the in edges to x
221   static PhiNode* make_blank( Node* r, Node* x );
222 
223   // Accessors
224   RegionNode* region() const { Node* r = in(Region); assert(!r || r->is_Region(), ""); return (RegionNode*)r; }
225 
226   bool is_tripcount(BasicType bt) const;
227 
228   // Determine a unique non-trivial input, if any.
229   // Ignore casts if it helps.  Return null on failure.
230   Node* unique_input(PhaseValues* phase, bool uncast);
231   Node* unique_input(PhaseValues* phase) {
232     Node* uin = unique_input(phase, false);
233     if (uin == nullptr) {
234       uin = unique_input(phase, true);
235     }
236     return uin;
237   }
238   Node* unique_constant_input_recursive(PhaseGVN* phase);
239 
240   // Check for a simple dead loop.
241   enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };
242   LoopSafety simple_data_loop_check(Node *in) const;
243   // Is it unsafe data loop? It becomes a dead loop if this phi node removed.
244   bool is_unsafe_data_reference(Node *in) const;
245   int is_diamond_phi() const;
246   bool try_clean_memory_phi(PhaseIterGVN* igvn);
247   virtual int Opcode() const;
248   virtual bool pinned() const { return in(0) != nullptr; }
249   virtual const TypePtr *adr_type() const { verify_adr_type(true); return _adr_type; }
250 
251   void  set_inst_mem_id(int inst_mem_id) { _inst_mem_id = inst_mem_id; }
252   int inst_mem_id() const { return _inst_mem_id; }
253   int inst_id()     const { return _inst_id; }
254   int inst_index()  const { return _inst_index; }
255   int inst_offset() const { return _inst_offset; }
256   bool is_same_inst_field(const Type* tp, int mem_id, int id, int index, int offset) {
257     return type()->basic_type() == tp->basic_type() &&
258            inst_mem_id() == mem_id &&
259            inst_id()     == id     &&
260            inst_index()  == index  &&
261            inst_offset() == offset &&
262            type()->higher_equal(tp);
263   }
264 
265   bool can_be_inline_type() const {
266     return Arguments::is_valhalla_enabled() && _type->isa_instptr() && _type->is_instptr()->can_be_inline_type();
267   }
268 
269   Node* try_push_inline_types_down(PhaseGVN* phase, bool can_reshape);
270   DEBUG_ONLY(bool can_push_inline_types_down(PhaseGVN* phase);)
271 
272   virtual const Type* Value(PhaseGVN* phase) const;
273   virtual Node* Identity(PhaseGVN* phase);
274   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
275   virtual const RegMask &out_RegMask() const;
276   virtual const RegMask &in_RegMask(uint) const;
277 #ifndef PRODUCT
278   virtual void dump_spec(outputStream *st) const;
279 #endif
280 #ifdef ASSERT
281   void verify_adr_type(VectorSet& visited, const TypePtr* at) const;
282   void verify_adr_type(bool recursive = false) const;
283 #else //ASSERT
284   void verify_adr_type(bool recursive = false) const {}
285 #endif //ASSERT
286 
287   const TypeTuple* collect_types(PhaseGVN* phase) const;
288   bool can_be_replaced_by(const PhiNode* other) const;
289 };
290 
291 //------------------------------GotoNode---------------------------------------
292 // GotoNodes perform direct branches.
293 class GotoNode : public Node {
294 public:
295   GotoNode( Node *control ) : Node(control) {}
296   virtual int Opcode() const;
297   virtual bool pinned() const { return true; }
298   virtual bool  is_CFG() const { return true; }
299   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
300   virtual const Node *is_block_proj() const { return this; }
301   virtual const Type *bottom_type() const { return Type::CONTROL; }
302   virtual const Type* Value(PhaseGVN* phase) const;
303   virtual Node* Identity(PhaseGVN* phase);
304   virtual const RegMask &out_RegMask() const;
305 };
306 
307 //------------------------------CProjNode--------------------------------------
308 // control projection for node that produces multiple control-flow paths
309 class CProjNode : public ProjNode {
310 public:
311   CProjNode( Node *ctrl, uint idx ) : ProjNode(ctrl,idx) {}
312   virtual int Opcode() const;
313   virtual bool  is_CFG() const { return true; }
314   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
315   virtual const Node *is_block_proj() const { return in(0); }
316   virtual const RegMask &out_RegMask() const;
317   virtual uint ideal_reg() const { return 0; }
318 };
319 
320 //---------------------------MultiBranchNode-----------------------------------
321 // This class defines a MultiBranchNode, a MultiNode which yields multiple
322 // control values. These are distinguished from other types of MultiNodes
323 // which yield multiple values, but control is always and only projection #0.
324 class MultiBranchNode : public MultiNode {
325 public:
326   MultiBranchNode( uint required ) : MultiNode(required) {
327     init_class_id(Class_MultiBranch);
328   }
329   // returns required number of users to be well formed.
330   virtual uint required_outcnt() const = 0;
331 };
332 
333 //------------------------------IfNode-----------------------------------------
334 // Output selected Control, based on a boolean test
335 class IfNode : public MultiBranchNode {
336  public:
337   float _prob;                           // Probability of true path being taken.
338   float _fcnt;                           // Frequency counter
339 
340  private:
341   AssertionPredicateType _assertion_predicate_type;
342 
343   void init_node(Node* control, Node* bol) {
344     init_class_id(Class_If);
345     init_req(0, control);
346     init_req(1, bol);
347   }
348 
349   // Size is bigger to hold the probability field.  However, _prob does not
350   // change the semantics so it does not appear in the hash & cmp functions.
351   virtual uint size_of() const { return sizeof(*this); }
352 
353   // Helper methods for fold_compares
354   bool cmpi_folds(PhaseIterGVN* igvn, bool fold_ne = false);
355   bool is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn);
356   bool has_shared_region(IfProjNode* proj, IfProjNode*& success, IfProjNode*& fail) const;
357   bool has_only_uncommon_traps(IfProjNode* proj, IfProjNode*& success, IfProjNode*& fail, PhaseIterGVN* igvn) const;
358   Node* merge_uncommon_traps(IfProjNode* proj, IfProjNode* success, IfProjNode* fail, PhaseIterGVN* igvn);
359   static void improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGVN* igvn);
360   bool is_cmp_with_loadrange(IfProjNode* proj) const;
361   bool is_null_check(IfProjNode* proj, PhaseIterGVN* igvn) const;
362   bool is_side_effect_free_test(IfProjNode* proj, PhaseIterGVN* igvn) const;
363   static void reroute_side_effect_free_unc(IfProjNode* proj, IfProjNode* dom_proj, PhaseIterGVN* igvn);
364   bool fold_compares_helper(IfProjNode* proj, IfProjNode* success, IfProjNode* fail, PhaseIterGVN* igvn);
365   static bool is_dominator_unc(CallStaticJavaNode* dom_unc, CallStaticJavaNode* unc);
366 
367 protected:
368   IfProjNode* range_check_trap_proj(int& flip, Node*& l, Node*& r) const;
369   Node* Ideal_common(PhaseGVN *phase, bool can_reshape);
370   Node* search_identical(int dist, PhaseIterGVN* igvn);
371 
372   Node* simple_subsuming(PhaseIterGVN* igvn);
373 
374 public:
375 
376   // Degrees of branch prediction probability by order of magnitude:
377   // PROB_UNLIKELY_1e(N) is a 1 in 1eN chance.
378   // PROB_LIKELY_1e(N) is a 1 - PROB_UNLIKELY_1e(N)
379 #define PROB_UNLIKELY_MAG(N)    (1e- ## N ## f)
380 #define PROB_LIKELY_MAG(N)      (1.0f-PROB_UNLIKELY_MAG(N))
381 
382   // Maximum and minimum branch prediction probabilties
383   // 1 in 1,000,000 (magnitude 6)
384   //
385   // Although PROB_NEVER == PROB_MIN and PROB_ALWAYS == PROB_MAX
386   // they are used to distinguish different situations:
387   //
388   // The name PROB_MAX (PROB_MIN) is for probabilities which correspond to
389   // very likely (unlikely) but with a concrete possibility of a rare
390   // contrary case.  These constants would be used for pinning
391   // measurements, and as measures for assertions that have high
392   // confidence, but some evidence of occasional failure.
393   //
394   // The name PROB_ALWAYS (PROB_NEVER) is to stand for situations for which
395   // there is no evidence at all that the contrary case has ever occurred.
396 
397 #define PROB_NEVER              PROB_UNLIKELY_MAG(6)
398 #define PROB_ALWAYS             PROB_LIKELY_MAG(6)
399 
400 #define PROB_MIN                PROB_UNLIKELY_MAG(6)
401 #define PROB_MAX                PROB_LIKELY_MAG(6)
402 
403   // Static branch prediction probabilities
404   // 1 in 10 (magnitude 1)
405 #define PROB_STATIC_INFREQUENT  PROB_UNLIKELY_MAG(1)
406 #define PROB_STATIC_FREQUENT    PROB_LIKELY_MAG(1)
407 
408   // Fair probability 50/50
409 #define PROB_FAIR               (0.5f)
410 
411   // Unknown probability sentinel
412 #define PROB_UNKNOWN            (-1.0f)
413 
414   // Probability "constructors", to distinguish as a probability any manifest
415   // constant without a names
416 #define PROB_LIKELY(x)          ((float) (x))
417 #define PROB_UNLIKELY(x)        (1.0f - (float)(x))
418 
419   // Other probabilities in use, but without a unique name, are documented
420   // here for lack of a better place:
421   //
422   // 1 in 1000 probabilities (magnitude 3):
423   //     threshold for converting to conditional move
424   //     likelihood of null check failure if a null HAS been seen before
425   //     likelihood of slow path taken in library calls
426   //
427   // 1 in 10,000 probabilities (magnitude 4):
428   //     threshold for making an uncommon trap probability more extreme
429   //     threshold for for making a null check implicit
430   //     likelihood of needing a gc if eden top moves during an allocation
431   //     likelihood of a predicted call failure
432   //
433   // 1 in 100,000 probabilities (magnitude 5):
434   //     threshold for ignoring counts when estimating path frequency
435   //     likelihood of FP clipping failure
436   //     likelihood of catching an exception from a try block
437   //     likelihood of null check failure if a null has NOT been seen before
438   //
439   // Magic manifest probabilities such as 0.83, 0.7, ... can be found in
440   // gen_subtype_check() and catch_inline_exceptions().
441 
442   IfNode(Node* control, Node* bol, float p, float fcnt);
443   IfNode(Node* control, Node* bol, float p, float fcnt, AssertionPredicateType assertion_predicate_type);
444 
445   static IfNode* make_with_same_profile(IfNode* if_node_profile, Node* ctrl, Node* bol);
446 
447   IfTrueNode* true_proj() const {
448     return proj_out(true)->as_IfTrue();
449   }
450 
451   IfTrueNode* true_proj_or_null() const {
452     ProjNode* true_proj = proj_out_or_null(true);
453     return true_proj == nullptr ? nullptr : true_proj->as_IfTrue();
454   }
455 
456   IfFalseNode* false_proj() const {
457     return proj_out(false)->as_IfFalse();
458   }
459 
460   IfFalseNode* false_proj_or_null() const {
461     ProjNode* false_proj = proj_out_or_null(false);
462     return false_proj == nullptr ? nullptr : false_proj->as_IfFalse();
463   }
464 
465   virtual int Opcode() const;
466   virtual bool pinned() const { return true; }
467   virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
468   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
469   virtual const Type* Value(PhaseGVN* phase) const;
470   virtual uint required_outcnt() const { return 2; }
471   virtual const RegMask &out_RegMask() const;
472   Node* fold_compares(PhaseIterGVN* phase);
473   static Node* up_one_dom(Node* curr, bool linear_only = false);
474   bool is_zero_trip_guard() const;
475   Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn, bool prev_dom_not_imply_this);
476   ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call, Deoptimization::DeoptReason reason = Deoptimization::Reason_none) const;
477 
478   // Takes the type of val and filters it through the test represented
479   // by if_proj and returns a more refined type if one is produced.
480   // Returns null is it couldn't improve the type.
481   static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
482 
483   bool is_flat_array_check(PhaseTransform* phase, Node** array = nullptr);
484 
485   AssertionPredicateType assertion_predicate_type() const {
486     return _assertion_predicate_type;
487   }
488 
489 #ifndef PRODUCT
490   virtual void dump_spec(outputStream *st) const;
491 #endif
492 
493   bool same_condition(const Node* dom, PhaseIterGVN* igvn) const;
494 };
495 
496 class RangeCheckNode : public IfNode {
497 private:
498   int is_range_check(Node*& range, Node*& index, jint& offset);
499 
500 public:
501   RangeCheckNode(Node* control, Node* bol, float p, float fcnt) : IfNode(control, bol, p, fcnt) {
502     init_class_id(Class_RangeCheck);
503   }
504 
505   RangeCheckNode(Node* control, Node* bol, float p, float fcnt, AssertionPredicateType assertion_predicate_type)
506       : IfNode(control, bol, p, fcnt, assertion_predicate_type) {
507     init_class_id(Class_RangeCheck);
508   }
509 
510   virtual int Opcode() const;
511   virtual Node* Ideal(PhaseGVN *phase, bool can_reshape);
512 };
513 
514 // Special node that denotes a Parse Predicate added during parsing. A Parse Predicate serves as placeholder to later
515 // create Regular Predicates (Runtime Predicates with possible Assertion Predicates) above it. Together they form a
516 // Predicate Block. The Parse Predicate and Regular Predicates share the same uncommon trap.
517 // There are three kinds of Parse Predicates:
518 // Loop Parse Predicate, Profiled Loop Parse Predicate (both used by Loop Predication), and Loop Limit Check Parse
519 // Predicate (used for integer overflow checks when creating a counted loop).
520 // More information about predicates can be found in loopPredicate.cpp.
521 class ParsePredicateNode : public IfNode {
522   Deoptimization::DeoptReason _deopt_reason;
523 
524   // When a Parse Predicate loses its connection to a loop head, it will be marked useless by
525   // EliminateUselessPredicates and cleaned up by Value(). It can also become useless when cloning it to both loops
526   // during Loop Multiversioning - we no longer use the old version.
527   PredicateState _predicate_state;
528  public:
529   ParsePredicateNode(Node* control, Deoptimization::DeoptReason deopt_reason, PhaseGVN* gvn);
530   virtual int Opcode() const;
531   virtual uint size_of() const { return sizeof(*this); }
532 
533   Deoptimization::DeoptReason deopt_reason() const {
534     return _deopt_reason;
535   }
536 
537   bool is_useless() const {
538     return _predicate_state == PredicateState::Useless;
539   }
540 
541   void mark_useless(PhaseIterGVN& igvn);
542 
543   void mark_maybe_useful() {
544     _predicate_state = PredicateState::MaybeUseful;
545   }
546 
547   bool is_useful() const {
548     return _predicate_state == PredicateState::Useful;
549   }
550 
551   void mark_useful() {
552     _predicate_state = PredicateState::Useful;
553   }
554 
555   // Return the uncommon trap If projection of this Parse Predicate.
556   ParsePredicateUncommonProj* uncommon_proj() const {
557     return false_proj();
558   }
559 
560   Node* uncommon_trap() const;
561 
562   Node* Ideal(PhaseGVN* phase, bool can_reshape) {
563     return nullptr; // Don't optimize
564   }
565 
566   const Type* Value(PhaseGVN* phase) const;
567   NOT_PRODUCT(void dump_spec(outputStream* st) const;)
568 };
569 
570 class IfProjNode : public CProjNode {
571 public:
572   IfProjNode(IfNode *ifnode, uint idx) : CProjNode(ifnode,idx) {}
573   virtual Node* Identity(PhaseGVN* phase);
574 
575   // Return the other IfProj node.
576   IfProjNode* other_if_proj() const {
577     return in(0)->as_If()->proj_out(1 - _con)->as_IfProj();
578   }
579 
580   void pin_dependent_nodes(PhaseIterGVN* igvn);
581 
582 protected:
583   // Type of If input when this branch is always taken
584   virtual bool always_taken(const TypeTuple* t) const = 0;
585 };
586 
587 class IfTrueNode : public IfProjNode {
588 public:
589   IfTrueNode( IfNode *ifnode ) : IfProjNode(ifnode,1) {
590     init_class_id(Class_IfTrue);
591   }
592   virtual int Opcode() const;
593 
594 protected:
595   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFTRUE; }
596 };
597 
598 class IfFalseNode : public IfProjNode {
599 public:
600   IfFalseNode( IfNode *ifnode ) : IfProjNode(ifnode,0) {
601     init_class_id(Class_IfFalse);
602   }
603   virtual int Opcode() const;
604 
605 protected:
606   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFFALSE; }
607 };
608 
609 
610 //------------------------------PCTableNode------------------------------------
611 // Build an indirect branch table.  Given a control and a table index,
612 // control is passed to the Projection matching the table index.  Used to
613 // implement switch statements and exception-handling capabilities.
614 // Undefined behavior if passed-in index is not inside the table.
615 class PCTableNode : public MultiBranchNode {
616   virtual uint hash() const;    // Target count; table size
617   virtual bool cmp( const Node &n ) const;
618   virtual uint size_of() const { return sizeof(*this); }
619 
620 public:
621   const uint _size;             // Number of targets
622 
623   PCTableNode( Node *ctrl, Node *idx, uint size ) : MultiBranchNode(2), _size(size) {
624     init_class_id(Class_PCTable);
625     init_req(0, ctrl);
626     init_req(1, idx);
627   }
628   virtual int Opcode() const;
629   virtual const Type* Value(PhaseGVN* phase) const;
630   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
631   virtual const Type *bottom_type() const;
632   virtual bool pinned() const { return true; }
633   virtual uint required_outcnt() const { return _size; }
634 };
635 
636 //------------------------------JumpNode---------------------------------------
637 // Indirect branch.  Uses PCTable above to implement a switch statement.
638 // It emits as a table load and local branch.
639 class JumpNode : public PCTableNode {
640   virtual uint size_of() const { return sizeof(*this); }
641 public:
642   float* _probs; // probability of each projection
643   float _fcnt;   // total number of times this Jump was executed
644   JumpNode( Node* control, Node* switch_val, uint size, float* probs, float cnt)
645     : PCTableNode(control, switch_val, size),
646       _probs(probs), _fcnt(cnt) {
647     init_class_id(Class_Jump);
648   }
649   virtual int   Opcode() const;
650   virtual const RegMask& out_RegMask() const;
651   virtual const Node* is_block_proj() const { return this; }
652 };
653 
654 class JumpProjNode : public JProjNode {
655   virtual uint hash() const;
656   virtual bool cmp( const Node &n ) const;
657   virtual uint size_of() const { return sizeof(*this); }
658 
659  private:
660   const int  _dest_bci;
661   const uint _proj_no;
662   const int  _switch_val;
663  public:
664   JumpProjNode(Node* jumpnode, uint proj_no, int dest_bci, int switch_val)
665     : JProjNode(jumpnode, proj_no), _dest_bci(dest_bci), _proj_no(proj_no), _switch_val(switch_val) {
666     init_class_id(Class_JumpProj);
667   }
668 
669   virtual int Opcode() const;
670   virtual const Type* bottom_type() const { return Type::CONTROL; }
671   int  dest_bci()    const { return _dest_bci; }
672   int  switch_val()  const { return _switch_val; }
673   uint proj_no()     const { return _proj_no; }
674 #ifndef PRODUCT
675   virtual void dump_spec(outputStream *st) const;
676   virtual void dump_compact_spec(outputStream *st) const;
677 #endif
678 };
679 
680 //------------------------------CatchNode--------------------------------------
681 // Helper node to fork exceptions.  "Catch" catches any exceptions thrown by
682 // a just-prior call.  Looks like a PCTableNode but emits no code - just the
683 // table.  The table lookup and branch is implemented by RethrowNode.
684 class CatchNode : public PCTableNode {
685 public:
686   CatchNode( Node *ctrl, Node *idx, uint size ) : PCTableNode(ctrl,idx,size){
687     init_class_id(Class_Catch);
688   }
689   virtual int Opcode() const;
690   virtual const Type* Value(PhaseGVN* phase) const;
691 };
692 
693 // CatchProjNode controls which exception handler is targeted after a call.
694 // It is passed in the bci of the target handler, or no_handler_bci in case
695 // the projection doesn't lead to an exception handler.
696 class CatchProjNode : public CProjNode {
697   virtual uint hash() const;
698   virtual bool cmp( const Node &n ) const;
699   virtual uint size_of() const { return sizeof(*this); }
700 
701 private:
702   const int _handler_bci;
703 
704 public:
705   enum {
706     fall_through_index =  0,      // the fall through projection index
707     catch_all_index    =  1,      // the projection index for catch-alls
708     no_handler_bci     = -1       // the bci for fall through or catch-all projs
709   };
710 
711   CatchProjNode(Node* catchnode, uint proj_no, int handler_bci)
712     : CProjNode(catchnode, proj_no), _handler_bci(handler_bci) {
713     init_class_id(Class_CatchProj);
714     assert(proj_no != fall_through_index || handler_bci < 0, "fall through case must have bci < 0");
715   }
716 
717   virtual int Opcode() const;
718   virtual Node* Identity(PhaseGVN* phase);
719   virtual const Type *bottom_type() const { return Type::CONTROL; }
720   int  handler_bci() const        { return _handler_bci; }
721   bool is_handler_proj() const    { return _handler_bci >= 0; }
722 #ifndef PRODUCT
723   virtual void dump_spec(outputStream *st) const;
724 #endif
725 };
726 
727 
728 //---------------------------------CreateExNode--------------------------------
729 // Helper node to create the exception coming back from a call
730 class CreateExNode : public TypeNode {
731 public:
732   CreateExNode(const Type* t, Node* control, Node* i_o) : TypeNode(t, 2) {
733     init_req(0, control);
734     init_req(1, i_o);
735   }
736   virtual int Opcode() const;
737   virtual Node* Identity(PhaseGVN* phase);
738   virtual bool pinned() const { return true; }
739   uint match_edge(uint idx) const { return 0; }
740   virtual uint ideal_reg() const { return Op_RegP; }
741 };
742 
743 //------------------------------NeverBranchNode-------------------------------
744 // The never-taken branch.  Used to give the appearance of exiting infinite
745 // loops to those algorithms that like all paths to be reachable.  Encodes
746 // empty.
747 class NeverBranchNode : public MultiBranchNode {
748 public:
749   NeverBranchNode(Node* ctrl) : MultiBranchNode(1) {
750     init_req(0, ctrl);
751     init_class_id(Class_NeverBranch);
752   }
753   virtual int Opcode() const;
754   virtual bool pinned() const { return true; };
755   virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
756   virtual const Type* Value(PhaseGVN* phase) const;
757   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
758   virtual uint required_outcnt() const { return 2; }
759   virtual void emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const { }
760   virtual uint size(PhaseRegAlloc *ra_) const { return 0; }
761 #ifndef PRODUCT
762   virtual void format( PhaseRegAlloc *, outputStream *st ) const;
763 #endif
764 };
765 
766 //------------------------------BlackholeNode----------------------------
767 // Blackhole all arguments. This node would survive through the compiler
768 // the effects on its arguments, and would be finally matched to nothing.
769 class BlackholeNode : public MultiNode {
770 public:
771   BlackholeNode(Node* ctrl) : MultiNode(1) {
772     init_req(TypeFunc::Control, ctrl);
773     init_class_id(Class_Blackhole);
774   }
775   virtual int   Opcode() const;
776   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
777   virtual const Type* bottom_type() const { return TypeTuple::MEMBAR; }
778   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
779 
780   const RegMask &in_RegMask(uint idx) const {
781     // Fake the incoming arguments mask for blackholes: accept all registers
782     // and all stack slots. This would avoid any redundant register moves
783     // for blackhole inputs.
784     return RegMask::ALL;
785   }
786 #ifndef PRODUCT
787   virtual void format(PhaseRegAlloc* ra, outputStream* st) const;
788 #endif
789 };
790 
791 
792 #endif // SHARE_OPTO_CFGNODE_HPP