src/share/vm/opto/memnode.hpp

Tue, 26 Nov 2013 18:38:19 -0800

author
goetz
date
Tue, 26 Nov 2013 18:38:19 -0800
changeset 6489
50fdb38839eb
parent 6485
da862781b584
child 6503
a9becfeecd1b
permissions
-rw-r--r--

8028515: PPPC64 (part 113.2): opto: Introduce LoadFence/StoreFence.
Summary: Use new nodes for loadFence/storeFence intrinsics in C2.
Reviewed-by: kvn, dholmes

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

mercurial