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