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