1 /*
  2  * Copyright (c) 1997, 2022, 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 //------------------------------RegionNode-------------------------------------
 62 // The class of RegionNodes, which can be mapped to basic blocks in the
 63 // program.  Their inputs point to Control sources.  PhiNodes (described
 64 // below) have an input point to a RegionNode.  Merged data inputs to PhiNodes
 65 // correspond 1-to-1 with RegionNode inputs.  The zero input of a PhiNode is
 66 // the RegionNode, and the zero input of the RegionNode is itself.
 67 class RegionNode : public Node {
 68 private:
 69   bool _is_unreachable_region;
 70 
 71   bool is_possible_unsafe_loop(const PhaseGVN* phase) const;
 72   bool is_unreachable_from_root(const PhaseGVN* phase) const;
 73 public:
 74   // Node layout (parallels PhiNode):
 75   enum { Region,                // Generally points to self.
 76          Control                // Control arcs are [1..len)
 77   };
 78 
 79   RegionNode(uint required) : Node(required), _is_unreachable_region(false) {
 80     init_class_id(Class_Region);
 81     init_req(0, this);
 82   }
 83 
 84   Node* is_copy() const {
 85     const Node* r = _in[Region];
 86     if (r == NULL)
 87       return nonnull_req();
 88     return NULL;  // not a copy!
 89   }
 90   PhiNode* has_phi() const;        // returns an arbitrary phi user, or NULL
 91   PhiNode* has_unique_phi() const; // returns the unique phi user, or NULL
 92   // Is this region node unreachable from root?
 93   bool is_unreachable_region(const PhaseGVN* phase);
 94   virtual int Opcode() const;
 95   virtual uint size_of() const { return sizeof(*this); }
 96   virtual bool pinned() const { return (const Node*)in(0) == this; }
 97   virtual bool is_CFG() const { return true; }
 98   virtual uint hash() const { return NO_HASH; } // CFG nodes do not hash
 99   virtual bool depends_only_on_test() const { return false; }
100   virtual const Type* bottom_type() const { return Type::CONTROL; }
101   virtual const Type* Value(PhaseGVN* phase) const;
102   virtual Node* Identity(PhaseGVN* phase);
103   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
104   virtual const RegMask &out_RegMask() const;
105   bool try_clean_mem_phi(PhaseGVN* phase);
106   bool optimize_trichotomy(PhaseIterGVN* igvn);
107 };
108 
109 //------------------------------JProjNode--------------------------------------
110 // jump projection for node that produces multiple control-flow paths
111 class JProjNode : public ProjNode {
112  public:
113   JProjNode( Node* ctrl, uint idx ) : ProjNode(ctrl,idx) {}
114   virtual int Opcode() const;
115   virtual bool  is_CFG() const { return true; }
116   virtual uint  hash() const { return NO_HASH; }  // CFG nodes do not hash
117   virtual const Node* is_block_proj() const { return in(0); }
118   virtual const RegMask& out_RegMask() const;
119   virtual uint  ideal_reg() const { return 0; }
120 };
121 
122 //------------------------------PhiNode----------------------------------------
123 // PhiNodes merge values from different Control paths.  Slot 0 points to the
124 // controlling RegionNode.  Other slots map 1-for-1 with incoming control flow
125 // paths to the RegionNode.
126 class PhiNode : public TypeNode {
127   friend class PhaseRenumberLive;
128 
129   const TypePtr* const _adr_type; // non-null only for Type::MEMORY nodes.
130   // The following fields are only used for data PhiNodes to indicate
131   // that the PhiNode represents the value of a known instance field.
132         int _inst_mem_id; // Instance memory id (node index of the memory Phi)
133         int _inst_id;     // Instance id of the memory slice.
134   const int _inst_index;  // Alias index of the instance memory slice.
135   // Array elements references have the same alias_idx but different offset.
136   const int _inst_offset; // Offset of the instance memory slice.
137   // Size is bigger to hold the _adr_type field.
138   virtual uint hash() const;    // Check the type
139   virtual bool cmp( const Node &n ) const;
140   virtual uint size_of() const { return sizeof(*this); }
141 
142   // Determine if CMoveNode::is_cmove_id can be used at this join point.
143   Node* is_cmove_id(PhaseTransform* phase, int true_path);
144   bool wait_for_region_igvn(PhaseGVN* phase);
145   bool is_data_loop(RegionNode* r, Node* uin, const PhaseGVN* phase);
146 
147   static Node* clone_through_phi(Node* root_phi, const Type* t, uint c, PhaseIterGVN* igvn);
148   static Node* merge_through_phi(Node* root_phi, PhaseIterGVN* igvn);
149 
150 public:
151   // Node layout (parallels RegionNode):
152   enum { Region,                // Control input is the Phi's region.
153          Input                  // Input values are [1..len)
154   };
155 
156   PhiNode( Node *r, const Type *t, const TypePtr* at = NULL,
157            const int imid = -1,
158            const int iid = TypeOopPtr::InstanceTop,
159            const int iidx = Compile::AliasIdxTop,
160            const int ioffs = Type::OffsetTop )
161     : TypeNode(t,r->req()),
162       _adr_type(at),
163       _inst_mem_id(imid),
164       _inst_id(iid),
165       _inst_index(iidx),
166       _inst_offset(ioffs)
167   {
168     init_class_id(Class_Phi);
169     init_req(0, r);
170     verify_adr_type();
171   }
172   // create a new phi with in edges matching r and set (initially) to x
173   static PhiNode* make( Node* r, Node* x );
174   // extra type arguments override the new phi's bottom_type and adr_type
175   static PhiNode* make( Node* r, Node* x, const Type *t, const TypePtr* at = NULL );
176   // create a new phi with narrowed memory type
177   PhiNode* slice_memory(const TypePtr* adr_type) const;
178   PhiNode* split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const;
179   // like make(r, x), but does not initialize the in edges to x
180   static PhiNode* make_blank( Node* r, Node* x );
181 
182   // Accessors
183   RegionNode* region() const { Node* r = in(Region); assert(!r || r->is_Region(), ""); return (RegionNode*)r; }
184 
185   bool is_tripcount(BasicType bt) const;
186 
187   // Determine a unique non-trivial input, if any.
188   // Ignore casts if it helps.  Return NULL on failure.
189   Node* unique_input(PhaseTransform *phase, bool uncast);
190   Node* unique_input(PhaseTransform *phase) {
191     Node* uin = unique_input(phase, false);
192     if (uin == NULL) {
193       uin = unique_input(phase, true);
194     }
195     return uin;
196   }
197 
198   // Check for a simple dead loop.
199   enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };
200   LoopSafety simple_data_loop_check(Node *in) const;
201   // Is it unsafe data loop? It becomes a dead loop if this phi node removed.
202   bool is_unsafe_data_reference(Node *in) const;
203   int  is_diamond_phi(bool check_control_only = false) const;
204   virtual int Opcode() const;
205   virtual bool pinned() const { return in(0) != 0; }
206   virtual const TypePtr *adr_type() const { verify_adr_type(true); return _adr_type; }
207 
208   void  set_inst_mem_id(int inst_mem_id) { _inst_mem_id = inst_mem_id; }
209   const int inst_mem_id() const { return _inst_mem_id; }
210   const int inst_id()     const { return _inst_id; }
211   const int inst_index()  const { return _inst_index; }
212   const int inst_offset() const { return _inst_offset; }
213   bool is_same_inst_field(const Type* tp, int mem_id, int id, int index, int offset) {
214     return type()->basic_type() == tp->basic_type() &&
215            inst_mem_id() == mem_id &&
216            inst_id()     == id     &&
217            inst_index()  == index  &&
218            inst_offset() == offset &&
219            type()->higher_equal(tp);
220   }
221 
222   virtual const Type* Value(PhaseGVN* phase) const;
223   virtual Node* Identity(PhaseGVN* phase);
224   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
225   virtual const RegMask &out_RegMask() const;
226   virtual const RegMask &in_RegMask(uint) const;
227 #ifndef PRODUCT
228   virtual void dump_spec(outputStream *st) const;
229 #endif
230 #ifdef ASSERT
231   void verify_adr_type(VectorSet& visited, const TypePtr* at) const;
232   void verify_adr_type(bool recursive = false) const;
233 #else //ASSERT
234   void verify_adr_type(bool recursive = false) const {}
235 #endif //ASSERT
236 };
237 
238 //------------------------------GotoNode---------------------------------------
239 // GotoNodes perform direct branches.
240 class GotoNode : public Node {
241 public:
242   GotoNode( Node *control ) : Node(control) {}
243   virtual int Opcode() const;
244   virtual bool pinned() const { return true; }
245   virtual bool  is_CFG() const { return true; }
246   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
247   virtual const Node *is_block_proj() const { return this; }
248   virtual bool depends_only_on_test() const { return false; }
249   virtual const Type *bottom_type() const { return Type::CONTROL; }
250   virtual const Type* Value(PhaseGVN* phase) const;
251   virtual Node* Identity(PhaseGVN* phase);
252   virtual const RegMask &out_RegMask() const;
253 };
254 
255 //------------------------------CProjNode--------------------------------------
256 // control projection for node that produces multiple control-flow paths
257 class CProjNode : public ProjNode {
258 public:
259   CProjNode( Node *ctrl, uint idx ) : ProjNode(ctrl,idx) {}
260   virtual int Opcode() const;
261   virtual bool  is_CFG() const { return true; }
262   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
263   virtual const Node *is_block_proj() const { return in(0); }
264   virtual const RegMask &out_RegMask() const;
265   virtual uint ideal_reg() const { return 0; }
266 };
267 
268 //---------------------------MultiBranchNode-----------------------------------
269 // This class defines a MultiBranchNode, a MultiNode which yields multiple
270 // control values. These are distinguished from other types of MultiNodes
271 // which yield multiple values, but control is always and only projection #0.
272 class MultiBranchNode : public MultiNode {
273 public:
274   MultiBranchNode( uint required ) : MultiNode(required) {
275     init_class_id(Class_MultiBranch);
276   }
277   // returns required number of users to be well formed.
278   virtual int required_outcnt() const = 0;
279 };
280 
281 //------------------------------IfNode-----------------------------------------
282 // Output selected Control, based on a boolean test
283 class IfNode : public MultiBranchNode {
284   // Size is bigger to hold the probability field.  However, _prob does not
285   // change the semantics so it does not appear in the hash & cmp functions.
286   virtual uint size_of() const { return sizeof(*this); }
287 
288 private:
289   // Helper methods for fold_compares
290   bool cmpi_folds(PhaseIterGVN* igvn, bool fold_ne = false);
291   bool is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn);
292   bool has_shared_region(ProjNode* proj, ProjNode*& success, ProjNode*& fail);
293   bool has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn);
294   Node* merge_uncommon_traps(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
295   static void improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGVN* igvn);
296   bool is_cmp_with_loadrange(ProjNode* proj);
297   bool is_null_check(ProjNode* proj, PhaseIterGVN* igvn);
298   bool is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn);
299   void reroute_side_effect_free_unc(ProjNode* proj, ProjNode* dom_proj, PhaseIterGVN* igvn);
300   ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call) const;
301   bool fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
302   static bool is_dominator_unc(CallStaticJavaNode* dom_unc, CallStaticJavaNode* unc);
303 
304 protected:
305   ProjNode* range_check_trap_proj(int& flip, Node*& l, Node*& r);
306   Node* Ideal_common(PhaseGVN *phase, bool can_reshape);
307   Node* search_identical(int dist);
308 
309   Node* simple_subsuming(PhaseIterGVN* igvn);
310 
311 public:
312 
313   // Degrees of branch prediction probability by order of magnitude:
314   // PROB_UNLIKELY_1e(N) is a 1 in 1eN chance.
315   // PROB_LIKELY_1e(N) is a 1 - PROB_UNLIKELY_1e(N)
316 #define PROB_UNLIKELY_MAG(N)    (1e- ## N ## f)
317 #define PROB_LIKELY_MAG(N)      (1.0f-PROB_UNLIKELY_MAG(N))
318 
319   // Maximum and minimum branch prediction probabilties
320   // 1 in 1,000,000 (magnitude 6)
321   //
322   // Although PROB_NEVER == PROB_MIN and PROB_ALWAYS == PROB_MAX
323   // they are used to distinguish different situations:
324   //
325   // The name PROB_MAX (PROB_MIN) is for probabilities which correspond to
326   // very likely (unlikely) but with a concrete possibility of a rare
327   // contrary case.  These constants would be used for pinning
328   // measurements, and as measures for assertions that have high
329   // confidence, but some evidence of occasional failure.
330   //
331   // The name PROB_ALWAYS (PROB_NEVER) is to stand for situations for which
332   // there is no evidence at all that the contrary case has ever occurred.
333 
334 #define PROB_NEVER              PROB_UNLIKELY_MAG(6)
335 #define PROB_ALWAYS             PROB_LIKELY_MAG(6)
336 
337 #define PROB_MIN                PROB_UNLIKELY_MAG(6)
338 #define PROB_MAX                PROB_LIKELY_MAG(6)
339 
340   // Static branch prediction probabilities
341   // 1 in 10 (magnitude 1)
342 #define PROB_STATIC_INFREQUENT  PROB_UNLIKELY_MAG(1)
343 #define PROB_STATIC_FREQUENT    PROB_LIKELY_MAG(1)
344 
345   // Fair probability 50/50
346 #define PROB_FAIR               (0.5f)
347 
348   // Unknown probability sentinel
349 #define PROB_UNKNOWN            (-1.0f)
350 
351   // Probability "constructors", to distinguish as a probability any manifest
352   // constant without a names
353 #define PROB_LIKELY(x)          ((float) (x))
354 #define PROB_UNLIKELY(x)        (1.0f - (float)(x))
355 
356   // Other probabilities in use, but without a unique name, are documented
357   // here for lack of a better place:
358   //
359   // 1 in 1000 probabilities (magnitude 3):
360   //     threshold for converting to conditional move
361   //     likelihood of null check failure if a null HAS been seen before
362   //     likelihood of slow path taken in library calls
363   //
364   // 1 in 10,000 probabilities (magnitude 4):
365   //     threshold for making an uncommon trap probability more extreme
366   //     threshold for for making a null check implicit
367   //     likelihood of needing a gc if eden top moves during an allocation
368   //     likelihood of a predicted call failure
369   //
370   // 1 in 100,000 probabilities (magnitude 5):
371   //     threshold for ignoring counts when estimating path frequency
372   //     likelihood of FP clipping failure
373   //     likelihood of catching an exception from a try block
374   //     likelihood of null check failure if a null has NOT been seen before
375   //
376   // Magic manifest probabilities such as 0.83, 0.7, ... can be found in
377   // gen_subtype_check() and catch_inline_exceptions().
378 
379   float _prob;                  // Probability of true path being taken.
380   float _fcnt;                  // Frequency counter
381   IfNode( Node *control, Node *b, float p, float fcnt )
382     : MultiBranchNode(2), _prob(p), _fcnt(fcnt) {
383     init_class_id(Class_If);
384     init_req(0,control);
385     init_req(1,b);
386   }
387   virtual int Opcode() const;
388   virtual bool pinned() const { return true; }
389   virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
390   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
391   virtual const Type* Value(PhaseGVN* phase) const;
392   virtual int required_outcnt() const { return 2; }
393   virtual const RegMask &out_RegMask() const;
394   Node* fold_compares(PhaseIterGVN* phase);
395   static Node* up_one_dom(Node* curr, bool linear_only = false);
396   Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn);
397 
398   // Takes the type of val and filters it through the test represented
399   // by if_proj and returns a more refined type if one is produced.
400   // Returns NULL is it couldn't improve the type.
401   static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
402 
403 #ifndef PRODUCT
404   virtual void dump_spec(outputStream *st) const;
405 #endif
406 };
407 
408 class RangeCheckNode : public IfNode {
409 private:
410   int is_range_check(Node* &range, Node* &index, jint &offset);
411 
412 public:
413   RangeCheckNode(Node* control, Node *b, float p, float fcnt)
414     : IfNode(control, b, p, fcnt) {
415     init_class_id(Class_RangeCheck);
416   }
417 
418   virtual int Opcode() const;
419   virtual Node* Ideal(PhaseGVN *phase, bool can_reshape);
420 };
421 
422 class IfProjNode : public CProjNode {
423 public:
424   IfProjNode(IfNode *ifnode, uint idx) : CProjNode(ifnode,idx) {}
425   virtual Node* Identity(PhaseGVN* phase);
426 
427 protected:
428   // Type of If input when this branch is always taken
429   virtual bool always_taken(const TypeTuple* t) const = 0;
430 };
431 
432 class IfTrueNode : public IfProjNode {
433 public:
434   IfTrueNode( IfNode *ifnode ) : IfProjNode(ifnode,1) {
435     init_class_id(Class_IfTrue);
436   }
437   virtual int Opcode() const;
438 
439 protected:
440   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFTRUE; }
441 };
442 
443 class IfFalseNode : public IfProjNode {
444 public:
445   IfFalseNode( IfNode *ifnode ) : IfProjNode(ifnode,0) {
446     init_class_id(Class_IfFalse);
447   }
448   virtual int Opcode() const;
449 
450 protected:
451   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFFALSE; }
452 };
453 
454 
455 //------------------------------PCTableNode------------------------------------
456 // Build an indirect branch table.  Given a control and a table index,
457 // control is passed to the Projection matching the table index.  Used to
458 // implement switch statements and exception-handling capabilities.
459 // Undefined behavior if passed-in index is not inside the table.
460 class PCTableNode : public MultiBranchNode {
461   virtual uint hash() const;    // Target count; table size
462   virtual bool cmp( const Node &n ) const;
463   virtual uint size_of() const { return sizeof(*this); }
464 
465 public:
466   const uint _size;             // Number of targets
467 
468   PCTableNode( Node *ctrl, Node *idx, uint size ) : MultiBranchNode(2), _size(size) {
469     init_class_id(Class_PCTable);
470     init_req(0, ctrl);
471     init_req(1, idx);
472   }
473   virtual int Opcode() const;
474   virtual const Type* Value(PhaseGVN* phase) const;
475   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
476   virtual const Type *bottom_type() const;
477   virtual bool pinned() const { return true; }
478   virtual int required_outcnt() const { return _size; }
479 };
480 
481 //------------------------------JumpNode---------------------------------------
482 // Indirect branch.  Uses PCTable above to implement a switch statement.
483 // It emits as a table load and local branch.
484 class JumpNode : public PCTableNode {
485   virtual uint size_of() const { return sizeof(*this); }
486 public:
487   float* _probs; // probability of each projection
488   float _fcnt;   // total number of times this Jump was executed
489   JumpNode( Node* control, Node* switch_val, uint size, float* probs, float cnt)
490     : PCTableNode(control, switch_val, size),
491       _probs(probs), _fcnt(cnt) {
492     init_class_id(Class_Jump);
493   }
494   virtual int   Opcode() const;
495   virtual const RegMask& out_RegMask() const;
496   virtual const Node* is_block_proj() const { return this; }
497 };
498 
499 class JumpProjNode : public JProjNode {
500   virtual uint hash() const;
501   virtual bool cmp( const Node &n ) const;
502   virtual uint size_of() const { return sizeof(*this); }
503 
504  private:
505   const int  _dest_bci;
506   const uint _proj_no;
507   const int  _switch_val;
508  public:
509   JumpProjNode(Node* jumpnode, uint proj_no, int dest_bci, int switch_val)
510     : JProjNode(jumpnode, proj_no), _dest_bci(dest_bci), _proj_no(proj_no), _switch_val(switch_val) {
511     init_class_id(Class_JumpProj);
512   }
513 
514   virtual int Opcode() const;
515   virtual const Type* bottom_type() const { return Type::CONTROL; }
516   int  dest_bci()    const { return _dest_bci; }
517   int  switch_val()  const { return _switch_val; }
518   uint proj_no()     const { return _proj_no; }
519 #ifndef PRODUCT
520   virtual void dump_spec(outputStream *st) const;
521   virtual void dump_compact_spec(outputStream *st) const;
522 #endif
523 };
524 
525 //------------------------------CatchNode--------------------------------------
526 // Helper node to fork exceptions.  "Catch" catches any exceptions thrown by
527 // a just-prior call.  Looks like a PCTableNode but emits no code - just the
528 // table.  The table lookup and branch is implemented by RethrowNode.
529 class CatchNode : public PCTableNode {
530 public:
531   CatchNode( Node *ctrl, Node *idx, uint size ) : PCTableNode(ctrl,idx,size){
532     init_class_id(Class_Catch);
533   }
534   virtual int Opcode() const;
535   virtual const Type* Value(PhaseGVN* phase) const;
536 };
537 
538 // CatchProjNode controls which exception handler is targeted after a call.
539 // It is passed in the bci of the target handler, or no_handler_bci in case
540 // the projection doesn't lead to an exception handler.
541 class CatchProjNode : public CProjNode {
542   virtual uint hash() const;
543   virtual bool cmp( const Node &n ) const;
544   virtual uint size_of() const { return sizeof(*this); }
545 
546 private:
547   const int _handler_bci;
548 
549 public:
550   enum {
551     fall_through_index =  0,      // the fall through projection index
552     catch_all_index    =  1,      // the projection index for catch-alls
553     no_handler_bci     = -1       // the bci for fall through or catch-all projs
554   };
555 
556   CatchProjNode(Node* catchnode, uint proj_no, int handler_bci)
557     : CProjNode(catchnode, proj_no), _handler_bci(handler_bci) {
558     init_class_id(Class_CatchProj);
559     assert(proj_no != fall_through_index || handler_bci < 0, "fall through case must have bci < 0");
560   }
561 
562   virtual int Opcode() const;
563   virtual Node* Identity(PhaseGVN* phase);
564   virtual const Type *bottom_type() const { return Type::CONTROL; }
565   int  handler_bci() const        { return _handler_bci; }
566   bool is_handler_proj() const    { return _handler_bci >= 0; }
567 #ifndef PRODUCT
568   virtual void dump_spec(outputStream *st) const;
569 #endif
570 };
571 
572 
573 //---------------------------------CreateExNode--------------------------------
574 // Helper node to create the exception coming back from a call
575 class CreateExNode : public TypeNode {
576 public:
577   CreateExNode(const Type* t, Node* control, Node* i_o) : TypeNode(t, 2) {
578     init_req(0, control);
579     init_req(1, i_o);
580   }
581   virtual int Opcode() const;
582   virtual Node* Identity(PhaseGVN* phase);
583   virtual bool pinned() const { return true; }
584   uint match_edge(uint idx) const { return 0; }
585   virtual uint ideal_reg() const { return Op_RegP; }
586 };
587 
588 //------------------------------NeverBranchNode-------------------------------
589 // The never-taken branch.  Used to give the appearance of exiting infinite
590 // loops to those algorithms that like all paths to be reachable.  Encodes
591 // empty.
592 class NeverBranchNode : public MultiBranchNode {
593 public:
594   NeverBranchNode( Node *ctrl ) : MultiBranchNode(1) { init_req(0,ctrl); }
595   virtual int Opcode() const;
596   virtual bool pinned() const { return true; };
597   virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
598   virtual const Type* Value(PhaseGVN* phase) const;
599   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
600   virtual int required_outcnt() const { return 2; }
601   virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { }
602   virtual uint size(PhaseRegAlloc *ra_) const { return 0; }
603 #ifndef PRODUCT
604   virtual void format( PhaseRegAlloc *, outputStream *st ) const;
605 #endif
606 };
607 
608 //------------------------------BlackholeNode----------------------------
609 // Blackhole all arguments. This node would survive through the compiler
610 // the effects on its arguments, and would be finally matched to nothing.
611 class BlackholeNode : public MultiNode {
612 public:
613   BlackholeNode(Node* ctrl) : MultiNode(1) {
614     init_req(TypeFunc::Control, ctrl);
615   }
616   virtual int   Opcode() const;
617   virtual uint ideal_reg() const { return 0; } // not matched in the AD file
618   virtual const Type* bottom_type() const { return TypeTuple::MEMBAR; }
619 
620   const RegMask &in_RegMask(uint idx) const {
621     // Fake the incoming arguments mask for blackholes: accept all registers
622     // and all stack slots. This would avoid any redundant register moves
623     // for blackhole inputs.
624     return RegMask::All;
625   }
626 #ifndef PRODUCT
627   virtual void format(PhaseRegAlloc* ra, outputStream* st) const;
628 #endif
629 };
630 
631 
632 #endif // SHARE_OPTO_CFGNODE_HPP