1 /* 2 * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2024, Alibaba Group Holding Limited. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef SHARE_OPTO_MEMNODE_HPP 27 #define SHARE_OPTO_MEMNODE_HPP 28 29 #include "opto/multnode.hpp" 30 #include "opto/node.hpp" 31 #include "opto/opcodes.hpp" 32 #include "opto/type.hpp" 33 34 // Portions of code courtesy of Clifford Click 35 36 class MultiNode; 37 class PhaseCCP; 38 class PhaseTransform; 39 40 //------------------------------MemNode---------------------------------------- 41 // Load or Store, possibly throwing a null pointer exception 42 class MemNode : public Node { 43 private: 44 bool _unaligned_access; // Unaligned access from unsafe 45 bool _mismatched_access; // Mismatched access from unsafe: byte read in integer array for instance 46 bool _unsafe_access; // Access of unsafe origin. 47 uint8_t _barrier_data; // Bit field with barrier information 48 49 protected: 50 #ifdef ASSERT 51 const TypePtr* _adr_type; // What kind of memory is being addressed? 52 #endif 53 virtual uint size_of() const; 54 public: 55 enum { Control, // When is it safe to do this load? 56 Memory, // Chunk of memory is being loaded from 57 Address, // Actually address, derived from base 58 ValueIn, // Value to store 59 OopStore // Preceding oop store, only in StoreCM 60 }; 61 typedef enum { unordered = 0, 62 acquire, // Load has to acquire or be succeeded by MemBarAcquire. 63 release, // Store has to release or be preceded by MemBarRelease. 64 seqcst, // LoadStore has to have both acquire and release semantics. 65 unset // The memory ordering is not set (used for testing) 66 } MemOrd; 67 protected: 68 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at ) : 69 Node(c0,c1,c2), 70 _unaligned_access(false), 71 _mismatched_access(false), 72 _unsafe_access(false), 73 _barrier_data(0) { 74 init_class_id(Class_Mem); 75 debug_only(_adr_type=at; adr_type();) 76 } 77 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 ) : 78 Node(c0,c1,c2,c3), 79 _unaligned_access(false), 80 _mismatched_access(false), 81 _unsafe_access(false), 82 _barrier_data(0) { 83 init_class_id(Class_Mem); 84 debug_only(_adr_type=at; adr_type();) 85 } 86 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4) : 87 Node(c0,c1,c2,c3,c4), 88 _unaligned_access(false), 89 _mismatched_access(false), 90 _unsafe_access(false), 91 _barrier_data(0) { 92 init_class_id(Class_Mem); 93 debug_only(_adr_type=at; adr_type();) 94 } 95 96 virtual Node* find_previous_arraycopy(PhaseValues* phase, Node* ld_alloc, Node*& mem, bool can_see_stored_value) const { return nullptr; } 97 ArrayCopyNode* find_array_copy_clone(Node* ld_alloc, Node* mem) const; 98 static bool check_if_adr_maybe_raw(Node* adr); 99 100 public: 101 // Helpers for the optimizer. Documented in memnode.cpp. 102 static bool detect_ptr_independence(Node* p1, AllocateNode* a1, 103 Node* p2, AllocateNode* a2, 104 PhaseTransform* phase); 105 static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast); 106 107 static Node *optimize_simple_memory_chain(Node *mchain, const TypeOopPtr *t_oop, Node *load, PhaseGVN *phase); 108 static Node *optimize_memory_chain(Node *mchain, const TypePtr *t_adr, Node *load, PhaseGVN *phase); 109 // The following two should probably be phase-specific functions: 110 static DomResult maybe_all_controls_dominate(Node* dom, Node* sub); 111 static bool all_controls_dominate(Node* dom, Node* sub) { 112 DomResult dom_result = maybe_all_controls_dominate(dom, sub); 113 return dom_result == DomResult::Dominate; 114 } 115 116 virtual const class TypePtr *adr_type() const; // returns bottom_type of address 117 118 // Shared code for Ideal methods: 119 Node *Ideal_common(PhaseGVN *phase, bool can_reshape); // Return -1 for short-circuit null. 120 121 // Helper function for adr_type() implementations. 122 static const TypePtr* calculate_adr_type(const Type* t, const TypePtr* cross_check = nullptr); 123 124 // Raw access function, to allow copying of adr_type efficiently in 125 // product builds and retain the debug info for debug builds. 126 const TypePtr *raw_adr_type() const { 127 #ifdef ASSERT 128 return _adr_type; 129 #else 130 return 0; 131 #endif 132 } 133 134 // Return the barrier data of n, if available, or 0 otherwise. 135 static uint8_t barrier_data(const Node* n); 136 137 // Map a load or store opcode to its corresponding store opcode. 138 // (Return -1 if unknown.) 139 virtual int store_Opcode() const { return -1; } 140 141 // What is the type of the value in memory? (T_VOID mean "unspecified".) 142 virtual BasicType memory_type() const = 0; 143 virtual int memory_size() const { 144 #ifdef ASSERT 145 return type2aelembytes(memory_type(), true); 146 #else 147 return type2aelembytes(memory_type()); 148 #endif 149 } 150 151 uint8_t barrier_data() { return _barrier_data; } 152 void set_barrier_data(uint8_t barrier_data) { _barrier_data = barrier_data; } 153 154 // Search through memory states which precede this node (load or store). 155 // Look for an exact match for the address, with no intervening 156 // aliased stores. 157 Node* find_previous_store(PhaseValues* phase); 158 159 // Can this node (load or store) accurately see a stored value in 160 // the given memory state? (The state may or may not be in(Memory).) 161 Node* can_see_stored_value(Node* st, PhaseValues* phase) const; 162 163 void set_unaligned_access() { _unaligned_access = true; } 164 bool is_unaligned_access() const { return _unaligned_access; } 165 void set_mismatched_access() { _mismatched_access = true; } 166 bool is_mismatched_access() const { return _mismatched_access; } 167 void set_unsafe_access() { _unsafe_access = true; } 168 bool is_unsafe_access() const { return _unsafe_access; } 169 170 #ifndef PRODUCT 171 static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st); 172 virtual void dump_spec(outputStream *st) const; 173 #endif 174 }; 175 176 //------------------------------LoadNode--------------------------------------- 177 // Load value; requires Memory and Address 178 class LoadNode : public MemNode { 179 public: 180 // Some loads (from unsafe) should be pinned: they don't depend only 181 // on the dominating test. The field _control_dependency below records 182 // whether that node depends only on the dominating test. 183 // Pinned and UnknownControl are similar, but differ in that Pinned 184 // loads are not allowed to float across safepoints, whereas UnknownControl 185 // loads are allowed to do that. Therefore, Pinned is stricter. 186 enum ControlDependency { 187 Pinned, 188 UnknownControl, 189 DependsOnlyOnTest 190 }; 191 192 private: 193 // LoadNode::hash() doesn't take the _control_dependency field 194 // into account: If the graph already has a non-pinned LoadNode and 195 // we add a pinned LoadNode with the same inputs, it's safe for GVN 196 // to replace the pinned LoadNode with the non-pinned LoadNode, 197 // otherwise it wouldn't be safe to have a non pinned LoadNode with 198 // those inputs in the first place. If the graph already has a 199 // pinned LoadNode and we add a non pinned LoadNode with the same 200 // inputs, it's safe (but suboptimal) for GVN to replace the 201 // non-pinned LoadNode by the pinned LoadNode. 202 ControlDependency _control_dependency; 203 204 // On platforms with weak memory ordering (e.g., PPC, Ia64) we distinguish 205 // loads that can be reordered, and such requiring acquire semantics to 206 // adhere to the Java specification. The required behaviour is stored in 207 // this field. 208 const MemOrd _mo; 209 210 AllocateNode* is_new_object_mark_load() const; 211 212 protected: 213 virtual bool cmp(const Node &n) const; 214 virtual uint size_of() const; // Size is bigger 215 // Should LoadNode::Ideal() attempt to remove control edges? 216 virtual bool can_remove_control() const; 217 const Type* const _type; // What kind of value is loaded? 218 219 virtual Node* find_previous_arraycopy(PhaseValues* phase, Node* ld_alloc, Node*& mem, bool can_see_stored_value) const; 220 public: 221 222 LoadNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt, MemOrd mo, ControlDependency control_dependency) 223 : MemNode(c,mem,adr,at), _control_dependency(control_dependency), _mo(mo), _type(rt) { 224 init_class_id(Class_Load); 225 } 226 inline bool is_unordered() const { return !is_acquire(); } 227 inline bool is_acquire() const { 228 assert(_mo == unordered || _mo == acquire, "unexpected"); 229 return _mo == acquire; 230 } 231 inline bool is_unsigned() const { 232 int lop = Opcode(); 233 return (lop == Op_LoadUB) || (lop == Op_LoadUS); 234 } 235 236 // Polymorphic factory method: 237 static Node* make(PhaseGVN& gvn, Node* c, Node* mem, Node* adr, 238 const TypePtr* at, const Type* rt, BasicType bt, 239 MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest, 240 bool require_atomic_access = false, bool unaligned = false, bool mismatched = false, bool unsafe = false, 241 uint8_t barrier_data = 0); 242 243 virtual uint hash() const; // Check the type 244 245 // Handle algebraic identities here. If we have an identity, return the Node 246 // we are equivalent to. We look for Load of a Store. 247 virtual Node* Identity(PhaseGVN* phase); 248 249 // If the load is from Field memory and the pointer is non-null, it might be possible to 250 // zero out the control input. 251 // If the offset is constant and the base is an object allocation, 252 // try to hook me up to the exact initializing store. 253 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 254 255 // Return true if it's possible to split the Load through a Phi merging the bases 256 bool can_split_through_phi_base(PhaseGVN *phase); 257 258 // Split instance field load through Phi. 259 Node* split_through_phi(PhaseGVN *phase, bool ignore_missing_instance_id = false); 260 261 // Recover original value from boxed values 262 Node *eliminate_autobox(PhaseIterGVN *igvn); 263 264 // Compute a new Type for this node. Basically we just do the pre-check, 265 // then call the virtual add() to set the type. 266 virtual const Type* Value(PhaseGVN* phase) const; 267 268 // Common methods for LoadKlass and LoadNKlass nodes. 269 const Type* klass_value_common(PhaseGVN* phase) const; 270 Node* klass_identity_common(PhaseGVN* phase); 271 272 virtual uint ideal_reg() const; 273 virtual const Type *bottom_type() const; 274 // Following method is copied from TypeNode: 275 void set_type(const Type* t) { 276 assert(t != nullptr, "sanity"); 277 debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH); 278 *(const Type**)&_type = t; // cast away const-ness 279 // If this node is in the hash table, make sure it doesn't need a rehash. 280 assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code"); 281 } 282 const Type* type() const { assert(_type != nullptr, "sanity"); return _type; }; 283 284 // Do not match memory edge 285 virtual uint match_edge(uint idx) const; 286 287 // Map a load opcode to its corresponding store opcode. 288 virtual int store_Opcode() const = 0; 289 290 // Check if the load's memory input is a Phi node with the same control. 291 bool is_instance_field_load_with_local_phi(Node* ctrl); 292 293 Node* convert_to_unsigned_load(PhaseGVN& gvn); 294 Node* convert_to_signed_load(PhaseGVN& gvn); 295 296 bool has_reinterpret_variant(const Type* rt); 297 Node* convert_to_reinterpret_load(PhaseGVN& gvn, const Type* rt); 298 299 ControlDependency control_dependency() const { return _control_dependency; } 300 bool has_unknown_control_dependency() const { return _control_dependency == UnknownControl; } 301 bool has_pinned_control_dependency() const { return _control_dependency == Pinned; } 302 303 LoadNode* pin_array_access_node() const; 304 305 #ifndef PRODUCT 306 virtual void dump_spec(outputStream *st) const; 307 #endif 308 #ifdef ASSERT 309 // Helper function to allow a raw load without control edge for some cases 310 static bool is_immutable_value(Node* adr); 311 #endif 312 protected: 313 const Type* load_array_final_field(const TypeKlassPtr *tkls, 314 ciKlass* klass) const; 315 316 Node* can_see_arraycopy_value(Node* st, PhaseGVN* phase) const; 317 318 // depends_only_on_test is almost always true, and needs to be almost always 319 // true to enable key hoisting & commoning optimizations. However, for the 320 // special case of RawPtr loads from TLS top & end, and other loads performed by 321 // GC barriers, the control edge carries the dependence preventing hoisting past 322 // a Safepoint instead of the memory edge. (An unfortunate consequence of having 323 // Safepoints not set Raw Memory; itself an unfortunate consequence of having Nodes 324 // which produce results (new raw memory state) inside of loops preventing all 325 // manner of other optimizations). Basically, it's ugly but so is the alternative. 326 // See comment in macro.cpp, around line 125 expand_allocate_common(). 327 virtual bool depends_only_on_test() const { 328 return adr_type() != TypeRawPtr::BOTTOM && _control_dependency == DependsOnlyOnTest; 329 } 330 331 LoadNode* clone_pinned() const; 332 }; 333 334 //------------------------------LoadBNode-------------------------------------- 335 // Load a byte (8bits signed) from memory 336 class LoadBNode : public LoadNode { 337 public: 338 LoadBNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 339 : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {} 340 virtual int Opcode() const; 341 virtual uint ideal_reg() const { return Op_RegI; } 342 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 343 virtual const Type* Value(PhaseGVN* phase) const; 344 virtual int store_Opcode() const { return Op_StoreB; } 345 virtual BasicType memory_type() const { return T_BYTE; } 346 }; 347 348 //------------------------------LoadUBNode------------------------------------- 349 // Load a unsigned byte (8bits unsigned) from memory 350 class LoadUBNode : public LoadNode { 351 public: 352 LoadUBNode(Node* c, Node* mem, Node* adr, const TypePtr* at, const TypeInt* ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 353 : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {} 354 virtual int Opcode() const; 355 virtual uint ideal_reg() const { return Op_RegI; } 356 virtual Node* Ideal(PhaseGVN *phase, bool can_reshape); 357 virtual const Type* Value(PhaseGVN* phase) const; 358 virtual int store_Opcode() const { return Op_StoreB; } 359 virtual BasicType memory_type() const { return T_BYTE; } 360 }; 361 362 //------------------------------LoadUSNode------------------------------------- 363 // Load an unsigned short/char (16bits unsigned) from memory 364 class LoadUSNode : public LoadNode { 365 public: 366 LoadUSNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 367 : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {} 368 virtual int Opcode() const; 369 virtual uint ideal_reg() const { return Op_RegI; } 370 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 371 virtual const Type* Value(PhaseGVN* phase) const; 372 virtual int store_Opcode() const { return Op_StoreC; } 373 virtual BasicType memory_type() const { return T_CHAR; } 374 }; 375 376 //------------------------------LoadSNode-------------------------------------- 377 // Load a short (16bits signed) from memory 378 class LoadSNode : public LoadNode { 379 public: 380 LoadSNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 381 : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {} 382 virtual int Opcode() const; 383 virtual uint ideal_reg() const { return Op_RegI; } 384 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 385 virtual const Type* Value(PhaseGVN* phase) const; 386 virtual int store_Opcode() const { return Op_StoreC; } 387 virtual BasicType memory_type() const { return T_SHORT; } 388 }; 389 390 //------------------------------LoadINode-------------------------------------- 391 // Load an integer from memory 392 class LoadINode : public LoadNode { 393 public: 394 LoadINode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 395 : LoadNode(c, mem, adr, at, ti, mo, control_dependency) {} 396 virtual int Opcode() const; 397 virtual uint ideal_reg() const { return Op_RegI; } 398 virtual int store_Opcode() const { return Op_StoreI; } 399 virtual BasicType memory_type() const { return T_INT; } 400 }; 401 402 //------------------------------LoadRangeNode---------------------------------- 403 // Load an array length from the array 404 class LoadRangeNode : public LoadINode { 405 public: 406 LoadRangeNode(Node *c, Node *mem, Node *adr, const TypeInt *ti = TypeInt::POS) 407 : LoadINode(c, mem, adr, TypeAryPtr::RANGE, ti, MemNode::unordered) {} 408 virtual int Opcode() const; 409 virtual const Type* Value(PhaseGVN* phase) const; 410 virtual Node* Identity(PhaseGVN* phase); 411 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 412 }; 413 414 //------------------------------LoadLNode-------------------------------------- 415 // Load a long from memory 416 class LoadLNode : public LoadNode { 417 virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; } 418 virtual bool cmp( const Node &n ) const { 419 return _require_atomic_access == ((LoadLNode&)n)._require_atomic_access 420 && LoadNode::cmp(n); 421 } 422 virtual uint size_of() const { return sizeof(*this); } 423 const bool _require_atomic_access; // is piecewise load forbidden? 424 425 public: 426 LoadLNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeLong *tl, 427 MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest, bool require_atomic_access = false) 428 : LoadNode(c, mem, adr, at, tl, mo, control_dependency), _require_atomic_access(require_atomic_access) {} 429 virtual int Opcode() const; 430 virtual uint ideal_reg() const { return Op_RegL; } 431 virtual int store_Opcode() const { return Op_StoreL; } 432 virtual BasicType memory_type() const { return T_LONG; } 433 bool require_atomic_access() const { return _require_atomic_access; } 434 435 #ifndef PRODUCT 436 virtual void dump_spec(outputStream *st) const { 437 LoadNode::dump_spec(st); 438 if (_require_atomic_access) st->print(" Atomic!"); 439 } 440 #endif 441 }; 442 443 //------------------------------LoadL_unalignedNode---------------------------- 444 // Load a long from unaligned memory 445 class LoadL_unalignedNode : public LoadLNode { 446 public: 447 LoadL_unalignedNode(Node *c, Node *mem, Node *adr, const TypePtr* at, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 448 : LoadLNode(c, mem, adr, at, TypeLong::LONG, mo, control_dependency) {} 449 virtual int Opcode() const; 450 }; 451 452 //------------------------------LoadFNode-------------------------------------- 453 // Load a float (64 bits) from memory 454 class LoadFNode : public LoadNode { 455 public: 456 LoadFNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 457 : LoadNode(c, mem, adr, at, t, mo, control_dependency) {} 458 virtual int Opcode() const; 459 virtual uint ideal_reg() const { return Op_RegF; } 460 virtual int store_Opcode() const { return Op_StoreF; } 461 virtual BasicType memory_type() const { return T_FLOAT; } 462 }; 463 464 //------------------------------LoadDNode-------------------------------------- 465 // Load a double (64 bits) from memory 466 class LoadDNode : public LoadNode { 467 virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; } 468 virtual bool cmp( const Node &n ) const { 469 return _require_atomic_access == ((LoadDNode&)n)._require_atomic_access 470 && LoadNode::cmp(n); 471 } 472 virtual uint size_of() const { return sizeof(*this); } 473 const bool _require_atomic_access; // is piecewise load forbidden? 474 475 public: 476 LoadDNode(Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t, 477 MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest, bool require_atomic_access = false) 478 : LoadNode(c, mem, adr, at, t, mo, control_dependency), _require_atomic_access(require_atomic_access) {} 479 virtual int Opcode() const; 480 virtual uint ideal_reg() const { return Op_RegD; } 481 virtual int store_Opcode() const { return Op_StoreD; } 482 virtual BasicType memory_type() const { return T_DOUBLE; } 483 bool require_atomic_access() const { return _require_atomic_access; } 484 485 #ifndef PRODUCT 486 virtual void dump_spec(outputStream *st) const { 487 LoadNode::dump_spec(st); 488 if (_require_atomic_access) st->print(" Atomic!"); 489 } 490 #endif 491 }; 492 493 //------------------------------LoadD_unalignedNode---------------------------- 494 // Load a double from unaligned memory 495 class LoadD_unalignedNode : public LoadDNode { 496 public: 497 LoadD_unalignedNode(Node *c, Node *mem, Node *adr, const TypePtr* at, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 498 : LoadDNode(c, mem, adr, at, Type::DOUBLE, mo, control_dependency) {} 499 virtual int Opcode() const; 500 }; 501 502 //------------------------------LoadPNode-------------------------------------- 503 // Load a pointer from memory (either object or array) 504 class LoadPNode : public LoadNode { 505 public: 506 LoadPNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypePtr* t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 507 : LoadNode(c, mem, adr, at, t, mo, control_dependency) {} 508 virtual int Opcode() const; 509 virtual uint ideal_reg() const { return Op_RegP; } 510 virtual int store_Opcode() const { return Op_StoreP; } 511 virtual BasicType memory_type() const { return T_ADDRESS; } 512 }; 513 514 515 //------------------------------LoadNNode-------------------------------------- 516 // Load a narrow oop from memory (either object or array) 517 class LoadNNode : public LoadNode { 518 public: 519 LoadNNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const Type* t, MemOrd mo, ControlDependency control_dependency = DependsOnlyOnTest) 520 : LoadNode(c, mem, adr, at, t, mo, control_dependency) {} 521 virtual int Opcode() const; 522 virtual uint ideal_reg() const { return Op_RegN; } 523 virtual int store_Opcode() const { return Op_StoreN; } 524 virtual BasicType memory_type() const { return T_NARROWOOP; } 525 }; 526 527 //------------------------------LoadKlassNode---------------------------------- 528 // Load a Klass from an object 529 class LoadKlassNode : public LoadPNode { 530 protected: 531 // In most cases, LoadKlassNode does not have the control input set. If the control 532 // input is set, it must not be removed (by LoadNode::Ideal()). 533 virtual bool can_remove_control() const; 534 public: 535 LoadKlassNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeKlassPtr *tk, MemOrd mo) 536 : LoadPNode(c, mem, adr, at, tk, mo) {} 537 virtual int Opcode() const; 538 virtual const Type* Value(PhaseGVN* phase) const; 539 virtual Node* Identity(PhaseGVN* phase); 540 virtual bool depends_only_on_test() const { return true; } 541 542 // Polymorphic factory method: 543 static Node* make(PhaseGVN& gvn, Node* ctl, Node* mem, Node* adr, const TypePtr* at, 544 const TypeKlassPtr* tk = TypeInstKlassPtr::OBJECT); 545 }; 546 547 //------------------------------LoadNKlassNode--------------------------------- 548 // Load a narrow Klass from an object. 549 class LoadNKlassNode : public LoadNNode { 550 public: 551 LoadNKlassNode(Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeNarrowKlass *tk, MemOrd mo) 552 : LoadNNode(c, mem, adr, at, tk, mo) {} 553 virtual int Opcode() const; 554 virtual uint ideal_reg() const { return Op_RegN; } 555 virtual int store_Opcode() const { return Op_StoreNKlass; } 556 virtual BasicType memory_type() const { return T_NARROWKLASS; } 557 558 virtual const Type* Value(PhaseGVN* phase) const; 559 virtual Node* Identity(PhaseGVN* phase); 560 virtual bool depends_only_on_test() const { return true; } 561 }; 562 563 564 //------------------------------StoreNode-------------------------------------- 565 // Store value; requires Store, Address and Value 566 class StoreNode : public MemNode { 567 private: 568 // On platforms with weak memory ordering (e.g., PPC, Ia64) we distinguish 569 // stores that can be reordered, and such requiring release semantics to 570 // adhere to the Java specification. The required behaviour is stored in 571 // this field. 572 const MemOrd _mo; 573 // Needed for proper cloning. 574 virtual uint size_of() const { return sizeof(*this); } 575 protected: 576 virtual bool cmp( const Node &n ) const; 577 virtual bool depends_only_on_test() const { return false; } 578 579 Node *Ideal_masked_input (PhaseGVN *phase, uint mask); 580 Node *Ideal_sign_extended_input(PhaseGVN *phase, int num_bits); 581 582 public: 583 // We must ensure that stores of object references will be visible 584 // only after the object's initialization. So the callers of this 585 // procedure must indicate that the store requires `release' 586 // semantics, if the stored value is an object reference that might 587 // point to a new object and may become externally visible. 588 StoreNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 589 : MemNode(c, mem, adr, at, val), _mo(mo) { 590 init_class_id(Class_Store); 591 } 592 StoreNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store, MemOrd mo) 593 : MemNode(c, mem, adr, at, val, oop_store), _mo(mo) { 594 init_class_id(Class_Store); 595 } 596 597 inline bool is_unordered() const { return !is_release(); } 598 inline bool is_release() const { 599 assert((_mo == unordered || _mo == release), "unexpected"); 600 return _mo == release; 601 } 602 603 // Conservatively release stores of object references in order to 604 // ensure visibility of object initialization. 605 static inline MemOrd release_if_reference(const BasicType t) { 606 #ifdef AARCH64 607 // AArch64 doesn't need a release store here because object 608 // initialization contains the necessary barriers. 609 return unordered; 610 #else 611 const MemOrd mo = (t == T_ARRAY || 612 t == T_ADDRESS || // Might be the address of an object reference (`boxing'). 613 t == T_OBJECT) ? release : unordered; 614 return mo; 615 #endif 616 } 617 618 // Polymorphic factory method 619 // 620 // We must ensure that stores of object references will be visible 621 // only after the object's initialization. So the callers of this 622 // procedure must indicate that the store requires `release' 623 // semantics, if the stored value is an object reference that might 624 // point to a new object and may become externally visible. 625 static StoreNode* make(PhaseGVN& gvn, Node* c, Node* mem, Node* adr, 626 const TypePtr* at, Node* val, BasicType bt, 627 MemOrd mo, bool require_atomic_access = false); 628 629 virtual uint hash() const; // Check the type 630 631 // If the store is to Field memory and the pointer is non-null, we can 632 // zero out the control input. 633 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 634 635 // Compute a new Type for this node. Basically we just do the pre-check, 636 // then call the virtual add() to set the type. 637 virtual const Type* Value(PhaseGVN* phase) const; 638 639 // Check for identity function on memory (Load then Store at same address) 640 virtual Node* Identity(PhaseGVN* phase); 641 642 // Do not match memory edge 643 virtual uint match_edge(uint idx) const; 644 645 virtual const Type *bottom_type() const; // returns Type::MEMORY 646 647 // Map a store opcode to its corresponding own opcode, trivially. 648 virtual int store_Opcode() const { return Opcode(); } 649 650 // have all possible loads of the value stored been optimized away? 651 bool value_never_loaded(PhaseValues* phase) const; 652 653 bool has_reinterpret_variant(const Type* vt); 654 Node* convert_to_reinterpret_store(PhaseGVN& gvn, Node* val, const Type* vt); 655 656 MemBarNode* trailing_membar() const; 657 }; 658 659 //------------------------------StoreBNode------------------------------------- 660 // Store byte to memory 661 class StoreBNode : public StoreNode { 662 public: 663 StoreBNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 664 : StoreNode(c, mem, adr, at, val, mo) {} 665 virtual int Opcode() const; 666 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 667 virtual BasicType memory_type() const { return T_BYTE; } 668 }; 669 670 //------------------------------StoreCNode------------------------------------- 671 // Store char/short to memory 672 class StoreCNode : public StoreNode { 673 public: 674 StoreCNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 675 : StoreNode(c, mem, adr, at, val, mo) {} 676 virtual int Opcode() const; 677 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 678 virtual BasicType memory_type() const { return T_CHAR; } 679 }; 680 681 //------------------------------StoreINode------------------------------------- 682 // Store int to memory 683 class StoreINode : public StoreNode { 684 public: 685 StoreINode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 686 : StoreNode(c, mem, adr, at, val, mo) {} 687 virtual int Opcode() const; 688 virtual BasicType memory_type() const { return T_INT; } 689 }; 690 691 //------------------------------StoreLNode------------------------------------- 692 // Store long to memory 693 class StoreLNode : public StoreNode { 694 virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; } 695 virtual bool cmp( const Node &n ) const { 696 return _require_atomic_access == ((StoreLNode&)n)._require_atomic_access 697 && StoreNode::cmp(n); 698 } 699 virtual uint size_of() const { return sizeof(*this); } 700 const bool _require_atomic_access; // is piecewise store forbidden? 701 702 public: 703 StoreLNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo, bool require_atomic_access = false) 704 : StoreNode(c, mem, adr, at, val, mo), _require_atomic_access(require_atomic_access) {} 705 virtual int Opcode() const; 706 virtual BasicType memory_type() const { return T_LONG; } 707 bool require_atomic_access() const { return _require_atomic_access; } 708 709 #ifndef PRODUCT 710 virtual void dump_spec(outputStream *st) const { 711 StoreNode::dump_spec(st); 712 if (_require_atomic_access) st->print(" Atomic!"); 713 } 714 #endif 715 }; 716 717 //------------------------------StoreFNode------------------------------------- 718 // Store float to memory 719 class StoreFNode : public StoreNode { 720 public: 721 StoreFNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 722 : StoreNode(c, mem, adr, at, val, mo) {} 723 virtual int Opcode() const; 724 virtual BasicType memory_type() const { return T_FLOAT; } 725 }; 726 727 //------------------------------StoreDNode------------------------------------- 728 // Store double to memory 729 class StoreDNode : public StoreNode { 730 virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; } 731 virtual bool cmp( const Node &n ) const { 732 return _require_atomic_access == ((StoreDNode&)n)._require_atomic_access 733 && StoreNode::cmp(n); 734 } 735 virtual uint size_of() const { return sizeof(*this); } 736 const bool _require_atomic_access; // is piecewise store forbidden? 737 public: 738 StoreDNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, 739 MemOrd mo, bool require_atomic_access = false) 740 : StoreNode(c, mem, adr, at, val, mo), _require_atomic_access(require_atomic_access) {} 741 virtual int Opcode() const; 742 virtual BasicType memory_type() const { return T_DOUBLE; } 743 bool require_atomic_access() const { return _require_atomic_access; } 744 745 #ifndef PRODUCT 746 virtual void dump_spec(outputStream *st) const { 747 StoreNode::dump_spec(st); 748 if (_require_atomic_access) st->print(" Atomic!"); 749 } 750 #endif 751 752 }; 753 754 //------------------------------StorePNode------------------------------------- 755 // Store pointer to memory 756 class StorePNode : public StoreNode { 757 public: 758 StorePNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 759 : StoreNode(c, mem, adr, at, val, mo) {} 760 virtual int Opcode() const; 761 virtual BasicType memory_type() const { return T_ADDRESS; } 762 }; 763 764 //------------------------------StoreNNode------------------------------------- 765 // Store narrow oop to memory 766 class StoreNNode : public StoreNode { 767 public: 768 StoreNNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 769 : StoreNode(c, mem, adr, at, val, mo) {} 770 virtual int Opcode() const; 771 virtual BasicType memory_type() const { return T_NARROWOOP; } 772 }; 773 774 //------------------------------StoreNKlassNode-------------------------------------- 775 // Store narrow klass to memory 776 class StoreNKlassNode : public StoreNNode { 777 public: 778 StoreNKlassNode(Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, MemOrd mo) 779 : StoreNNode(c, mem, adr, at, val, mo) {} 780 virtual int Opcode() const; 781 virtual BasicType memory_type() const { return T_NARROWKLASS; } 782 }; 783 784 //------------------------------StoreCMNode----------------------------------- 785 // Store card-mark byte to memory for CM 786 // The last StoreCM before a SafePoint must be preserved and occur after its "oop" store 787 // Preceding equivalent StoreCMs may be eliminated. 788 class StoreCMNode : public StoreNode { 789 private: 790 virtual uint hash() const { return StoreNode::hash() + _oop_alias_idx; } 791 virtual bool cmp( const Node &n ) const { 792 return _oop_alias_idx == ((StoreCMNode&)n)._oop_alias_idx 793 && StoreNode::cmp(n); 794 } 795 virtual uint size_of() const { return sizeof(*this); } 796 int _oop_alias_idx; // The alias_idx of OopStore 797 798 public: 799 StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store, int oop_alias_idx ) : 800 StoreNode(c, mem, adr, at, val, oop_store, MemNode::release), 801 _oop_alias_idx(oop_alias_idx) { 802 assert(_oop_alias_idx >= Compile::AliasIdxRaw || 803 (_oop_alias_idx == Compile::AliasIdxBot && !Compile::current()->do_aliasing()), 804 "bad oop alias idx"); 805 } 806 virtual int Opcode() const; 807 virtual Node* Identity(PhaseGVN* phase); 808 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 809 virtual const Type* Value(PhaseGVN* phase) const; 810 virtual BasicType memory_type() const { return T_VOID; } // unspecific 811 int oop_alias_idx() const { return _oop_alias_idx; } 812 }; 813 814 //------------------------------SCMemProjNode--------------------------------------- 815 // This class defines a projection of the memory state of a store conditional node. 816 // These nodes return a value, but also update memory. 817 class SCMemProjNode : public ProjNode { 818 public: 819 enum {SCMEMPROJCON = (uint)-2}; 820 SCMemProjNode( Node *src) : ProjNode( src, SCMEMPROJCON) { } 821 virtual int Opcode() const; 822 virtual bool is_CFG() const { return false; } 823 virtual const Type *bottom_type() const {return Type::MEMORY;} 824 virtual const TypePtr *adr_type() const { 825 Node* ctrl = in(0); 826 if (ctrl == nullptr) return nullptr; // node is dead 827 return ctrl->in(MemNode::Memory)->adr_type(); 828 } 829 virtual uint ideal_reg() const { return 0;} // memory projections don't have a register 830 virtual const Type* Value(PhaseGVN* phase) const; 831 #ifndef PRODUCT 832 virtual void dump_spec(outputStream *st) const {}; 833 #endif 834 }; 835 836 //------------------------------LoadStoreNode--------------------------- 837 // Note: is_Mem() method returns 'true' for this class. 838 class LoadStoreNode : public Node { 839 private: 840 const Type* const _type; // What kind of value is loaded? 841 const TypePtr* _adr_type; // What kind of memory is being addressed? 842 uint8_t _barrier_data; // Bit field with barrier information 843 virtual uint size_of() const; // Size is bigger 844 public: 845 LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* rt, uint required ); 846 virtual bool depends_only_on_test() const { return false; } 847 virtual uint match_edge(uint idx) const { return idx == MemNode::Address || idx == MemNode::ValueIn; } 848 849 virtual const Type *bottom_type() const { return _type; } 850 virtual uint ideal_reg() const; 851 virtual const class TypePtr *adr_type() const { return _adr_type; } // returns bottom_type of address 852 virtual const Type* Value(PhaseGVN* phase) const; 853 854 bool result_not_used() const; 855 MemBarNode* trailing_membar() const; 856 857 uint8_t barrier_data() { return _barrier_data; } 858 void set_barrier_data(uint8_t barrier_data) { _barrier_data = barrier_data; } 859 }; 860 861 class LoadStoreConditionalNode : public LoadStoreNode { 862 public: 863 enum { 864 ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode 865 }; 866 LoadStoreConditionalNode(Node *c, Node *mem, Node *adr, Node *val, Node *ex); 867 virtual const Type* Value(PhaseGVN* phase) const; 868 }; 869 870 class CompareAndSwapNode : public LoadStoreConditionalNode { 871 private: 872 const MemNode::MemOrd _mem_ord; 873 public: 874 CompareAndSwapNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : LoadStoreConditionalNode(c, mem, adr, val, ex), _mem_ord(mem_ord) {} 875 MemNode::MemOrd order() const { 876 return _mem_ord; 877 } 878 virtual uint size_of() const { return sizeof(*this); } 879 }; 880 881 class CompareAndExchangeNode : public LoadStoreNode { 882 private: 883 const MemNode::MemOrd _mem_ord; 884 public: 885 enum { 886 ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode 887 }; 888 CompareAndExchangeNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord, const TypePtr* at, const Type* t) : 889 LoadStoreNode(c, mem, adr, val, at, t, 5), _mem_ord(mem_ord) { 890 init_req(ExpectedIn, ex ); 891 } 892 893 MemNode::MemOrd order() const { 894 return _mem_ord; 895 } 896 virtual uint size_of() const { return sizeof(*this); } 897 }; 898 899 //------------------------------CompareAndSwapBNode--------------------------- 900 class CompareAndSwapBNode : public CompareAndSwapNode { 901 public: 902 CompareAndSwapBNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 903 virtual int Opcode() const; 904 }; 905 906 //------------------------------CompareAndSwapSNode--------------------------- 907 class CompareAndSwapSNode : public CompareAndSwapNode { 908 public: 909 CompareAndSwapSNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 910 virtual int Opcode() const; 911 }; 912 913 //------------------------------CompareAndSwapINode--------------------------- 914 class CompareAndSwapINode : public CompareAndSwapNode { 915 public: 916 CompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 917 virtual int Opcode() const; 918 }; 919 920 //------------------------------CompareAndSwapLNode--------------------------- 921 class CompareAndSwapLNode : public CompareAndSwapNode { 922 public: 923 CompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 924 virtual int Opcode() const; 925 }; 926 927 //------------------------------CompareAndSwapPNode--------------------------- 928 class CompareAndSwapPNode : public CompareAndSwapNode { 929 public: 930 CompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 931 virtual int Opcode() const; 932 }; 933 934 //------------------------------CompareAndSwapNNode--------------------------- 935 class CompareAndSwapNNode : public CompareAndSwapNode { 936 public: 937 CompareAndSwapNNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 938 virtual int Opcode() const; 939 }; 940 941 //------------------------------WeakCompareAndSwapBNode--------------------------- 942 class WeakCompareAndSwapBNode : public CompareAndSwapNode { 943 public: 944 WeakCompareAndSwapBNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 945 virtual int Opcode() const; 946 }; 947 948 //------------------------------WeakCompareAndSwapSNode--------------------------- 949 class WeakCompareAndSwapSNode : public CompareAndSwapNode { 950 public: 951 WeakCompareAndSwapSNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 952 virtual int Opcode() const; 953 }; 954 955 //------------------------------WeakCompareAndSwapINode--------------------------- 956 class WeakCompareAndSwapINode : public CompareAndSwapNode { 957 public: 958 WeakCompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 959 virtual int Opcode() const; 960 }; 961 962 //------------------------------WeakCompareAndSwapLNode--------------------------- 963 class WeakCompareAndSwapLNode : public CompareAndSwapNode { 964 public: 965 WeakCompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 966 virtual int Opcode() const; 967 }; 968 969 //------------------------------WeakCompareAndSwapPNode--------------------------- 970 class WeakCompareAndSwapPNode : public CompareAndSwapNode { 971 public: 972 WeakCompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 973 virtual int Opcode() const; 974 }; 975 976 //------------------------------WeakCompareAndSwapNNode--------------------------- 977 class WeakCompareAndSwapNNode : public CompareAndSwapNode { 978 public: 979 WeakCompareAndSwapNNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, MemNode::MemOrd mem_ord) : CompareAndSwapNode(c, mem, adr, val, ex, mem_ord) { } 980 virtual int Opcode() const; 981 }; 982 983 //------------------------------CompareAndExchangeBNode--------------------------- 984 class CompareAndExchangeBNode : public CompareAndExchangeNode { 985 public: 986 CompareAndExchangeBNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeInt::BYTE) { } 987 virtual int Opcode() const; 988 }; 989 990 991 //------------------------------CompareAndExchangeSNode--------------------------- 992 class CompareAndExchangeSNode : public CompareAndExchangeNode { 993 public: 994 CompareAndExchangeSNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeInt::SHORT) { } 995 virtual int Opcode() const; 996 }; 997 998 //------------------------------CompareAndExchangeLNode--------------------------- 999 class CompareAndExchangeLNode : public CompareAndExchangeNode { 1000 public: 1001 CompareAndExchangeLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeLong::LONG) { } 1002 virtual int Opcode() const; 1003 }; 1004 1005 1006 //------------------------------CompareAndExchangeINode--------------------------- 1007 class CompareAndExchangeINode : public CompareAndExchangeNode { 1008 public: 1009 CompareAndExchangeINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, TypeInt::INT) { } 1010 virtual int Opcode() const; 1011 }; 1012 1013 1014 //------------------------------CompareAndExchangePNode--------------------------- 1015 class CompareAndExchangePNode : public CompareAndExchangeNode { 1016 public: 1017 CompareAndExchangePNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, t) { } 1018 virtual int Opcode() const; 1019 }; 1020 1021 //------------------------------CompareAndExchangeNNode--------------------------- 1022 class CompareAndExchangeNNode : public CompareAndExchangeNode { 1023 public: 1024 CompareAndExchangeNNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex, const TypePtr* at, const Type* t, MemNode::MemOrd mem_ord) : CompareAndExchangeNode(c, mem, adr, val, ex, mem_ord, at, t) { } 1025 virtual int Opcode() const; 1026 }; 1027 1028 //------------------------------GetAndAddBNode--------------------------- 1029 class GetAndAddBNode : public LoadStoreNode { 1030 public: 1031 GetAndAddBNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::BYTE, 4) { } 1032 virtual int Opcode() const; 1033 }; 1034 1035 //------------------------------GetAndAddSNode--------------------------- 1036 class GetAndAddSNode : public LoadStoreNode { 1037 public: 1038 GetAndAddSNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::SHORT, 4) { } 1039 virtual int Opcode() const; 1040 }; 1041 1042 //------------------------------GetAndAddINode--------------------------- 1043 class GetAndAddINode : public LoadStoreNode { 1044 public: 1045 GetAndAddINode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::INT, 4) { } 1046 virtual int Opcode() const; 1047 }; 1048 1049 //------------------------------GetAndAddLNode--------------------------- 1050 class GetAndAddLNode : public LoadStoreNode { 1051 public: 1052 GetAndAddLNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeLong::LONG, 4) { } 1053 virtual int Opcode() const; 1054 }; 1055 1056 //------------------------------GetAndSetBNode--------------------------- 1057 class GetAndSetBNode : public LoadStoreNode { 1058 public: 1059 GetAndSetBNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::BYTE, 4) { } 1060 virtual int Opcode() const; 1061 }; 1062 1063 //------------------------------GetAndSetSNode--------------------------- 1064 class GetAndSetSNode : public LoadStoreNode { 1065 public: 1066 GetAndSetSNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::SHORT, 4) { } 1067 virtual int Opcode() const; 1068 }; 1069 1070 //------------------------------GetAndSetINode--------------------------- 1071 class GetAndSetINode : public LoadStoreNode { 1072 public: 1073 GetAndSetINode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeInt::INT, 4) { } 1074 virtual int Opcode() const; 1075 }; 1076 1077 //------------------------------GetAndSetLNode--------------------------- 1078 class GetAndSetLNode : public LoadStoreNode { 1079 public: 1080 GetAndSetLNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at ) : LoadStoreNode(c, mem, adr, val, at, TypeLong::LONG, 4) { } 1081 virtual int Opcode() const; 1082 }; 1083 1084 //------------------------------GetAndSetPNode--------------------------- 1085 class GetAndSetPNode : public LoadStoreNode { 1086 public: 1087 GetAndSetPNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* t ) : LoadStoreNode(c, mem, adr, val, at, t, 4) { } 1088 virtual int Opcode() const; 1089 }; 1090 1091 //------------------------------GetAndSetNNode--------------------------- 1092 class GetAndSetNNode : public LoadStoreNode { 1093 public: 1094 GetAndSetNNode( Node *c, Node *mem, Node *adr, Node *val, const TypePtr* at, const Type* t ) : LoadStoreNode(c, mem, adr, val, at, t, 4) { } 1095 virtual int Opcode() const; 1096 }; 1097 1098 //------------------------------ClearArray------------------------------------- 1099 class ClearArrayNode: public Node { 1100 private: 1101 bool _is_large; 1102 public: 1103 ClearArrayNode( Node *ctrl, Node *arymem, Node *word_cnt, Node *base, bool is_large) 1104 : Node(ctrl,arymem,word_cnt,base), _is_large(is_large) { 1105 init_class_id(Class_ClearArray); 1106 } 1107 virtual int Opcode() const; 1108 virtual const Type *bottom_type() const { return Type::MEMORY; } 1109 // ClearArray modifies array elements, and so affects only the 1110 // array memory addressed by the bottom_type of its base address. 1111 virtual const class TypePtr *adr_type() const; 1112 virtual Node* Identity(PhaseGVN* phase); 1113 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1114 virtual uint match_edge(uint idx) const; 1115 bool is_large() const { return _is_large; } 1116 1117 // Clear the given area of an object or array. 1118 // The start offset must always be aligned mod BytesPerInt. 1119 // The end offset must always be aligned mod BytesPerLong. 1120 // Return the new memory. 1121 static Node* clear_memory(Node* control, Node* mem, Node* dest, 1122 intptr_t start_offset, 1123 intptr_t end_offset, 1124 PhaseGVN* phase); 1125 static Node* clear_memory(Node* control, Node* mem, Node* dest, 1126 intptr_t start_offset, 1127 Node* end_offset, 1128 PhaseGVN* phase); 1129 static Node* clear_memory(Node* control, Node* mem, Node* dest, 1130 Node* start_offset, 1131 Node* end_offset, 1132 PhaseGVN* phase); 1133 // Return allocation input memory edge if it is different instance 1134 // or itself if it is the one we are looking for. 1135 static bool step_through(Node** np, uint instance_id, PhaseValues* phase); 1136 }; 1137 1138 //------------------------------MemBar----------------------------------------- 1139 // There are different flavors of Memory Barriers to match the Java Memory 1140 // Model. Monitor-enter and volatile-load act as Acquires: no following ref 1141 // can be moved to before them. We insert a MemBar-Acquire after a FastLock or 1142 // volatile-load. Monitor-exit and volatile-store act as Release: no 1143 // preceding ref can be moved to after them. We insert a MemBar-Release 1144 // before a FastUnlock or volatile-store. All volatiles need to be 1145 // serialized, so we follow all volatile-stores with a MemBar-Volatile to 1146 // separate it from any following volatile-load. 1147 class MemBarNode: public MultiNode { 1148 virtual uint hash() const ; // { return NO_HASH; } 1149 virtual bool cmp( const Node &n ) const ; // Always fail, except on self 1150 1151 virtual uint size_of() const { return sizeof(*this); } 1152 // Memory type this node is serializing. Usually either rawptr or bottom. 1153 const TypePtr* _adr_type; 1154 1155 // How is this membar related to a nearby memory access? 1156 enum { 1157 Standalone, 1158 TrailingLoad, 1159 TrailingStore, 1160 LeadingStore, 1161 TrailingLoadStore, 1162 LeadingLoadStore, 1163 TrailingPartialArrayCopy 1164 } _kind; 1165 1166 #ifdef ASSERT 1167 uint _pair_idx; 1168 #endif 1169 1170 public: 1171 enum { 1172 Precedent = TypeFunc::Parms // optional edge to force precedence 1173 }; 1174 MemBarNode(Compile* C, int alias_idx, Node* precedent); 1175 virtual int Opcode() const = 0; 1176 virtual const class TypePtr *adr_type() const { return _adr_type; } 1177 virtual const Type* Value(PhaseGVN* phase) const; 1178 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1179 virtual uint match_edge(uint idx) const { return 0; } 1180 virtual const Type *bottom_type() const { return TypeTuple::MEMBAR; } 1181 virtual Node *match( const ProjNode *proj, const Matcher *m ); 1182 // Factory method. Builds a wide or narrow membar. 1183 // Optional 'precedent' becomes an extra edge if not null. 1184 static MemBarNode* make(Compile* C, int opcode, 1185 int alias_idx = Compile::AliasIdxBot, 1186 Node* precedent = nullptr); 1187 1188 MemBarNode* trailing_membar() const; 1189 MemBarNode* leading_membar() const; 1190 1191 void set_trailing_load() { _kind = TrailingLoad; } 1192 bool trailing_load() const { return _kind == TrailingLoad; } 1193 bool trailing_store() const { return _kind == TrailingStore; } 1194 bool leading_store() const { return _kind == LeadingStore; } 1195 bool trailing_load_store() const { return _kind == TrailingLoadStore; } 1196 bool leading_load_store() const { return _kind == LeadingLoadStore; } 1197 bool trailing() const { return _kind == TrailingLoad || _kind == TrailingStore || _kind == TrailingLoadStore; } 1198 bool leading() const { return _kind == LeadingStore || _kind == LeadingLoadStore; } 1199 bool standalone() const { return _kind == Standalone; } 1200 void set_trailing_partial_array_copy() { _kind = TrailingPartialArrayCopy; } 1201 bool trailing_partial_array_copy() const { return _kind == TrailingPartialArrayCopy; } 1202 1203 static void set_store_pair(MemBarNode* leading, MemBarNode* trailing); 1204 static void set_load_store_pair(MemBarNode* leading, MemBarNode* trailing); 1205 1206 void remove(PhaseIterGVN *igvn); 1207 }; 1208 1209 // "Acquire" - no following ref can move before (but earlier refs can 1210 // follow, like an early Load stalled in cache). Requires multi-cpu 1211 // visibility. Inserted after a volatile load. 1212 class MemBarAcquireNode: public MemBarNode { 1213 public: 1214 MemBarAcquireNode(Compile* C, int alias_idx, Node* precedent) 1215 : MemBarNode(C, alias_idx, precedent) {} 1216 virtual int Opcode() const; 1217 }; 1218 1219 // "Acquire" - no following ref can move before (but earlier refs can 1220 // follow, like an early Load stalled in cache). Requires multi-cpu 1221 // visibility. Inserted independent of any load, as required 1222 // for intrinsic Unsafe.loadFence(). 1223 class LoadFenceNode: public MemBarNode { 1224 public: 1225 LoadFenceNode(Compile* C, int alias_idx, Node* precedent) 1226 : MemBarNode(C, alias_idx, precedent) {} 1227 virtual int Opcode() const; 1228 }; 1229 1230 // "Release" - no earlier ref can move after (but later refs can move 1231 // up, like a speculative pipelined cache-hitting Load). Requires 1232 // multi-cpu visibility. Inserted before a volatile store. 1233 class MemBarReleaseNode: public MemBarNode { 1234 public: 1235 MemBarReleaseNode(Compile* C, int alias_idx, Node* precedent) 1236 : MemBarNode(C, alias_idx, precedent) {} 1237 virtual int Opcode() const; 1238 }; 1239 1240 // "Release" - no earlier ref can move after (but later refs can move 1241 // up, like a speculative pipelined cache-hitting Load). Requires 1242 // multi-cpu visibility. Inserted independent of any store, as required 1243 // for intrinsic Unsafe.storeFence(). 1244 class StoreFenceNode: public MemBarNode { 1245 public: 1246 StoreFenceNode(Compile* C, int alias_idx, Node* precedent) 1247 : MemBarNode(C, alias_idx, precedent) {} 1248 virtual int Opcode() const; 1249 }; 1250 1251 // "Acquire" - no following ref can move before (but earlier refs can 1252 // follow, like an early Load stalled in cache). Requires multi-cpu 1253 // visibility. Inserted after a FastLock. 1254 class MemBarAcquireLockNode: public MemBarNode { 1255 public: 1256 MemBarAcquireLockNode(Compile* C, int alias_idx, Node* precedent) 1257 : MemBarNode(C, alias_idx, precedent) {} 1258 virtual int Opcode() const; 1259 }; 1260 1261 // "Release" - no earlier ref can move after (but later refs can move 1262 // up, like a speculative pipelined cache-hitting Load). Requires 1263 // multi-cpu visibility. Inserted before a FastUnLock. 1264 class MemBarReleaseLockNode: public MemBarNode { 1265 public: 1266 MemBarReleaseLockNode(Compile* C, int alias_idx, Node* precedent) 1267 : MemBarNode(C, alias_idx, precedent) {} 1268 virtual int Opcode() const; 1269 }; 1270 1271 class MemBarStoreStoreNode: public MemBarNode { 1272 public: 1273 MemBarStoreStoreNode(Compile* C, int alias_idx, Node* precedent) 1274 : MemBarNode(C, alias_idx, precedent) { 1275 init_class_id(Class_MemBarStoreStore); 1276 } 1277 virtual int Opcode() const; 1278 }; 1279 1280 class StoreStoreFenceNode: public MemBarNode { 1281 public: 1282 StoreStoreFenceNode(Compile* C, int alias_idx, Node* precedent) 1283 : MemBarNode(C, alias_idx, precedent) {} 1284 virtual int Opcode() const; 1285 }; 1286 1287 // Ordering between a volatile store and a following volatile load. 1288 // Requires multi-CPU visibility? 1289 class MemBarVolatileNode: public MemBarNode { 1290 public: 1291 MemBarVolatileNode(Compile* C, int alias_idx, Node* precedent) 1292 : MemBarNode(C, alias_idx, precedent) {} 1293 virtual int Opcode() const; 1294 }; 1295 1296 // Ordering within the same CPU. Used to order unsafe memory references 1297 // inside the compiler when we lack alias info. Not needed "outside" the 1298 // compiler because the CPU does all the ordering for us. 1299 class MemBarCPUOrderNode: public MemBarNode { 1300 public: 1301 MemBarCPUOrderNode(Compile* C, int alias_idx, Node* precedent) 1302 : MemBarNode(C, alias_idx, precedent) {} 1303 virtual int Opcode() const; 1304 virtual uint ideal_reg() const { return 0; } // not matched in the AD file 1305 }; 1306 1307 class OnSpinWaitNode: public MemBarNode { 1308 public: 1309 OnSpinWaitNode(Compile* C, int alias_idx, Node* precedent) 1310 : MemBarNode(C, alias_idx, precedent) {} 1311 virtual int Opcode() const; 1312 }; 1313 1314 // Isolation of object setup after an AllocateNode and before next safepoint. 1315 // (See comment in memnode.cpp near InitializeNode::InitializeNode for semantics.) 1316 class InitializeNode: public MemBarNode { 1317 friend class AllocateNode; 1318 1319 enum { 1320 Incomplete = 0, 1321 Complete = 1, 1322 WithArraycopy = 2 1323 }; 1324 int _is_complete; 1325 1326 bool _does_not_escape; 1327 1328 public: 1329 enum { 1330 Control = TypeFunc::Control, 1331 Memory = TypeFunc::Memory, // MergeMem for states affected by this op 1332 RawAddress = TypeFunc::Parms+0, // the newly-allocated raw address 1333 RawStores = TypeFunc::Parms+1 // zero or more stores (or TOP) 1334 }; 1335 1336 InitializeNode(Compile* C, int adr_type, Node* rawoop); 1337 virtual int Opcode() const; 1338 virtual uint size_of() const { return sizeof(*this); } 1339 virtual uint ideal_reg() const { return 0; } // not matched in the AD file 1340 virtual const RegMask &in_RegMask(uint) const; // mask for RawAddress 1341 1342 // Manage incoming memory edges via a MergeMem on in(Memory): 1343 Node* memory(uint alias_idx); 1344 1345 // The raw memory edge coming directly from the Allocation. 1346 // The contents of this memory are *always* all-zero-bits. 1347 Node* zero_memory() { return memory(Compile::AliasIdxRaw); } 1348 1349 // Return the corresponding allocation for this initialization (or null if none). 1350 // (Note: Both InitializeNode::allocation and AllocateNode::initialization 1351 // are defined in graphKit.cpp, which sets up the bidirectional relation.) 1352 AllocateNode* allocation(); 1353 1354 // Anything other than zeroing in this init? 1355 bool is_non_zero(); 1356 1357 // An InitializeNode must completed before macro expansion is done. 1358 // Completion requires that the AllocateNode must be followed by 1359 // initialization of the new memory to zero, then to any initializers. 1360 bool is_complete() { return _is_complete != Incomplete; } 1361 bool is_complete_with_arraycopy() { return (_is_complete & WithArraycopy) != 0; } 1362 1363 // Mark complete. (Must not yet be complete.) 1364 void set_complete(PhaseGVN* phase); 1365 void set_complete_with_arraycopy() { _is_complete = Complete | WithArraycopy; } 1366 1367 bool does_not_escape() { return _does_not_escape; } 1368 void set_does_not_escape() { _does_not_escape = true; } 1369 1370 #ifdef ASSERT 1371 // ensure all non-degenerate stores are ordered and non-overlapping 1372 bool stores_are_sane(PhaseValues* phase); 1373 #endif //ASSERT 1374 1375 // See if this store can be captured; return offset where it initializes. 1376 // Return 0 if the store cannot be moved (any sort of problem). 1377 intptr_t can_capture_store(StoreNode* st, PhaseGVN* phase, bool can_reshape); 1378 1379 // Capture another store; reformat it to write my internal raw memory. 1380 // Return the captured copy, else null if there is some sort of problem. 1381 Node* capture_store(StoreNode* st, intptr_t start, PhaseGVN* phase, bool can_reshape); 1382 1383 // Find captured store which corresponds to the range [start..start+size). 1384 // Return my own memory projection (meaning the initial zero bits) 1385 // if there is no such store. Return null if there is a problem. 1386 Node* find_captured_store(intptr_t start, int size_in_bytes, PhaseValues* phase); 1387 1388 // Called when the associated AllocateNode is expanded into CFG. 1389 Node* complete_stores(Node* rawctl, Node* rawmem, Node* rawptr, 1390 intptr_t header_size, Node* size_in_bytes, 1391 PhaseIterGVN* phase); 1392 1393 private: 1394 void remove_extra_zeroes(); 1395 1396 // Find out where a captured store should be placed (or already is placed). 1397 int captured_store_insertion_point(intptr_t start, int size_in_bytes, 1398 PhaseValues* phase); 1399 1400 static intptr_t get_store_offset(Node* st, PhaseValues* phase); 1401 1402 Node* make_raw_address(intptr_t offset, PhaseGVN* phase); 1403 1404 bool detect_init_independence(Node* value, PhaseGVN* phase); 1405 1406 void coalesce_subword_stores(intptr_t header_size, Node* size_in_bytes, 1407 PhaseGVN* phase); 1408 1409 intptr_t find_next_fullword_store(uint i, PhaseGVN* phase); 1410 }; 1411 1412 //------------------------------MergeMem--------------------------------------- 1413 // (See comment in memnode.cpp near MergeMemNode::MergeMemNode for semantics.) 1414 class MergeMemNode: public Node { 1415 virtual uint hash() const ; // { return NO_HASH; } 1416 virtual bool cmp( const Node &n ) const ; // Always fail, except on self 1417 friend class MergeMemStream; 1418 MergeMemNode(Node* def); // clients use MergeMemNode::make 1419 1420 public: 1421 // If the input is a whole memory state, clone it with all its slices intact. 1422 // Otherwise, make a new memory state with just that base memory input. 1423 // In either case, the result is a newly created MergeMem. 1424 static MergeMemNode* make(Node* base_memory); 1425 1426 virtual int Opcode() const; 1427 virtual Node* Identity(PhaseGVN* phase); 1428 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); 1429 virtual uint ideal_reg() const { return NotAMachineReg; } 1430 virtual uint match_edge(uint idx) const { return 0; } 1431 virtual const RegMask &out_RegMask() const; 1432 virtual const Type *bottom_type() const { return Type::MEMORY; } 1433 virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; } 1434 // sparse accessors 1435 // Fetch the previously stored "set_memory_at", or else the base memory. 1436 // (Caller should clone it if it is a phi-nest.) 1437 Node* memory_at(uint alias_idx) const; 1438 // set the memory, regardless of its previous value 1439 void set_memory_at(uint alias_idx, Node* n); 1440 // the "base" is the memory that provides the non-finite support 1441 Node* base_memory() const { return in(Compile::AliasIdxBot); } 1442 // warning: setting the base can implicitly set any of the other slices too 1443 void set_base_memory(Node* def); 1444 // sentinel value which denotes a copy of the base memory: 1445 Node* empty_memory() const { return in(Compile::AliasIdxTop); } 1446 static Node* make_empty_memory(); // where the sentinel comes from 1447 bool is_empty_memory(Node* n) const { assert((n == empty_memory()) == n->is_top(), "sanity"); return n->is_top(); } 1448 // hook for the iterator, to perform any necessary setup 1449 void iteration_setup(const MergeMemNode* other = nullptr); 1450 // push sentinels until I am at least as long as the other (semantic no-op) 1451 void grow_to_match(const MergeMemNode* other); 1452 bool verify_sparse() const PRODUCT_RETURN0; 1453 #ifndef PRODUCT 1454 virtual void dump_spec(outputStream *st) const; 1455 #endif 1456 }; 1457 1458 class MergeMemStream : public StackObj { 1459 private: 1460 MergeMemNode* _mm; 1461 const MergeMemNode* _mm2; // optional second guy, contributes non-empty iterations 1462 Node* _mm_base; // loop-invariant base memory of _mm 1463 int _idx; 1464 int _cnt; 1465 Node* _mem; 1466 Node* _mem2; 1467 int _cnt2; 1468 1469 void init(MergeMemNode* mm, const MergeMemNode* mm2 = nullptr) { 1470 // subsume_node will break sparseness at times, whenever a memory slice 1471 // folds down to a copy of the base ("fat") memory. In such a case, 1472 // the raw edge will update to base, although it should be top. 1473 // This iterator will recognize either top or base_memory as an 1474 // "empty" slice. See is_empty, is_empty2, and next below. 1475 // 1476 // The sparseness property is repaired in MergeMemNode::Ideal. 1477 // As long as access to a MergeMem goes through this iterator 1478 // or the memory_at accessor, flaws in the sparseness will 1479 // never be observed. 1480 // 1481 // Also, iteration_setup repairs sparseness. 1482 assert(mm->verify_sparse(), "please, no dups of base"); 1483 assert(mm2==nullptr || mm2->verify_sparse(), "please, no dups of base"); 1484 1485 _mm = mm; 1486 _mm_base = mm->base_memory(); 1487 _mm2 = mm2; 1488 _cnt = mm->req(); 1489 _idx = Compile::AliasIdxBot-1; // start at the base memory 1490 _mem = nullptr; 1491 _mem2 = nullptr; 1492 } 1493 1494 #ifdef ASSERT 1495 Node* check_memory() const { 1496 if (at_base_memory()) 1497 return _mm->base_memory(); 1498 else if ((uint)_idx < _mm->req() && !_mm->in(_idx)->is_top()) 1499 return _mm->memory_at(_idx); 1500 else 1501 return _mm_base; 1502 } 1503 Node* check_memory2() const { 1504 return at_base_memory()? _mm2->base_memory(): _mm2->memory_at(_idx); 1505 } 1506 #endif 1507 1508 static bool match_memory(Node* mem, const MergeMemNode* mm, int idx) PRODUCT_RETURN0; 1509 void assert_synch() const { 1510 assert(!_mem || _idx >= _cnt || match_memory(_mem, _mm, _idx), 1511 "no side-effects except through the stream"); 1512 } 1513 1514 public: 1515 1516 // expected usages: 1517 // for (MergeMemStream mms(mem->is_MergeMem()); next_non_empty(); ) { ... } 1518 // for (MergeMemStream mms(mem1, mem2); next_non_empty2(); ) { ... } 1519 1520 // iterate over one merge 1521 MergeMemStream(MergeMemNode* mm) { 1522 mm->iteration_setup(); 1523 init(mm); 1524 debug_only(_cnt2 = 999); 1525 } 1526 // iterate in parallel over two merges 1527 // only iterates through non-empty elements of mm2 1528 MergeMemStream(MergeMemNode* mm, const MergeMemNode* mm2) { 1529 assert(mm2, "second argument must be a MergeMem also"); 1530 ((MergeMemNode*)mm2)->iteration_setup(); // update hidden state 1531 mm->iteration_setup(mm2); 1532 init(mm, mm2); 1533 _cnt2 = mm2->req(); 1534 } 1535 #ifdef ASSERT 1536 ~MergeMemStream() { 1537 assert_synch(); 1538 } 1539 #endif 1540 1541 MergeMemNode* all_memory() const { 1542 return _mm; 1543 } 1544 Node* base_memory() const { 1545 assert(_mm_base == _mm->base_memory(), "no update to base memory, please"); 1546 return _mm_base; 1547 } 1548 const MergeMemNode* all_memory2() const { 1549 assert(_mm2 != nullptr, ""); 1550 return _mm2; 1551 } 1552 bool at_base_memory() const { 1553 return _idx == Compile::AliasIdxBot; 1554 } 1555 int alias_idx() const { 1556 assert(_mem, "must call next 1st"); 1557 return _idx; 1558 } 1559 1560 const TypePtr* adr_type() const { 1561 return Compile::current()->get_adr_type(alias_idx()); 1562 } 1563 1564 const TypePtr* adr_type(Compile* C) const { 1565 return C->get_adr_type(alias_idx()); 1566 } 1567 bool is_empty() const { 1568 assert(_mem, "must call next 1st"); 1569 assert(_mem->is_top() == (_mem==_mm->empty_memory()), "correct sentinel"); 1570 return _mem->is_top(); 1571 } 1572 bool is_empty2() const { 1573 assert(_mem2, "must call next 1st"); 1574 assert(_mem2->is_top() == (_mem2==_mm2->empty_memory()), "correct sentinel"); 1575 return _mem2->is_top(); 1576 } 1577 Node* memory() const { 1578 assert(!is_empty(), "must not be empty"); 1579 assert_synch(); 1580 return _mem; 1581 } 1582 // get the current memory, regardless of empty or non-empty status 1583 Node* force_memory() const { 1584 assert(!is_empty() || !at_base_memory(), ""); 1585 // Use _mm_base to defend against updates to _mem->base_memory(). 1586 Node *mem = _mem->is_top() ? _mm_base : _mem; 1587 assert(mem == check_memory(), ""); 1588 return mem; 1589 } 1590 Node* memory2() const { 1591 assert(_mem2 == check_memory2(), ""); 1592 return _mem2; 1593 } 1594 void set_memory(Node* mem) { 1595 if (at_base_memory()) { 1596 // Note that this does not change the invariant _mm_base. 1597 _mm->set_base_memory(mem); 1598 } else { 1599 _mm->set_memory_at(_idx, mem); 1600 } 1601 _mem = mem; 1602 assert_synch(); 1603 } 1604 1605 // Recover from a side effect to the MergeMemNode. 1606 void set_memory() { 1607 _mem = _mm->in(_idx); 1608 } 1609 1610 bool next() { return next(false); } 1611 bool next2() { return next(true); } 1612 1613 bool next_non_empty() { return next_non_empty(false); } 1614 bool next_non_empty2() { return next_non_empty(true); } 1615 // next_non_empty2 can yield states where is_empty() is true 1616 1617 private: 1618 // find the next item, which might be empty 1619 bool next(bool have_mm2) { 1620 assert((_mm2 != nullptr) == have_mm2, "use other next"); 1621 assert_synch(); 1622 if (++_idx < _cnt) { 1623 // Note: This iterator allows _mm to be non-sparse. 1624 // It behaves the same whether _mem is top or base_memory. 1625 _mem = _mm->in(_idx); 1626 if (have_mm2) 1627 _mem2 = _mm2->in((_idx < _cnt2) ? _idx : Compile::AliasIdxTop); 1628 return true; 1629 } 1630 return false; 1631 } 1632 1633 // find the next non-empty item 1634 bool next_non_empty(bool have_mm2) { 1635 while (next(have_mm2)) { 1636 if (!is_empty()) { 1637 // make sure _mem2 is filled in sensibly 1638 if (have_mm2 && _mem2->is_top()) _mem2 = _mm2->base_memory(); 1639 return true; 1640 } else if (have_mm2 && !is_empty2()) { 1641 return true; // is_empty() == true 1642 } 1643 } 1644 return false; 1645 } 1646 }; 1647 1648 // cachewb node for guaranteeing writeback of the cache line at a 1649 // given address to (non-volatile) RAM 1650 class CacheWBNode : public Node { 1651 public: 1652 CacheWBNode(Node *ctrl, Node *mem, Node *addr) : Node(ctrl, mem, addr) {} 1653 virtual int Opcode() const; 1654 virtual uint ideal_reg() const { return NotAMachineReg; } 1655 virtual uint match_edge(uint idx) const { return (idx == 2); } 1656 virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; } 1657 virtual const Type *bottom_type() const { return Type::MEMORY; } 1658 }; 1659 1660 // cachewb pre sync node for ensuring that writebacks are serialised 1661 // relative to preceding or following stores 1662 class CacheWBPreSyncNode : public Node { 1663 public: 1664 CacheWBPreSyncNode(Node *ctrl, Node *mem) : Node(ctrl, mem) {} 1665 virtual int Opcode() const; 1666 virtual uint ideal_reg() const { return NotAMachineReg; } 1667 virtual uint match_edge(uint idx) const { return false; } 1668 virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; } 1669 virtual const Type *bottom_type() const { return Type::MEMORY; } 1670 }; 1671 1672 // cachewb pre sync node for ensuring that writebacks are serialised 1673 // relative to preceding or following stores 1674 class CacheWBPostSyncNode : public Node { 1675 public: 1676 CacheWBPostSyncNode(Node *ctrl, Node *mem) : Node(ctrl, mem) {} 1677 virtual int Opcode() const; 1678 virtual uint ideal_reg() const { return NotAMachineReg; } 1679 virtual uint match_edge(uint idx) const { return false; } 1680 virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; } 1681 virtual const Type *bottom_type() const { return Type::MEMORY; } 1682 }; 1683 1684 //------------------------------Prefetch--------------------------------------- 1685 1686 // Allocation prefetch which may fault, TLAB size have to be adjusted. 1687 class PrefetchAllocationNode : public Node { 1688 public: 1689 PrefetchAllocationNode(Node *mem, Node *adr) : Node(nullptr,mem,adr) {} 1690 virtual int Opcode() const; 1691 virtual uint ideal_reg() const { return NotAMachineReg; } 1692 virtual uint match_edge(uint idx) const { return idx==2; } 1693 virtual const Type *bottom_type() const { return ( AllocatePrefetchStyle == 3 ) ? Type::MEMORY : Type::ABIO; } 1694 }; 1695 1696 #endif // SHARE_OPTO_MEMNODE_HPP