src/share/vm/opto/memnode.hpp

Mon, 28 May 2018 10:33:52 +0800

author
aoqi
date
Mon, 28 May 2018 10:33:52 +0800
changeset 9041
95a08233f46c
parent 8879
6bc9abf210fd
parent 8856
ac27a9c85bea
permissions
-rw-r--r--

Merge

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

mercurial