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