annotate src/share/vm/opto/memnode.hpp @ 5935:de5e8c8a9b87

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