Mercurial > hg > graal-jvmci-8
annotate src/share/vm/opto/memnode.hpp @ 67:16e1cb7cde24
6666343: Compile::has_loops not always set correctly
Summary: Compile::has_loops() should be set from inlined methods
Reviewed-by: kvn, rasbold
author | never |
---|---|
date | Tue, 18 Mar 2008 11:17:37 -0700 |
parents | b8f5ba577b02 |
children | 2a9af0b9cb1c |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 // Portions of code courtesy of Clifford Click | |
26 | |
27 class MultiNode; | |
28 class PhaseCCP; | |
29 class PhaseTransform; | |
30 | |
31 //------------------------------MemNode---------------------------------------- | |
32 // Load or Store, possibly throwing a NULL pointer exception | |
33 class MemNode : public Node { | |
34 protected: | |
35 #ifdef ASSERT | |
36 const TypePtr* _adr_type; // What kind of memory is being addressed? | |
37 #endif | |
38 virtual uint size_of() const; // Size is bigger (ASSERT only) | |
39 public: | |
40 enum { Control, // When is it safe to do this load? | |
41 Memory, // Chunk of memory is being loaded from | |
42 Address, // Actually address, derived from base | |
43 ValueIn, // Value to store | |
44 OopStore // Preceeding oop store, only in StoreCM | |
45 }; | |
46 protected: | |
47 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at ) | |
48 : Node(c0,c1,c2 ) { | |
49 init_class_id(Class_Mem); | |
50 debug_only(_adr_type=at; adr_type();) | |
51 } | |
52 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 ) | |
53 : Node(c0,c1,c2,c3) { | |
54 init_class_id(Class_Mem); | |
55 debug_only(_adr_type=at; adr_type();) | |
56 } | |
57 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4) | |
58 : Node(c0,c1,c2,c3,c4) { | |
59 init_class_id(Class_Mem); | |
60 debug_only(_adr_type=at; adr_type();) | |
61 } | |
62 | |
33 | 63 public: |
0 | 64 // Helpers for the optimizer. Documented in memnode.cpp. |
65 static bool detect_ptr_independence(Node* p1, AllocateNode* a1, | |
66 Node* p2, AllocateNode* a2, | |
67 PhaseTransform* phase); | |
68 static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast); | |
69 | |
70 // This one should probably be a phase-specific function: | |
71 static bool detect_dominating_control(Node* dom, Node* sub); | |
72 | |
73 // Is this Node a MemNode or some descendent? Default is YES. | |
74 virtual Node *Ideal_DU_postCCP( PhaseCCP *ccp ); | |
75 | |
76 virtual const class TypePtr *adr_type() const; // returns bottom_type of address | |
77 | |
78 // Shared code for Ideal methods: | |
79 Node *Ideal_common(PhaseGVN *phase, bool can_reshape); // Return -1 for short-circuit NULL. | |
80 | |
81 // Helper function for adr_type() implementations. | |
82 static const TypePtr* calculate_adr_type(const Type* t, const TypePtr* cross_check = NULL); | |
83 | |
84 // Raw access function, to allow copying of adr_type efficiently in | |
85 // product builds and retain the debug info for debug builds. | |
86 const TypePtr *raw_adr_type() const { | |
87 #ifdef ASSERT | |
88 return _adr_type; | |
89 #else | |
90 return 0; | |
91 #endif | |
92 } | |
93 | |
94 // Map a load or store opcode to its corresponding store opcode. | |
95 // (Return -1 if unknown.) | |
96 virtual int store_Opcode() const { return -1; } | |
97 | |
98 // What is the type of the value in memory? (T_VOID mean "unspecified".) | |
99 virtual BasicType memory_type() const = 0; | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
17
diff
changeset
|
100 virtual int memory_size() const { |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
17
diff
changeset
|
101 #ifdef ASSERT |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
17
diff
changeset
|
102 return type2aelembytes(memory_type(), true); |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
17
diff
changeset
|
103 #else |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
17
diff
changeset
|
104 return type2aelembytes(memory_type()); |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
17
diff
changeset
|
105 #endif |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
17
diff
changeset
|
106 } |
0 | 107 |
108 // Search through memory states which precede this node (load or store). | |
109 // Look for an exact match for the address, with no intervening | |
110 // aliased stores. | |
111 Node* find_previous_store(PhaseTransform* phase); | |
112 | |
113 // Can this node (load or store) accurately see a stored value in | |
114 // the given memory state? (The state may or may not be in(Memory).) | |
115 Node* can_see_stored_value(Node* st, PhaseTransform* phase) const; | |
116 | |
117 #ifndef PRODUCT | |
118 static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st); | |
119 virtual void dump_spec(outputStream *st) const; | |
120 #endif | |
121 }; | |
122 | |
123 //------------------------------LoadNode--------------------------------------- | |
124 // Load value; requires Memory and Address | |
125 class LoadNode : public MemNode { | |
126 protected: | |
127 virtual uint cmp( const Node &n ) const; | |
128 virtual uint size_of() const; // Size is bigger | |
129 const Type* const _type; // What kind of value is loaded? | |
130 public: | |
131 | |
132 LoadNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt ) | |
133 : MemNode(c,mem,adr,at), _type(rt) { | |
134 init_class_id(Class_Load); | |
135 } | |
136 | |
137 // Polymorphic factory method: | |
138 static LoadNode* make( Compile *C, Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *rt, BasicType bt ); | |
139 | |
140 virtual uint hash() const; // Check the type | |
141 | |
142 // Handle algebraic identities here. If we have an identity, return the Node | |
143 // we are equivalent to. We look for Load of a Store. | |
144 virtual Node *Identity( PhaseTransform *phase ); | |
145 | |
146 // If the load is from Field memory and the pointer is non-null, we can | |
147 // zero out the control input. | |
148 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
149 | |
17
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
150 // Recover original value from boxed values |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
151 Node *eliminate_autobox(PhaseGVN *phase); |
ff5961f4c095
6395208: Elide autoboxing for calls to HashMap.get(int) and HashMap.get(long)
never
parents:
0
diff
changeset
|
152 |
0 | 153 // Compute a new Type for this node. Basically we just do the pre-check, |
154 // then call the virtual add() to set the type. | |
155 virtual const Type *Value( PhaseTransform *phase ) const; | |
156 | |
157 virtual uint ideal_reg() const; | |
158 virtual const Type *bottom_type() const; | |
159 // Following method is copied from TypeNode: | |
160 void set_type(const Type* t) { | |
161 assert(t != NULL, "sanity"); | |
162 debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH); | |
163 *(const Type**)&_type = t; // cast away const-ness | |
164 // If this node is in the hash table, make sure it doesn't need a rehash. | |
165 assert(check_hash == NO_HASH || check_hash == hash(), "type change must preserve hash code"); | |
166 } | |
167 const Type* type() const { assert(_type != NULL, "sanity"); return _type; }; | |
168 | |
169 // Do not match memory edge | |
170 virtual uint match_edge(uint idx) const; | |
171 | |
172 // Map a load opcode to its corresponding store opcode. | |
173 virtual int store_Opcode() const = 0; | |
174 | |
64
b8f5ba577b02
6673473: (Escape Analysis) Add the instance's field information to PhiNode
kvn
parents:
33
diff
changeset
|
175 // Check if the load's memory input is a Phi node with the same control. |
b8f5ba577b02
6673473: (Escape Analysis) Add the instance's field information to PhiNode
kvn
parents:
33
diff
changeset
|
176 bool is_instance_field_load_with_local_phi(Node* ctrl); |
b8f5ba577b02
6673473: (Escape Analysis) Add the instance's field information to PhiNode
kvn
parents:
33
diff
changeset
|
177 |
0 | 178 #ifndef PRODUCT |
179 virtual void dump_spec(outputStream *st) const; | |
180 #endif | |
181 protected: | |
182 const Type* load_array_final_field(const TypeKlassPtr *tkls, | |
183 ciKlass* klass) const; | |
184 }; | |
185 | |
186 //------------------------------LoadBNode-------------------------------------- | |
187 // Load a byte (8bits signed) from memory | |
188 class LoadBNode : public LoadNode { | |
189 public: | |
190 LoadBNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::BYTE ) | |
191 : LoadNode(c,mem,adr,at,ti) {} | |
192 virtual int Opcode() const; | |
193 virtual uint ideal_reg() const { return Op_RegI; } | |
194 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
195 virtual int store_Opcode() const { return Op_StoreB; } | |
196 virtual BasicType memory_type() const { return T_BYTE; } | |
197 }; | |
198 | |
199 //------------------------------LoadCNode-------------------------------------- | |
200 // Load a char (16bits unsigned) from memory | |
201 class LoadCNode : public LoadNode { | |
202 public: | |
203 LoadCNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::CHAR ) | |
204 : LoadNode(c,mem,adr,at,ti) {} | |
205 virtual int Opcode() const; | |
206 virtual uint ideal_reg() const { return Op_RegI; } | |
207 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
208 virtual int store_Opcode() const { return Op_StoreC; } | |
209 virtual BasicType memory_type() const { return T_CHAR; } | |
210 }; | |
211 | |
212 //------------------------------LoadINode-------------------------------------- | |
213 // Load an integer from memory | |
214 class LoadINode : public LoadNode { | |
215 public: | |
216 LoadINode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::INT ) | |
217 : LoadNode(c,mem,adr,at,ti) {} | |
218 virtual int Opcode() const; | |
219 virtual uint ideal_reg() const { return Op_RegI; } | |
220 virtual int store_Opcode() const { return Op_StoreI; } | |
221 virtual BasicType memory_type() const { return T_INT; } | |
222 }; | |
223 | |
224 //------------------------------LoadRangeNode---------------------------------- | |
225 // Load an array length from the array | |
226 class LoadRangeNode : public LoadINode { | |
227 public: | |
228 LoadRangeNode( Node *c, Node *mem, Node *adr, const TypeInt *ti = TypeInt::POS ) | |
229 : LoadINode(c,mem,adr,TypeAryPtr::RANGE,ti) {} | |
230 virtual int Opcode() const; | |
231 virtual const Type *Value( PhaseTransform *phase ) const; | |
232 virtual Node *Identity( PhaseTransform *phase ); | |
233 }; | |
234 | |
235 //------------------------------LoadLNode-------------------------------------- | |
236 // Load a long from memory | |
237 class LoadLNode : public LoadNode { | |
238 virtual uint hash() const { return LoadNode::hash() + _require_atomic_access; } | |
239 virtual uint cmp( const Node &n ) const { | |
240 return _require_atomic_access == ((LoadLNode&)n)._require_atomic_access | |
241 && LoadNode::cmp(n); | |
242 } | |
243 virtual uint size_of() const { return sizeof(*this); } | |
244 const bool _require_atomic_access; // is piecewise load forbidden? | |
245 | |
246 public: | |
247 LoadLNode( Node *c, Node *mem, Node *adr, const TypePtr* at, | |
248 const TypeLong *tl = TypeLong::LONG, | |
249 bool require_atomic_access = false ) | |
250 : LoadNode(c,mem,adr,at,tl) | |
251 , _require_atomic_access(require_atomic_access) | |
252 {} | |
253 virtual int Opcode() const; | |
254 virtual uint ideal_reg() const { return Op_RegL; } | |
255 virtual int store_Opcode() const { return Op_StoreL; } | |
256 virtual BasicType memory_type() const { return T_LONG; } | |
257 bool require_atomic_access() { return _require_atomic_access; } | |
258 static LoadLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, const Type* rt); | |
259 #ifndef PRODUCT | |
260 virtual void dump_spec(outputStream *st) const { | |
261 LoadNode::dump_spec(st); | |
262 if (_require_atomic_access) st->print(" Atomic!"); | |
263 } | |
264 #endif | |
265 }; | |
266 | |
267 //------------------------------LoadL_unalignedNode---------------------------- | |
268 // Load a long from unaligned memory | |
269 class LoadL_unalignedNode : public LoadLNode { | |
270 public: | |
271 LoadL_unalignedNode( Node *c, Node *mem, Node *adr, const TypePtr* at ) | |
272 : LoadLNode(c,mem,adr,at) {} | |
273 virtual int Opcode() const; | |
274 }; | |
275 | |
276 //------------------------------LoadFNode-------------------------------------- | |
277 // Load a float (64 bits) from memory | |
278 class LoadFNode : public LoadNode { | |
279 public: | |
280 LoadFNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t = Type::FLOAT ) | |
281 : LoadNode(c,mem,adr,at,t) {} | |
282 virtual int Opcode() const; | |
283 virtual uint ideal_reg() const { return Op_RegF; } | |
284 virtual int store_Opcode() const { return Op_StoreF; } | |
285 virtual BasicType memory_type() const { return T_FLOAT; } | |
286 }; | |
287 | |
288 //------------------------------LoadDNode-------------------------------------- | |
289 // Load a double (64 bits) from memory | |
290 class LoadDNode : public LoadNode { | |
291 public: | |
292 LoadDNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const Type *t = Type::DOUBLE ) | |
293 : LoadNode(c,mem,adr,at,t) {} | |
294 virtual int Opcode() const; | |
295 virtual uint ideal_reg() const { return Op_RegD; } | |
296 virtual int store_Opcode() const { return Op_StoreD; } | |
297 virtual BasicType memory_type() const { return T_DOUBLE; } | |
298 }; | |
299 | |
300 //------------------------------LoadD_unalignedNode---------------------------- | |
301 // Load a double from unaligned memory | |
302 class LoadD_unalignedNode : public LoadDNode { | |
303 public: | |
304 LoadD_unalignedNode( Node *c, Node *mem, Node *adr, const TypePtr* at ) | |
305 : LoadDNode(c,mem,adr,at) {} | |
306 virtual int Opcode() const; | |
307 }; | |
308 | |
309 //------------------------------LoadPNode-------------------------------------- | |
310 // Load a pointer from memory (either object or array) | |
311 class LoadPNode : public LoadNode { | |
312 public: | |
313 LoadPNode( Node *c, Node *mem, Node *adr, const TypePtr *at, const TypePtr* t ) | |
314 : LoadNode(c,mem,adr,at,t) {} | |
315 virtual int Opcode() const; | |
316 virtual uint ideal_reg() const { return Op_RegP; } | |
317 virtual int store_Opcode() const { return Op_StoreP; } | |
318 virtual BasicType memory_type() const { return T_ADDRESS; } | |
319 // depends_only_on_test is almost always true, and needs to be almost always | |
320 // true to enable key hoisting & commoning optimizations. However, for the | |
321 // special case of RawPtr loads from TLS top & end, the control edge carries | |
322 // the dependence preventing hoisting past a Safepoint instead of the memory | |
323 // edge. (An unfortunate consequence of having Safepoints not set Raw | |
324 // Memory; itself an unfortunate consequence of having Nodes which produce | |
325 // results (new raw memory state) inside of loops preventing all manner of | |
326 // other optimizations). Basically, it's ugly but so is the alternative. | |
327 // See comment in macro.cpp, around line 125 expand_allocate_common(). | |
328 virtual bool depends_only_on_test() const { return adr_type() != TypeRawPtr::BOTTOM; } | |
329 }; | |
330 | |
331 //------------------------------LoadKlassNode---------------------------------- | |
332 // Load a Klass from an object | |
333 class LoadKlassNode : public LoadPNode { | |
334 public: | |
335 LoadKlassNode( Node *c, Node *mem, Node *adr, const TypePtr *at, const TypeKlassPtr *tk = TypeKlassPtr::OBJECT ) | |
336 : LoadPNode(c,mem,adr,at,tk) {} | |
337 virtual int Opcode() const; | |
338 virtual const Type *Value( PhaseTransform *phase ) const; | |
339 virtual Node *Identity( PhaseTransform *phase ); | |
340 virtual bool depends_only_on_test() const { return true; } | |
341 }; | |
342 | |
343 //------------------------------LoadSNode-------------------------------------- | |
344 // Load a short (16bits signed) from memory | |
345 class LoadSNode : public LoadNode { | |
346 public: | |
347 LoadSNode( Node *c, Node *mem, Node *adr, const TypePtr* at, const TypeInt *ti = TypeInt::SHORT ) | |
348 : LoadNode(c,mem,adr,at,ti) {} | |
349 virtual int Opcode() const; | |
350 virtual uint ideal_reg() const { return Op_RegI; } | |
351 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
352 virtual int store_Opcode() const { return Op_StoreC; } | |
353 virtual BasicType memory_type() const { return T_SHORT; } | |
354 }; | |
355 | |
356 //------------------------------StoreNode-------------------------------------- | |
357 // Store value; requires Store, Address and Value | |
358 class StoreNode : public MemNode { | |
359 protected: | |
360 virtual uint cmp( const Node &n ) const; | |
361 virtual bool depends_only_on_test() const { return false; } | |
362 | |
363 Node *Ideal_masked_input (PhaseGVN *phase, uint mask); | |
364 Node *Ideal_sign_extended_input(PhaseGVN *phase, int num_bits); | |
365 | |
366 public: | |
367 StoreNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) | |
368 : MemNode(c,mem,adr,at,val) { | |
369 init_class_id(Class_Store); | |
370 } | |
371 StoreNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store ) | |
372 : MemNode(c,mem,adr,at,val,oop_store) { | |
373 init_class_id(Class_Store); | |
374 } | |
375 | |
376 // Polymorphic factory method: | |
377 static StoreNode* make( Compile *C, Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, BasicType bt ); | |
378 | |
379 virtual uint hash() const; // Check the type | |
380 | |
381 // If the store is to Field memory and the pointer is non-null, we can | |
382 // zero out the control input. | |
383 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
384 | |
385 // Compute a new Type for this node. Basically we just do the pre-check, | |
386 // then call the virtual add() to set the type. | |
387 virtual const Type *Value( PhaseTransform *phase ) const; | |
388 | |
389 // Check for identity function on memory (Load then Store at same address) | |
390 virtual Node *Identity( PhaseTransform *phase ); | |
391 | |
392 // Do not match memory edge | |
393 virtual uint match_edge(uint idx) const; | |
394 | |
395 virtual const Type *bottom_type() const; // returns Type::MEMORY | |
396 | |
397 // Map a store opcode to its corresponding own opcode, trivially. | |
398 virtual int store_Opcode() const { return Opcode(); } | |
399 | |
400 // have all possible loads of the value stored been optimized away? | |
401 bool value_never_loaded(PhaseTransform *phase) const; | |
402 }; | |
403 | |
404 //------------------------------StoreBNode------------------------------------- | |
405 // Store byte to memory | |
406 class StoreBNode : public StoreNode { | |
407 public: | |
408 StoreBNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {} | |
409 virtual int Opcode() const; | |
410 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
411 virtual BasicType memory_type() const { return T_BYTE; } | |
412 }; | |
413 | |
414 //------------------------------StoreCNode------------------------------------- | |
415 // Store char/short to memory | |
416 class StoreCNode : public StoreNode { | |
417 public: | |
418 StoreCNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {} | |
419 virtual int Opcode() const; | |
420 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
421 virtual BasicType memory_type() const { return T_CHAR; } | |
422 }; | |
423 | |
424 //------------------------------StoreINode------------------------------------- | |
425 // Store int to memory | |
426 class StoreINode : public StoreNode { | |
427 public: | |
428 StoreINode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {} | |
429 virtual int Opcode() const; | |
430 virtual BasicType memory_type() const { return T_INT; } | |
431 }; | |
432 | |
433 //------------------------------StoreLNode------------------------------------- | |
434 // Store long to memory | |
435 class StoreLNode : public StoreNode { | |
436 virtual uint hash() const { return StoreNode::hash() + _require_atomic_access; } | |
437 virtual uint cmp( const Node &n ) const { | |
438 return _require_atomic_access == ((StoreLNode&)n)._require_atomic_access | |
439 && StoreNode::cmp(n); | |
440 } | |
441 virtual uint size_of() const { return sizeof(*this); } | |
442 const bool _require_atomic_access; // is piecewise store forbidden? | |
443 | |
444 public: | |
445 StoreLNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, | |
446 bool require_atomic_access = false ) | |
447 : StoreNode(c,mem,adr,at,val) | |
448 , _require_atomic_access(require_atomic_access) | |
449 {} | |
450 virtual int Opcode() const; | |
451 virtual BasicType memory_type() const { return T_LONG; } | |
452 bool require_atomic_access() { return _require_atomic_access; } | |
453 static StoreLNode* make_atomic(Compile *C, Node* ctl, Node* mem, Node* adr, const TypePtr* adr_type, Node* val); | |
454 #ifndef PRODUCT | |
455 virtual void dump_spec(outputStream *st) const { | |
456 StoreNode::dump_spec(st); | |
457 if (_require_atomic_access) st->print(" Atomic!"); | |
458 } | |
459 #endif | |
460 }; | |
461 | |
462 //------------------------------StoreFNode------------------------------------- | |
463 // Store float to memory | |
464 class StoreFNode : public StoreNode { | |
465 public: | |
466 StoreFNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {} | |
467 virtual int Opcode() const; | |
468 virtual BasicType memory_type() const { return T_FLOAT; } | |
469 }; | |
470 | |
471 //------------------------------StoreDNode------------------------------------- | |
472 // Store double to memory | |
473 class StoreDNode : public StoreNode { | |
474 public: | |
475 StoreDNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {} | |
476 virtual int Opcode() const; | |
477 virtual BasicType memory_type() const { return T_DOUBLE; } | |
478 }; | |
479 | |
480 //------------------------------StorePNode------------------------------------- | |
481 // Store pointer to memory | |
482 class StorePNode : public StoreNode { | |
483 public: | |
484 StorePNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val ) : StoreNode(c,mem,adr,at,val) {} | |
485 virtual int Opcode() const; | |
486 virtual BasicType memory_type() const { return T_ADDRESS; } | |
487 }; | |
488 | |
489 //------------------------------StoreCMNode----------------------------------- | |
490 // Store card-mark byte to memory for CM | |
491 // The last StoreCM before a SafePoint must be preserved and occur after its "oop" store | |
492 // Preceeding equivalent StoreCMs may be eliminated. | |
493 class StoreCMNode : public StoreNode { | |
494 public: | |
495 StoreCMNode( Node *c, Node *mem, Node *adr, const TypePtr* at, Node *val, Node *oop_store ) : StoreNode(c,mem,adr,at,val,oop_store) {} | |
496 virtual int Opcode() const; | |
497 virtual Node *Identity( PhaseTransform *phase ); | |
498 virtual const Type *Value( PhaseTransform *phase ) const; | |
499 virtual BasicType memory_type() const { return T_VOID; } // unspecific | |
500 }; | |
501 | |
502 //------------------------------LoadPLockedNode--------------------------------- | |
503 // Load-locked a pointer from memory (either object or array). | |
504 // On Sparc & Intel this is implemented as a normal pointer load. | |
505 // On PowerPC and friends it's a real load-locked. | |
506 class LoadPLockedNode : public LoadPNode { | |
507 public: | |
508 LoadPLockedNode( Node *c, Node *mem, Node *adr ) | |
509 : LoadPNode(c,mem,adr,TypeRawPtr::BOTTOM, TypeRawPtr::BOTTOM) {} | |
510 virtual int Opcode() const; | |
511 virtual int store_Opcode() const { return Op_StorePConditional; } | |
512 virtual bool depends_only_on_test() const { return true; } | |
513 }; | |
514 | |
515 //------------------------------LoadLLockedNode--------------------------------- | |
516 // Load-locked a pointer from memory (either object or array). | |
517 // On Sparc & Intel this is implemented as a normal long load. | |
518 class LoadLLockedNode : public LoadLNode { | |
519 public: | |
520 LoadLLockedNode( Node *c, Node *mem, Node *adr ) | |
521 : LoadLNode(c,mem,adr,TypeRawPtr::BOTTOM, TypeLong::LONG) {} | |
522 virtual int Opcode() const; | |
523 virtual int store_Opcode() const { return Op_StoreLConditional; } | |
524 }; | |
525 | |
526 //------------------------------SCMemProjNode--------------------------------------- | |
527 // This class defines a projection of the memory state of a store conditional node. | |
528 // These nodes return a value, but also update memory. | |
529 class SCMemProjNode : public ProjNode { | |
530 public: | |
531 enum {SCMEMPROJCON = (uint)-2}; | |
532 SCMemProjNode( Node *src) : ProjNode( src, SCMEMPROJCON) { } | |
533 virtual int Opcode() const; | |
534 virtual bool is_CFG() const { return false; } | |
535 virtual const Type *bottom_type() const {return Type::MEMORY;} | |
536 virtual const TypePtr *adr_type() const { return in(0)->in(MemNode::Memory)->adr_type();} | |
537 virtual uint ideal_reg() const { return 0;} // memory projections don't have a register | |
538 virtual const Type *Value( PhaseTransform *phase ) const; | |
539 #ifndef PRODUCT | |
540 virtual void dump_spec(outputStream *st) const {}; | |
541 #endif | |
542 }; | |
543 | |
544 //------------------------------LoadStoreNode--------------------------- | |
545 class LoadStoreNode : public Node { | |
546 public: | |
547 enum { | |
548 ExpectedIn = MemNode::ValueIn+1 // One more input than MemNode | |
549 }; | |
550 LoadStoreNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex); | |
551 virtual bool depends_only_on_test() const { return false; } | |
552 virtual const Type *bottom_type() const { return TypeInt::BOOL; } | |
553 virtual uint ideal_reg() const { return Op_RegI; } | |
554 virtual uint match_edge(uint idx) const { return idx == MemNode::Address || idx == MemNode::ValueIn; } | |
555 }; | |
556 | |
557 //------------------------------StorePConditionalNode--------------------------- | |
558 // Conditionally store pointer to memory, if no change since prior | |
559 // load-locked. Sets flags for success or failure of the store. | |
560 class StorePConditionalNode : public LoadStoreNode { | |
561 public: | |
562 StorePConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreNode(c, mem, adr, val, ll) { } | |
563 virtual int Opcode() const; | |
564 // Produces flags | |
565 virtual uint ideal_reg() const { return Op_RegFlags; } | |
566 }; | |
567 | |
568 //------------------------------StoreLConditionalNode--------------------------- | |
569 // Conditionally store long to memory, if no change since prior | |
570 // load-locked. Sets flags for success or failure of the store. | |
571 class StoreLConditionalNode : public LoadStoreNode { | |
572 public: | |
573 StoreLConditionalNode( Node *c, Node *mem, Node *adr, Node *val, Node *ll ) : LoadStoreNode(c, mem, adr, val, ll) { } | |
574 virtual int Opcode() const; | |
575 }; | |
576 | |
577 | |
578 //------------------------------CompareAndSwapLNode--------------------------- | |
579 class CompareAndSwapLNode : public LoadStoreNode { | |
580 public: | |
581 CompareAndSwapLNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { } | |
582 virtual int Opcode() const; | |
583 }; | |
584 | |
585 | |
586 //------------------------------CompareAndSwapINode--------------------------- | |
587 class CompareAndSwapINode : public LoadStoreNode { | |
588 public: | |
589 CompareAndSwapINode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { } | |
590 virtual int Opcode() const; | |
591 }; | |
592 | |
593 | |
594 //------------------------------CompareAndSwapPNode--------------------------- | |
595 class CompareAndSwapPNode : public LoadStoreNode { | |
596 public: | |
597 CompareAndSwapPNode( Node *c, Node *mem, Node *adr, Node *val, Node *ex) : LoadStoreNode(c, mem, adr, val, ex) { } | |
598 virtual int Opcode() const; | |
599 }; | |
600 | |
601 //------------------------------ClearArray------------------------------------- | |
602 class ClearArrayNode: public Node { | |
603 public: | |
604 ClearArrayNode( Node *ctrl, Node *arymem, Node *word_cnt, Node *base ) : Node(ctrl,arymem,word_cnt,base) {} | |
605 virtual int Opcode() const; | |
606 virtual const Type *bottom_type() const { return Type::MEMORY; } | |
607 // ClearArray modifies array elements, and so affects only the | |
608 // array memory addressed by the bottom_type of its base address. | |
609 virtual const class TypePtr *adr_type() const; | |
610 virtual Node *Identity( PhaseTransform *phase ); | |
611 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
612 virtual uint match_edge(uint idx) const; | |
613 | |
614 // Clear the given area of an object or array. | |
615 // The start offset must always be aligned mod BytesPerInt. | |
616 // The end offset must always be aligned mod BytesPerLong. | |
617 // Return the new memory. | |
618 static Node* clear_memory(Node* control, Node* mem, Node* dest, | |
619 intptr_t start_offset, | |
620 intptr_t end_offset, | |
621 PhaseGVN* phase); | |
622 static Node* clear_memory(Node* control, Node* mem, Node* dest, | |
623 intptr_t start_offset, | |
624 Node* end_offset, | |
625 PhaseGVN* phase); | |
626 static Node* clear_memory(Node* control, Node* mem, Node* dest, | |
627 Node* start_offset, | |
628 Node* end_offset, | |
629 PhaseGVN* phase); | |
630 }; | |
631 | |
632 //------------------------------StrComp------------------------------------- | |
633 class StrCompNode: public Node { | |
634 public: | |
635 StrCompNode(Node *control, | |
636 Node* char_array_mem, | |
637 Node* value_mem, | |
638 Node* count_mem, | |
639 Node* offset_mem, | |
640 Node* s1, Node* s2): Node(control, | |
641 char_array_mem, | |
642 value_mem, | |
643 count_mem, | |
644 offset_mem, | |
645 s1, s2) {}; | |
646 virtual int Opcode() const; | |
647 virtual bool depends_only_on_test() const { return false; } | |
648 virtual const Type* bottom_type() const { return TypeInt::INT; } | |
649 // a StrCompNode (conservatively) aliases with everything: | |
650 virtual const TypePtr* adr_type() const { return TypePtr::BOTTOM; } | |
651 virtual uint match_edge(uint idx) const; | |
652 virtual uint ideal_reg() const { return Op_RegI; } | |
653 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
654 }; | |
655 | |
656 //------------------------------MemBar----------------------------------------- | |
657 // There are different flavors of Memory Barriers to match the Java Memory | |
658 // Model. Monitor-enter and volatile-load act as Aquires: no following ref | |
659 // can be moved to before them. We insert a MemBar-Acquire after a FastLock or | |
660 // volatile-load. Monitor-exit and volatile-store act as Release: no | |
661 // preceeding ref can be moved to after them. We insert a MemBar-Release | |
662 // before a FastUnlock or volatile-store. All volatiles need to be | |
663 // serialized, so we follow all volatile-stores with a MemBar-Volatile to | |
664 // seperate it from any following volatile-load. | |
665 class MemBarNode: public MultiNode { | |
666 virtual uint hash() const ; // { return NO_HASH; } | |
667 virtual uint cmp( const Node &n ) const ; // Always fail, except on self | |
668 | |
669 virtual uint size_of() const { return sizeof(*this); } | |
670 // Memory type this node is serializing. Usually either rawptr or bottom. | |
671 const TypePtr* _adr_type; | |
672 | |
673 public: | |
674 enum { | |
675 Precedent = TypeFunc::Parms // optional edge to force precedence | |
676 }; | |
677 MemBarNode(Compile* C, int alias_idx, Node* precedent); | |
678 virtual int Opcode() const = 0; | |
679 virtual const class TypePtr *adr_type() const { return _adr_type; } | |
680 virtual const Type *Value( PhaseTransform *phase ) const; | |
681 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
682 virtual uint match_edge(uint idx) const { return 0; } | |
683 virtual const Type *bottom_type() const { return TypeTuple::MEMBAR; } | |
684 virtual Node *match( const ProjNode *proj, const Matcher *m ); | |
685 // Factory method. Builds a wide or narrow membar. | |
686 // Optional 'precedent' becomes an extra edge if not null. | |
687 static MemBarNode* make(Compile* C, int opcode, | |
688 int alias_idx = Compile::AliasIdxBot, | |
689 Node* precedent = NULL); | |
690 }; | |
691 | |
692 // "Acquire" - no following ref can move before (but earlier refs can | |
693 // follow, like an early Load stalled in cache). Requires multi-cpu | |
694 // visibility. Inserted after a volatile load or FastLock. | |
695 class MemBarAcquireNode: public MemBarNode { | |
696 public: | |
697 MemBarAcquireNode(Compile* C, int alias_idx, Node* precedent) | |
698 : MemBarNode(C, alias_idx, precedent) {} | |
699 virtual int Opcode() const; | |
700 }; | |
701 | |
702 // "Release" - no earlier ref can move after (but later refs can move | |
703 // up, like a speculative pipelined cache-hitting Load). Requires | |
704 // multi-cpu visibility. Inserted before a volatile store or FastUnLock. | |
705 class MemBarReleaseNode: public MemBarNode { | |
706 public: | |
707 MemBarReleaseNode(Compile* C, int alias_idx, Node* precedent) | |
708 : MemBarNode(C, alias_idx, precedent) {} | |
709 virtual int Opcode() const; | |
710 }; | |
711 | |
712 // Ordering between a volatile store and a following volatile load. | |
713 // Requires multi-CPU visibility? | |
714 class MemBarVolatileNode: public MemBarNode { | |
715 public: | |
716 MemBarVolatileNode(Compile* C, int alias_idx, Node* precedent) | |
717 : MemBarNode(C, alias_idx, precedent) {} | |
718 virtual int Opcode() const; | |
719 }; | |
720 | |
721 // Ordering within the same CPU. Used to order unsafe memory references | |
722 // inside the compiler when we lack alias info. Not needed "outside" the | |
723 // compiler because the CPU does all the ordering for us. | |
724 class MemBarCPUOrderNode: public MemBarNode { | |
725 public: | |
726 MemBarCPUOrderNode(Compile* C, int alias_idx, Node* precedent) | |
727 : MemBarNode(C, alias_idx, precedent) {} | |
728 virtual int Opcode() const; | |
729 virtual uint ideal_reg() const { return 0; } // not matched in the AD file | |
730 }; | |
731 | |
732 // Isolation of object setup after an AllocateNode and before next safepoint. | |
733 // (See comment in memnode.cpp near InitializeNode::InitializeNode for semantics.) | |
734 class InitializeNode: public MemBarNode { | |
735 friend class AllocateNode; | |
736 | |
737 bool _is_complete; | |
738 | |
739 public: | |
740 enum { | |
741 Control = TypeFunc::Control, | |
742 Memory = TypeFunc::Memory, // MergeMem for states affected by this op | |
743 RawAddress = TypeFunc::Parms+0, // the newly-allocated raw address | |
744 RawStores = TypeFunc::Parms+1 // zero or more stores (or TOP) | |
745 }; | |
746 | |
747 InitializeNode(Compile* C, int adr_type, Node* rawoop); | |
748 virtual int Opcode() const; | |
749 virtual uint size_of() const { return sizeof(*this); } | |
750 virtual uint ideal_reg() const { return 0; } // not matched in the AD file | |
751 virtual const RegMask &in_RegMask(uint) const; // mask for RawAddress | |
752 | |
753 // Manage incoming memory edges via a MergeMem on in(Memory): | |
754 Node* memory(uint alias_idx); | |
755 | |
756 // The raw memory edge coming directly from the Allocation. | |
757 // The contents of this memory are *always* all-zero-bits. | |
758 Node* zero_memory() { return memory(Compile::AliasIdxRaw); } | |
759 | |
760 // Return the corresponding allocation for this initialization (or null if none). | |
761 // (Note: Both InitializeNode::allocation and AllocateNode::initialization | |
762 // are defined in graphKit.cpp, which sets up the bidirectional relation.) | |
763 AllocateNode* allocation(); | |
764 | |
765 // Anything other than zeroing in this init? | |
766 bool is_non_zero(); | |
767 | |
768 // An InitializeNode must completed before macro expansion is done. | |
769 // Completion requires that the AllocateNode must be followed by | |
770 // initialization of the new memory to zero, then to any initializers. | |
771 bool is_complete() { return _is_complete; } | |
772 | |
773 // Mark complete. (Must not yet be complete.) | |
774 void set_complete(PhaseGVN* phase); | |
775 | |
776 #ifdef ASSERT | |
777 // ensure all non-degenerate stores are ordered and non-overlapping | |
778 bool stores_are_sane(PhaseTransform* phase); | |
779 #endif //ASSERT | |
780 | |
781 // See if this store can be captured; return offset where it initializes. | |
782 // Return 0 if the store cannot be moved (any sort of problem). | |
783 intptr_t can_capture_store(StoreNode* st, PhaseTransform* phase); | |
784 | |
785 // Capture another store; reformat it to write my internal raw memory. | |
786 // Return the captured copy, else NULL if there is some sort of problem. | |
787 Node* capture_store(StoreNode* st, intptr_t start, PhaseTransform* phase); | |
788 | |
789 // Find captured store which corresponds to the range [start..start+size). | |
790 // Return my own memory projection (meaning the initial zero bits) | |
791 // if there is no such store. Return NULL if there is a problem. | |
792 Node* find_captured_store(intptr_t start, int size_in_bytes, PhaseTransform* phase); | |
793 | |
794 // Called when the associated AllocateNode is expanded into CFG. | |
795 Node* complete_stores(Node* rawctl, Node* rawmem, Node* rawptr, | |
796 intptr_t header_size, Node* size_in_bytes, | |
797 PhaseGVN* phase); | |
798 | |
799 private: | |
800 void remove_extra_zeroes(); | |
801 | |
802 // Find out where a captured store should be placed (or already is placed). | |
803 int captured_store_insertion_point(intptr_t start, int size_in_bytes, | |
804 PhaseTransform* phase); | |
805 | |
806 static intptr_t get_store_offset(Node* st, PhaseTransform* phase); | |
807 | |
808 Node* make_raw_address(intptr_t offset, PhaseTransform* phase); | |
809 | |
810 bool detect_init_independence(Node* n, bool st_is_pinned, int& count); | |
811 | |
812 void coalesce_subword_stores(intptr_t header_size, Node* size_in_bytes, | |
813 PhaseGVN* phase); | |
814 | |
815 intptr_t find_next_fullword_store(uint i, PhaseGVN* phase); | |
816 }; | |
817 | |
818 //------------------------------MergeMem--------------------------------------- | |
819 // (See comment in memnode.cpp near MergeMemNode::MergeMemNode for semantics.) | |
820 class MergeMemNode: public Node { | |
821 virtual uint hash() const ; // { return NO_HASH; } | |
822 virtual uint cmp( const Node &n ) const ; // Always fail, except on self | |
823 friend class MergeMemStream; | |
824 MergeMemNode(Node* def); // clients use MergeMemNode::make | |
825 | |
826 public: | |
827 // If the input is a whole memory state, clone it with all its slices intact. | |
828 // Otherwise, make a new memory state with just that base memory input. | |
829 // In either case, the result is a newly created MergeMem. | |
830 static MergeMemNode* make(Compile* C, Node* base_memory); | |
831 | |
832 virtual int Opcode() const; | |
833 virtual Node *Identity( PhaseTransform *phase ); | |
834 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape); | |
835 virtual uint ideal_reg() const { return NotAMachineReg; } | |
836 virtual uint match_edge(uint idx) const { return 0; } | |
837 virtual const RegMask &out_RegMask() const; | |
838 virtual const Type *bottom_type() const { return Type::MEMORY; } | |
839 virtual const TypePtr *adr_type() const { return TypePtr::BOTTOM; } | |
840 // sparse accessors | |
841 // Fetch the previously stored "set_memory_at", or else the base memory. | |
842 // (Caller should clone it if it is a phi-nest.) | |
843 Node* memory_at(uint alias_idx) const; | |
844 // set the memory, regardless of its previous value | |
845 void set_memory_at(uint alias_idx, Node* n); | |
846 // the "base" is the memory that provides the non-finite support | |
847 Node* base_memory() const { return in(Compile::AliasIdxBot); } | |
848 // warning: setting the base can implicitly set any of the other slices too | |
849 void set_base_memory(Node* def); | |
850 // sentinel value which denotes a copy of the base memory: | |
851 Node* empty_memory() const { return in(Compile::AliasIdxTop); } | |
852 static Node* make_empty_memory(); // where the sentinel comes from | |
853 bool is_empty_memory(Node* n) const { assert((n == empty_memory()) == n->is_top(), "sanity"); return n->is_top(); } | |
854 // hook for the iterator, to perform any necessary setup | |
855 void iteration_setup(const MergeMemNode* other = NULL); | |
856 // push sentinels until I am at least as long as the other (semantic no-op) | |
857 void grow_to_match(const MergeMemNode* other); | |
858 bool verify_sparse() const PRODUCT_RETURN0; | |
859 #ifndef PRODUCT | |
860 virtual void dump_spec(outputStream *st) const; | |
861 #endif | |
862 }; | |
863 | |
864 class MergeMemStream : public StackObj { | |
865 private: | |
866 MergeMemNode* _mm; | |
867 const MergeMemNode* _mm2; // optional second guy, contributes non-empty iterations | |
868 Node* _mm_base; // loop-invariant base memory of _mm | |
869 int _idx; | |
870 int _cnt; | |
871 Node* _mem; | |
872 Node* _mem2; | |
873 int _cnt2; | |
874 | |
875 void init(MergeMemNode* mm, const MergeMemNode* mm2 = NULL) { | |
876 // subsume_node will break sparseness at times, whenever a memory slice | |
877 // folds down to a copy of the base ("fat") memory. In such a case, | |
878 // the raw edge will update to base, although it should be top. | |
879 // This iterator will recognize either top or base_memory as an | |
880 // "empty" slice. See is_empty, is_empty2, and next below. | |
881 // | |
882 // The sparseness property is repaired in MergeMemNode::Ideal. | |
883 // As long as access to a MergeMem goes through this iterator | |
884 // or the memory_at accessor, flaws in the sparseness will | |
885 // never be observed. | |
886 // | |
887 // Also, iteration_setup repairs sparseness. | |
888 assert(mm->verify_sparse(), "please, no dups of base"); | |
889 assert(mm2==NULL || mm2->verify_sparse(), "please, no dups of base"); | |
890 | |
891 _mm = mm; | |
892 _mm_base = mm->base_memory(); | |
893 _mm2 = mm2; | |
894 _cnt = mm->req(); | |
895 _idx = Compile::AliasIdxBot-1; // start at the base memory | |
896 _mem = NULL; | |
897 _mem2 = NULL; | |
898 } | |
899 | |
900 #ifdef ASSERT | |
901 Node* check_memory() const { | |
902 if (at_base_memory()) | |
903 return _mm->base_memory(); | |
904 else if ((uint)_idx < _mm->req() && !_mm->in(_idx)->is_top()) | |
905 return _mm->memory_at(_idx); | |
906 else | |
907 return _mm_base; | |
908 } | |
909 Node* check_memory2() const { | |
910 return at_base_memory()? _mm2->base_memory(): _mm2->memory_at(_idx); | |
911 } | |
912 #endif | |
913 | |
914 static bool match_memory(Node* mem, const MergeMemNode* mm, int idx) PRODUCT_RETURN0; | |
915 void assert_synch() const { | |
916 assert(!_mem || _idx >= _cnt || match_memory(_mem, _mm, _idx), | |
917 "no side-effects except through the stream"); | |
918 } | |
919 | |
920 public: | |
921 | |
922 // expected usages: | |
923 // for (MergeMemStream mms(mem->is_MergeMem()); next_non_empty(); ) { ... } | |
924 // for (MergeMemStream mms(mem1, mem2); next_non_empty2(); ) { ... } | |
925 | |
926 // iterate over one merge | |
927 MergeMemStream(MergeMemNode* mm) { | |
928 mm->iteration_setup(); | |
929 init(mm); | |
930 debug_only(_cnt2 = 999); | |
931 } | |
932 // iterate in parallel over two merges | |
933 // only iterates through non-empty elements of mm2 | |
934 MergeMemStream(MergeMemNode* mm, const MergeMemNode* mm2) { | |
935 assert(mm2, "second argument must be a MergeMem also"); | |
936 ((MergeMemNode*)mm2)->iteration_setup(); // update hidden state | |
937 mm->iteration_setup(mm2); | |
938 init(mm, mm2); | |
939 _cnt2 = mm2->req(); | |
940 } | |
941 #ifdef ASSERT | |
942 ~MergeMemStream() { | |
943 assert_synch(); | |
944 } | |
945 #endif | |
946 | |
947 MergeMemNode* all_memory() const { | |
948 return _mm; | |
949 } | |
950 Node* base_memory() const { | |
951 assert(_mm_base == _mm->base_memory(), "no update to base memory, please"); | |
952 return _mm_base; | |
953 } | |
954 const MergeMemNode* all_memory2() const { | |
955 assert(_mm2 != NULL, ""); | |
956 return _mm2; | |
957 } | |
958 bool at_base_memory() const { | |
959 return _idx == Compile::AliasIdxBot; | |
960 } | |
961 int alias_idx() const { | |
962 assert(_mem, "must call next 1st"); | |
963 return _idx; | |
964 } | |
965 | |
966 const TypePtr* adr_type() const { | |
967 return Compile::current()->get_adr_type(alias_idx()); | |
968 } | |
969 | |
970 const TypePtr* adr_type(Compile* C) const { | |
971 return C->get_adr_type(alias_idx()); | |
972 } | |
973 bool is_empty() const { | |
974 assert(_mem, "must call next 1st"); | |
975 assert(_mem->is_top() == (_mem==_mm->empty_memory()), "correct sentinel"); | |
976 return _mem->is_top(); | |
977 } | |
978 bool is_empty2() const { | |
979 assert(_mem2, "must call next 1st"); | |
980 assert(_mem2->is_top() == (_mem2==_mm2->empty_memory()), "correct sentinel"); | |
981 return _mem2->is_top(); | |
982 } | |
983 Node* memory() const { | |
984 assert(!is_empty(), "must not be empty"); | |
985 assert_synch(); | |
986 return _mem; | |
987 } | |
988 // get the current memory, regardless of empty or non-empty status | |
989 Node* force_memory() const { | |
990 assert(!is_empty() || !at_base_memory(), ""); | |
991 // Use _mm_base to defend against updates to _mem->base_memory(). | |
992 Node *mem = _mem->is_top() ? _mm_base : _mem; | |
993 assert(mem == check_memory(), ""); | |
994 return mem; | |
995 } | |
996 Node* memory2() const { | |
997 assert(_mem2 == check_memory2(), ""); | |
998 return _mem2; | |
999 } | |
1000 void set_memory(Node* mem) { | |
1001 if (at_base_memory()) { | |
1002 // Note that this does not change the invariant _mm_base. | |
1003 _mm->set_base_memory(mem); | |
1004 } else { | |
1005 _mm->set_memory_at(_idx, mem); | |
1006 } | |
1007 _mem = mem; | |
1008 assert_synch(); | |
1009 } | |
1010 | |
1011 // Recover from a side effect to the MergeMemNode. | |
1012 void set_memory() { | |
1013 _mem = _mm->in(_idx); | |
1014 } | |
1015 | |
1016 bool next() { return next(false); } | |
1017 bool next2() { return next(true); } | |
1018 | |
1019 bool next_non_empty() { return next_non_empty(false); } | |
1020 bool next_non_empty2() { return next_non_empty(true); } | |
1021 // next_non_empty2 can yield states where is_empty() is true | |
1022 | |
1023 private: | |
1024 // find the next item, which might be empty | |
1025 bool next(bool have_mm2) { | |
1026 assert((_mm2 != NULL) == have_mm2, "use other next"); | |
1027 assert_synch(); | |
1028 if (++_idx < _cnt) { | |
1029 // Note: This iterator allows _mm to be non-sparse. | |
1030 // It behaves the same whether _mem is top or base_memory. | |
1031 _mem = _mm->in(_idx); | |
1032 if (have_mm2) | |
1033 _mem2 = _mm2->in((_idx < _cnt2) ? _idx : Compile::AliasIdxTop); | |
1034 return true; | |
1035 } | |
1036 return false; | |
1037 } | |
1038 | |
1039 // find the next non-empty item | |
1040 bool next_non_empty(bool have_mm2) { | |
1041 while (next(have_mm2)) { | |
1042 if (!is_empty()) { | |
1043 // make sure _mem2 is filled in sensibly | |
1044 if (have_mm2 && _mem2->is_top()) _mem2 = _mm2->base_memory(); | |
1045 return true; | |
1046 } else if (have_mm2 && !is_empty2()) { | |
1047 return true; // is_empty() == true | |
1048 } | |
1049 } | |
1050 return false; | |
1051 } | |
1052 }; | |
1053 | |
1054 //------------------------------Prefetch--------------------------------------- | |
1055 | |
1056 // Non-faulting prefetch load. Prefetch for many reads. | |
1057 class PrefetchReadNode : public Node { | |
1058 public: | |
1059 PrefetchReadNode(Node *abio, Node *adr) : Node(0,abio,adr) {} | |
1060 virtual int Opcode() const; | |
1061 virtual uint ideal_reg() const { return NotAMachineReg; } | |
1062 virtual uint match_edge(uint idx) const { return idx==2; } | |
1063 virtual const Type *bottom_type() const { return Type::ABIO; } | |
1064 }; | |
1065 | |
1066 // Non-faulting prefetch load. Prefetch for many reads & many writes. | |
1067 class PrefetchWriteNode : public Node { | |
1068 public: | |
1069 PrefetchWriteNode(Node *abio, Node *adr) : Node(0,abio,adr) {} | |
1070 virtual int Opcode() const; | |
1071 virtual uint ideal_reg() const { return NotAMachineReg; } | |
1072 virtual uint match_edge(uint idx) const { return idx==2; } | |
1073 virtual const Type *bottom_type() const { return Type::ABIO; } | |
1074 }; |