src/share/vm/opto/memnode.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6503
a9becfeecd1b
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial