src/share/vm/opto/memnode.hpp

Tue, 09 Oct 2012 10:11:38 +0200

author
roland
date
Tue, 09 Oct 2012 10:11:38 +0200
changeset 4159
8e47bac5643a
parent 4106
7eca5de9e0b6
child 4160
f6badecb7ea7
permissions
-rw-r--r--

7054512: Compress class pointers after perm gen removal
Summary: support of compress class pointers in the compilers.
Reviewed-by: kvn, twisti

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

mercurial