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