src/share/vm/opto/memnode.hpp

Tue, 06 May 2014 09:17:57 +0200

author
anoll
date
Tue, 06 May 2014 09:17:57 +0200
changeset 7858
55d07ec5bde4
parent 7341
e7b3d177adda
child 7859
c1c199dde5c9
permissions
-rw-r--r--

8036851: volatile double accesses are not explicitly atomic in C2
Summary: The C2 structure is adapted to distinguish between volatile and non-volatile double accesses.
Reviewed-by: twisti, kvn
Contributed-by: Tobias Hartmann <tobias.hartmann@oracle.com>

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

mercurial