1 /*
   2  * Copyright (c) 1997, 2015, 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_VM_OPTO_CFGNODE_HPP
  26 #define SHARE_VM_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 public:
  68   // Node layout (parallels PhiNode):
  69   enum { Region,                // Generally points to self.
  70          Control                // Control arcs are [1..len)
  71   };
  72 
  73   RegionNode( uint required ) : Node(required) {
  74     init_class_id(Class_Region);
  75     init_req(0,this);
  76   }
  77 
  78   Node* is_copy() const {
  79     const Node* r = _in[Region];
  80     if (r == NULL)
  81       return nonnull_req();
  82     return NULL;  // not a copy!
  83   }
  84   PhiNode* has_phi() const;        // returns an arbitrary phi user, or NULL
  85   PhiNode* has_unique_phi() const; // returns the unique phi user, or NULL
  86   // Is this region node unreachable from root?
  87   bool is_unreachable_region(PhaseGVN *phase) const;
  88   virtual int Opcode() const;
  89   virtual bool pinned() const { return (const Node *)in(0) == this; }
  90   virtual bool  is_CFG   () const { return true; }
  91   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
  92   virtual bool depends_only_on_test() const { return false; }
  93   virtual const Type *bottom_type() const { return Type::CONTROL; }
  94   virtual const Type* Value(PhaseGVN* phase) const;
  95   virtual Node* Identity(PhaseGVN* phase);
  96   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  97   virtual const RegMask &out_RegMask() const;
  98   bool try_clean_mem_phi(PhaseGVN *phase);
  99 };
 100 
 101 //------------------------------JProjNode--------------------------------------
 102 // jump projection for node that produces multiple control-flow paths
 103 class JProjNode : public ProjNode {
 104  public:
 105   JProjNode( Node* ctrl, uint idx ) : ProjNode(ctrl,idx) {}
 106   virtual int Opcode() const;
 107   virtual bool  is_CFG() const { return true; }
 108   virtual uint  hash() const { return NO_HASH; }  // CFG nodes do not hash
 109   virtual const Node* is_block_proj() const { return in(0); }
 110   virtual const RegMask& out_RegMask() const;
 111   virtual uint  ideal_reg() const { return 0; }
 112 };
 113 
 114 //------------------------------PhiNode----------------------------------------
 115 // PhiNodes merge values from different Control paths.  Slot 0 points to the
 116 // controlling RegionNode.  Other slots map 1-for-1 with incoming control flow
 117 // paths to the RegionNode.  For speed reasons (to avoid another pass) we
 118 // can turn PhiNodes into copys in-place by NULL'ing out their RegionNode
 119 // input in slot 0.
 120 class PhiNode : public TypeNode {
 121   const TypePtr* const _adr_type; // non-null only for Type::MEMORY nodes.
 122   const int _inst_id;     // Instance id of the memory slice.
 123   const int _inst_index;  // Alias index of the instance memory slice.
 124   // Array elements references have the same alias_idx but different offset.
 125   const int _inst_offset; // Offset of the instance memory slice.
 126   // Size is bigger to hold the _adr_type field.
 127   virtual uint hash() const;    // Check the type
 128   virtual uint cmp( const Node &n ) const;
 129   virtual uint size_of() const { return sizeof(*this); }
 130 
 131   // Determine if CMoveNode::is_cmove_id can be used at this join point.
 132   Node* is_cmove_id(PhaseTransform* phase, int true_path);
 133 
 134 public:
 135   // Node layout (parallels RegionNode):
 136   enum { Region,                // Control input is the Phi's region.
 137          Input                  // Input values are [1..len)
 138   };
 139 
 140   PhiNode( Node *r, const Type *t, const TypePtr* at = NULL,
 141            const int iid = TypeOopPtr::InstanceTop,
 142            const int iidx = Compile::AliasIdxTop,
 143            const int ioffs = Type::OffsetTop )
 144     : TypeNode(t,r->req()),
 145       _adr_type(at),
 146       _inst_id(iid),
 147       _inst_index(iidx),
 148       _inst_offset(ioffs)
 149   {
 150     init_class_id(Class_Phi);
 151     init_req(0, r);
 152     verify_adr_type();
 153   }
 154   // create a new phi with in edges matching r and set (initially) to x
 155   static PhiNode* make( Node* r, Node* x );
 156   // extra type arguments override the new phi's bottom_type and adr_type
 157   static PhiNode* make( Node* r, Node* x, const Type *t, const TypePtr* at = NULL );
 158   // create a new phi with narrowed memory type
 159   PhiNode* slice_memory(const TypePtr* adr_type) const;
 160   PhiNode* split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const;
 161   // like make(r, x), but does not initialize the in edges to x
 162   static PhiNode* make_blank( Node* r, Node* x );
 163 
 164   // Accessors
 165   RegionNode* region() const { Node* r = in(Region); assert(!r || r->is_Region(), ""); return (RegionNode*)r; }
 166 
 167   Node* is_copy() const {
 168     // The node is a real phi if _in[0] is a Region node.
 169     DEBUG_ONLY(const Node* r = _in[Region];)
 170     assert(r != NULL && r->is_Region(), "Not valid control");
 171     return NULL;  // not a copy!
 172   }
 173 
 174   bool is_tripcount() const;
 175 
 176   // Determine a unique non-trivial input, if any.
 177   // Ignore casts if it helps.  Return NULL on failure.
 178   Node* unique_input(PhaseTransform *phase, bool uncast);
 179   Node* unique_input(PhaseTransform *phase) {
 180     Node* uin = unique_input(phase, false);
 181     if (uin == NULL) {
 182       uin = unique_input(phase, true);
 183     }
 184     return uin;
 185   }
 186 
 187   // Check for a simple dead loop.
 188   enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };
 189   LoopSafety simple_data_loop_check(Node *in) const;
 190   // Is it unsafe data loop? It becomes a dead loop if this phi node removed.
 191   bool is_unsafe_data_reference(Node *in) const;
 192   int  is_diamond_phi(bool check_control_only = false) const;
 193   virtual int Opcode() const;
 194   virtual bool pinned() const { return in(0) != 0; }
 195   virtual const TypePtr *adr_type() const { verify_adr_type(true); return _adr_type; }
 196 
 197   const int inst_id()     const { return _inst_id; }
 198   const int inst_index()  const { return _inst_index; }
 199   const int inst_offset() const { return _inst_offset; }
 200   bool is_same_inst_field(const Type* tp, int id, int index, int offset) {
 201     return type()->basic_type() == tp->basic_type() &&
 202            inst_id()     == id     &&
 203            inst_index()  == index  &&
 204            inst_offset() == offset &&
 205            type()->higher_equal(tp);
 206   }
 207 
 208   virtual const Type* Value(PhaseGVN* phase) const;
 209   virtual Node* Identity(PhaseGVN* phase);
 210   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 211   virtual const RegMask &out_RegMask() const;
 212   virtual const RegMask &in_RegMask(uint) const;
 213 #ifndef PRODUCT
 214   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
 215   virtual void dump_spec(outputStream *st) const;
 216 #endif
 217 #ifdef ASSERT
 218   void verify_adr_type(VectorSet& visited, const TypePtr* at) const;
 219   void verify_adr_type(bool recursive = false) const;
 220 #else //ASSERT
 221   void verify_adr_type(bool recursive = false) const {}
 222 #endif //ASSERT
 223 };
 224 
 225 //------------------------------GotoNode---------------------------------------
 226 // GotoNodes perform direct branches.
 227 class GotoNode : public Node {
 228 public:
 229   GotoNode( Node *control ) : Node(control) {}
 230   virtual int Opcode() const;
 231   virtual bool pinned() const { return true; }
 232   virtual bool  is_CFG() const { return true; }
 233   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
 234   virtual const Node *is_block_proj() const { return this; }
 235   virtual bool depends_only_on_test() const { return false; }
 236   virtual const Type *bottom_type() const { return Type::CONTROL; }
 237   virtual const Type* Value(PhaseGVN* phase) const;
 238   virtual Node* Identity(PhaseGVN* phase);
 239   virtual const RegMask &out_RegMask() const;
 240 
 241 #ifndef PRODUCT
 242   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
 243 #endif
 244 };
 245 
 246 //------------------------------CProjNode--------------------------------------
 247 // control projection for node that produces multiple control-flow paths
 248 class CProjNode : public ProjNode {
 249 public:
 250   CProjNode( Node *ctrl, uint idx ) : ProjNode(ctrl,idx) {}
 251   virtual int Opcode() const;
 252   virtual bool  is_CFG() const { return true; }
 253   virtual uint hash() const { return NO_HASH; }  // CFG nodes do not hash
 254   virtual const Node *is_block_proj() const { return in(0); }
 255   virtual const RegMask &out_RegMask() const;
 256   virtual uint ideal_reg() const { return 0; }
 257 };
 258 
 259 //---------------------------MultiBranchNode-----------------------------------
 260 // This class defines a MultiBranchNode, a MultiNode which yields multiple
 261 // control values. These are distinguished from other types of MultiNodes
 262 // which yield multiple values, but control is always and only projection #0.
 263 class MultiBranchNode : public MultiNode {
 264 public:
 265   MultiBranchNode( uint required ) : MultiNode(required) {
 266     init_class_id(Class_MultiBranch);
 267   }
 268   // returns required number of users to be well formed.
 269   virtual int required_outcnt() const = 0;
 270 };
 271 
 272 //------------------------------IfNode-----------------------------------------
 273 // Output selected Control, based on a boolean test
 274 class IfNode : public MultiBranchNode {
 275   // Size is bigger to hold the probability field.  However, _prob does not
 276   // change the semantics so it does not appear in the hash & cmp functions.
 277   virtual uint size_of() const { return sizeof(*this); }
 278 
 279 private:
 280   ProjNode* range_check_trap_proj() {
 281     int flip_test = 0;
 282     Node* l = NULL;
 283     Node* r = NULL;
 284     return range_check_trap_proj(flip_test, l, r);
 285   }
 286 
 287   // Helper methods for fold_compares
 288   bool cmpi_folds(PhaseIterGVN* igvn);
 289   bool is_ctrl_folds(Node* ctrl, PhaseIterGVN* igvn);
 290   bool has_shared_region(ProjNode* proj, ProjNode*& success, ProjNode*& fail);
 291   bool has_only_uncommon_traps(ProjNode* proj, ProjNode*& success, ProjNode*& fail, PhaseIterGVN* igvn);
 292   Node* merge_uncommon_traps(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
 293   static void improve_address_types(Node* l, Node* r, ProjNode* fail, PhaseIterGVN* igvn);
 294   bool is_cmp_with_loadrange(ProjNode* proj);
 295   bool is_null_check(ProjNode* proj, PhaseIterGVN* igvn);
 296   bool is_side_effect_free_test(ProjNode* proj, PhaseIterGVN* igvn);
 297   void reroute_side_effect_free_unc(ProjNode* proj, ProjNode* dom_proj, PhaseIterGVN* igvn);
 298   ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call) const;
 299   bool fold_compares_helper(ProjNode* proj, ProjNode* success, ProjNode* fail, PhaseIterGVN* igvn);
 300 
 301 protected:
 302   ProjNode* range_check_trap_proj(int& flip, Node*& l, Node*& r);
 303   Node* Ideal_common(PhaseGVN *phase, bool can_reshape);
 304   Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn);
 305   Node* search_identical(int dist);
 306 
 307 public:
 308 
 309   // Degrees of branch prediction probability by order of magnitude:
 310   // PROB_UNLIKELY_1e(N) is a 1 in 1eN chance.
 311   // PROB_LIKELY_1e(N) is a 1 - PROB_UNLIKELY_1e(N)
 312 #define PROB_UNLIKELY_MAG(N)    (1e- ## N ## f)
 313 #define PROB_LIKELY_MAG(N)      (1.0f-PROB_UNLIKELY_MAG(N))
 314 
 315   // Maximum and minimum branch prediction probabilties
 316   // 1 in 1,000,000 (magnitude 6)
 317   //
 318   // Although PROB_NEVER == PROB_MIN and PROB_ALWAYS == PROB_MAX
 319   // they are used to distinguish different situations:
 320   //
 321   // The name PROB_MAX (PROB_MIN) is for probabilities which correspond to
 322   // very likely (unlikely) but with a concrete possibility of a rare
 323   // contrary case.  These constants would be used for pinning
 324   // measurements, and as measures for assertions that have high
 325   // confidence, but some evidence of occasional failure.
 326   //
 327   // The name PROB_ALWAYS (PROB_NEVER) is to stand for situations for which
 328   // there is no evidence at all that the contrary case has ever occurred.
 329 
 330 #define PROB_NEVER              PROB_UNLIKELY_MAG(6)
 331 #define PROB_ALWAYS             PROB_LIKELY_MAG(6)
 332 
 333 #define PROB_MIN                PROB_UNLIKELY_MAG(6)
 334 #define PROB_MAX                PROB_LIKELY_MAG(6)
 335 
 336   // Static branch prediction probabilities
 337   // 1 in 10 (magnitude 1)
 338 #define PROB_STATIC_INFREQUENT  PROB_UNLIKELY_MAG(1)
 339 #define PROB_STATIC_FREQUENT    PROB_LIKELY_MAG(1)
 340 
 341   // Fair probability 50/50
 342 #define PROB_FAIR               (0.5f)
 343 
 344   // Unknown probability sentinel
 345 #define PROB_UNKNOWN            (-1.0f)
 346 
 347   // Probability "constructors", to distinguish as a probability any manifest
 348   // constant without a names
 349 #define PROB_LIKELY(x)          ((float) (x))
 350 #define PROB_UNLIKELY(x)        (1.0f - (float)(x))
 351 
 352   // Other probabilities in use, but without a unique name, are documented
 353   // here for lack of a better place:
 354   //
 355   // 1 in 1000 probabilities (magnitude 3):
 356   //     threshold for converting to conditional move
 357   //     likelihood of null check failure if a null HAS been seen before
 358   //     likelihood of slow path taken in library calls
 359   //
 360   // 1 in 10,000 probabilities (magnitude 4):
 361   //     threshold for making an uncommon trap probability more extreme
 362   //     threshold for for making a null check implicit
 363   //     likelihood of needing a gc if eden top moves during an allocation
 364   //     likelihood of a predicted call failure
 365   //
 366   // 1 in 100,000 probabilities (magnitude 5):
 367   //     threshold for ignoring counts when estimating path frequency
 368   //     likelihood of FP clipping failure
 369   //     likelihood of catching an exception from a try block
 370   //     likelihood of null check failure if a null has NOT been seen before
 371   //
 372   // Magic manifest probabilities such as 0.83, 0.7, ... can be found in
 373   // gen_subtype_check() and catch_inline_exceptions().
 374 
 375   float _prob;                  // Probability of true path being taken.
 376   float _fcnt;                  // Frequency counter
 377   IfNode( Node *control, Node *b, float p, float fcnt )
 378     : MultiBranchNode(2), _prob(p), _fcnt(fcnt) {
 379     init_class_id(Class_If);
 380     init_req(0,control);
 381     init_req(1,b);
 382   }
 383   virtual int Opcode() const;
 384   virtual bool pinned() const { return true; }
 385   virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
 386   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 387   virtual const Type* Value(PhaseGVN* phase) const;
 388   virtual int required_outcnt() const { return 2; }
 389   virtual const RegMask &out_RegMask() const;
 390   Node* fold_compares(PhaseIterGVN* phase);
 391   static Node* up_one_dom(Node* curr, bool linear_only = false);
 392 
 393   // Takes the type of val and filters it through the test represented
 394   // by if_proj and returns a more refined type if one is produced.
 395   // Returns NULL is it couldn't improve the type.
 396   static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
 397 
 398 #ifndef PRODUCT
 399   virtual void dump_spec(outputStream *st) const;
 400   virtual void related(GrowableArray <Node *> *in_rel, GrowableArray <Node *> *out_rel, bool compact) const;
 401 #endif
 402 };
 403 
 404 class RangeCheckNode : public IfNode {
 405 private:
 406   int is_range_check(Node* &range, Node* &index, jint &offset);
 407 
 408 public:
 409   RangeCheckNode(Node* control, Node *b, float p, float fcnt)
 410     : IfNode(control, b, p, fcnt) {
 411     init_class_id(Class_RangeCheck);
 412   }
 413 
 414   virtual int Opcode() const;
 415   virtual Node* Ideal(PhaseGVN *phase, bool can_reshape);
 416 };
 417 
 418 class IfProjNode : public CProjNode {
 419 public:
 420   IfProjNode(IfNode *ifnode, uint idx) : CProjNode(ifnode,idx) {}
 421   virtual Node* Identity(PhaseGVN* phase);
 422 
 423 protected:
 424   // Type of If input when this branch is always taken
 425   virtual bool always_taken(const TypeTuple* t) const = 0;
 426 
 427 #ifndef PRODUCT
 428 public:
 429   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
 430 #endif
 431 };
 432 
 433 class IfTrueNode : public IfProjNode {
 434 public:
 435   IfTrueNode( IfNode *ifnode ) : IfProjNode(ifnode,1) {
 436     init_class_id(Class_IfTrue);
 437   }
 438   virtual int Opcode() const;
 439 
 440 protected:
 441   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFTRUE; }
 442 };
 443 
 444 class IfFalseNode : public IfProjNode {
 445 public:
 446   IfFalseNode( IfNode *ifnode ) : IfProjNode(ifnode,0) {
 447     init_class_id(Class_IfFalse);
 448   }
 449   virtual int Opcode() const;
 450 
 451 protected:
 452   virtual bool always_taken(const TypeTuple* t) const { return t == TypeTuple::IFFALSE; }
 453 };
 454 
 455 
 456 //------------------------------PCTableNode------------------------------------
 457 // Build an indirect branch table.  Given a control and a table index,
 458 // control is passed to the Projection matching the table index.  Used to
 459 // implement switch statements and exception-handling capabilities.
 460 // Undefined behavior if passed-in index is not inside the table.
 461 class PCTableNode : public MultiBranchNode {
 462   virtual uint hash() const;    // Target count; table size
 463   virtual uint cmp( const Node &n ) const;
 464   virtual uint size_of() const { return sizeof(*this); }
 465 
 466 public:
 467   const uint _size;             // Number of targets
 468 
 469   PCTableNode( Node *ctrl, Node *idx, uint size ) : MultiBranchNode(2), _size(size) {
 470     init_class_id(Class_PCTable);
 471     init_req(0, ctrl);
 472     init_req(1, idx);
 473   }
 474   virtual int Opcode() const;
 475   virtual const Type* Value(PhaseGVN* phase) const;
 476   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 477   virtual const Type *bottom_type() const;
 478   virtual bool pinned() const { return true; }
 479   virtual int required_outcnt() const { return _size; }
 480 };
 481 
 482 //------------------------------JumpNode---------------------------------------
 483 // Indirect branch.  Uses PCTable above to implement a switch statement.
 484 // It emits as a table load and local branch.
 485 class JumpNode : public PCTableNode {
 486 public:
 487   JumpNode( Node* control, Node* switch_val, uint size) : PCTableNode(control, switch_val, size) {
 488     init_class_id(Class_Jump);
 489   }
 490   virtual int   Opcode() const;
 491   virtual const RegMask& out_RegMask() const;
 492   virtual const Node* is_block_proj() const { return this; }
 493 #ifndef PRODUCT
 494   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) const;
 495 #endif
 496 };
 497 
 498 class JumpProjNode : public JProjNode {
 499   virtual uint hash() const;
 500   virtual uint cmp( const Node &n ) const;
 501   virtual uint size_of() const { return sizeof(*this); }
 502 
 503  private:
 504   const int  _dest_bci;
 505   const uint _proj_no;
 506   const int  _switch_val;
 507  public:
 508   JumpProjNode(Node* jumpnode, uint proj_no, int dest_bci, int switch_val)
 509     : JProjNode(jumpnode, proj_no), _dest_bci(dest_bci), _proj_no(proj_no), _switch_val(switch_val) {
 510     init_class_id(Class_JumpProj);
 511   }
 512 
 513   virtual int Opcode() const;
 514   virtual const Type* bottom_type() const { return Type::CONTROL; }
 515   int  dest_bci()    const { return _dest_bci; }
 516   int  switch_val()  const { return _switch_val; }
 517   uint proj_no()     const { return _proj_no; }
 518 #ifndef PRODUCT
 519   virtual void dump_spec(outputStream *st) const;
 520   virtual void dump_compact_spec(outputStream *st) const;
 521   virtual void related(GrowableArray<Node*> *in_rel, GrowableArray<Node*> *out_rel, bool compact) 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 targetted 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 uint 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 #endif // SHARE_VM_OPTO_CFGNODE_HPP