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