Fri, 15 Oct 2010 09:38:20 +0200
6991577: add IfOp optimization to C1
Summary: Ifop optimization for c1
Reviewed-by: never, phh, iveresov
1 /*
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 // Predefined classes
26 class ciField;
27 class ValueStack;
28 class InstructionPrinter;
29 class IRScope;
30 class LIR_OprDesc;
31 typedef LIR_OprDesc* LIR_Opr;
34 // Instruction class hierarchy
35 //
36 // All leaf classes in the class hierarchy are concrete classes
37 // (i.e., are instantiated). All other classes are abstract and
38 // serve factoring.
40 class Instruction;
41 class Phi;
42 class Local;
43 class Constant;
44 class AccessField;
45 class LoadField;
46 class StoreField;
47 class AccessArray;
48 class ArrayLength;
49 class AccessIndexed;
50 class LoadIndexed;
51 class StoreIndexed;
52 class NegateOp;
53 class Op2;
54 class ArithmeticOp;
55 class ShiftOp;
56 class LogicOp;
57 class CompareOp;
58 class IfOp;
59 class Convert;
60 class NullCheck;
61 class OsrEntry;
62 class ExceptionObject;
63 class StateSplit;
64 class Invoke;
65 class NewInstance;
66 class NewArray;
67 class NewTypeArray;
68 class NewObjectArray;
69 class NewMultiArray;
70 class TypeCheck;
71 class CheckCast;
72 class InstanceOf;
73 class AccessMonitor;
74 class MonitorEnter;
75 class MonitorExit;
76 class Intrinsic;
77 class BlockBegin;
78 class BlockEnd;
79 class Goto;
80 class If;
81 class IfInstanceOf;
82 class Switch;
83 class TableSwitch;
84 class LookupSwitch;
85 class Return;
86 class Throw;
87 class Base;
88 class RoundFP;
89 class UnsafeOp;
90 class UnsafeRawOp;
91 class UnsafeGetRaw;
92 class UnsafePutRaw;
93 class UnsafeObjectOp;
94 class UnsafeGetObject;
95 class UnsafePutObject;
96 class UnsafePrefetch;
97 class UnsafePrefetchRead;
98 class UnsafePrefetchWrite;
99 class ProfileCall;
100 class ProfileInvoke;
102 // A Value is a reference to the instruction creating the value
103 typedef Instruction* Value;
104 define_array(ValueArray, Value)
105 define_stack(Values, ValueArray)
107 define_array(ValueStackArray, ValueStack*)
108 define_stack(ValueStackStack, ValueStackArray)
110 // BlockClosure is the base class for block traversal/iteration.
112 class BlockClosure: public CompilationResourceObj {
113 public:
114 virtual void block_do(BlockBegin* block) = 0;
115 };
118 // A simple closure class for visiting the values of an Instruction
119 class ValueVisitor: public StackObj {
120 public:
121 virtual void visit(Value* v) = 0;
122 };
125 // Some array and list classes
126 define_array(BlockBeginArray, BlockBegin*)
127 define_stack(_BlockList, BlockBeginArray)
129 class BlockList: public _BlockList {
130 public:
131 BlockList(): _BlockList() {}
132 BlockList(const int size): _BlockList(size) {}
133 BlockList(const int size, BlockBegin* init): _BlockList(size, init) {}
135 void iterate_forward(BlockClosure* closure);
136 void iterate_backward(BlockClosure* closure);
137 void blocks_do(void f(BlockBegin*));
138 void values_do(ValueVisitor* f);
139 void print(bool cfg_only = false, bool live_only = false) PRODUCT_RETURN;
140 };
143 // InstructionVisitors provide type-based dispatch for instructions.
144 // For each concrete Instruction class X, a virtual function do_X is
145 // provided. Functionality that needs to be implemented for all classes
146 // (e.g., printing, code generation) is factored out into a specialised
147 // visitor instead of added to the Instruction classes itself.
149 class InstructionVisitor: public StackObj {
150 public:
151 virtual void do_Phi (Phi* x) = 0;
152 virtual void do_Local (Local* x) = 0;
153 virtual void do_Constant (Constant* x) = 0;
154 virtual void do_LoadField (LoadField* x) = 0;
155 virtual void do_StoreField (StoreField* x) = 0;
156 virtual void do_ArrayLength (ArrayLength* x) = 0;
157 virtual void do_LoadIndexed (LoadIndexed* x) = 0;
158 virtual void do_StoreIndexed (StoreIndexed* x) = 0;
159 virtual void do_NegateOp (NegateOp* x) = 0;
160 virtual void do_ArithmeticOp (ArithmeticOp* x) = 0;
161 virtual void do_ShiftOp (ShiftOp* x) = 0;
162 virtual void do_LogicOp (LogicOp* x) = 0;
163 virtual void do_CompareOp (CompareOp* x) = 0;
164 virtual void do_IfOp (IfOp* x) = 0;
165 virtual void do_Convert (Convert* x) = 0;
166 virtual void do_NullCheck (NullCheck* x) = 0;
167 virtual void do_Invoke (Invoke* x) = 0;
168 virtual void do_NewInstance (NewInstance* x) = 0;
169 virtual void do_NewTypeArray (NewTypeArray* x) = 0;
170 virtual void do_NewObjectArray (NewObjectArray* x) = 0;
171 virtual void do_NewMultiArray (NewMultiArray* x) = 0;
172 virtual void do_CheckCast (CheckCast* x) = 0;
173 virtual void do_InstanceOf (InstanceOf* x) = 0;
174 virtual void do_MonitorEnter (MonitorEnter* x) = 0;
175 virtual void do_MonitorExit (MonitorExit* x) = 0;
176 virtual void do_Intrinsic (Intrinsic* x) = 0;
177 virtual void do_BlockBegin (BlockBegin* x) = 0;
178 virtual void do_Goto (Goto* x) = 0;
179 virtual void do_If (If* x) = 0;
180 virtual void do_IfInstanceOf (IfInstanceOf* x) = 0;
181 virtual void do_TableSwitch (TableSwitch* x) = 0;
182 virtual void do_LookupSwitch (LookupSwitch* x) = 0;
183 virtual void do_Return (Return* x) = 0;
184 virtual void do_Throw (Throw* x) = 0;
185 virtual void do_Base (Base* x) = 0;
186 virtual void do_OsrEntry (OsrEntry* x) = 0;
187 virtual void do_ExceptionObject(ExceptionObject* x) = 0;
188 virtual void do_RoundFP (RoundFP* x) = 0;
189 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x) = 0;
190 virtual void do_UnsafePutRaw (UnsafePutRaw* x) = 0;
191 virtual void do_UnsafeGetObject(UnsafeGetObject* x) = 0;
192 virtual void do_UnsafePutObject(UnsafePutObject* x) = 0;
193 virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x) = 0;
194 virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) = 0;
195 virtual void do_ProfileCall (ProfileCall* x) = 0;
196 virtual void do_ProfileInvoke (ProfileInvoke* x) = 0;
197 };
200 // Hashing support
201 //
202 // Note: This hash functions affect the performance
203 // of ValueMap - make changes carefully!
205 #define HASH1(x1 ) ((intx)(x1))
206 #define HASH2(x1, x2 ) ((HASH1(x1 ) << 7) ^ HASH1(x2))
207 #define HASH3(x1, x2, x3 ) ((HASH2(x1, x2 ) << 7) ^ HASH1(x3))
208 #define HASH4(x1, x2, x3, x4) ((HASH3(x1, x2, x3) << 7) ^ HASH1(x4))
211 // The following macros are used to implement instruction-specific hashing.
212 // By default, each instruction implements hash() and is_equal(Value), used
213 // for value numbering/common subexpression elimination. The default imple-
214 // mentation disables value numbering. Each instruction which can be value-
215 // numbered, should define corresponding hash() and is_equal(Value) functions
216 // via the macros below. The f arguments specify all the values/op codes, etc.
217 // that need to be identical for two instructions to be identical.
218 //
219 // Note: The default implementation of hash() returns 0 in order to indicate
220 // that the instruction should not be considered for value numbering.
221 // The currently used hash functions do not guarantee that never a 0
222 // is produced. While this is still correct, it may be a performance
223 // bug (no value numbering for that node). However, this situation is
224 // so unlikely, that we are not going to handle it specially.
226 #define HASHING1(class_name, enabled, f1) \
227 virtual intx hash() const { \
228 return (enabled) ? HASH2(name(), f1) : 0; \
229 } \
230 virtual bool is_equal(Value v) const { \
231 if (!(enabled) ) return false; \
232 class_name* _v = v->as_##class_name(); \
233 if (_v == NULL ) return false; \
234 if (f1 != _v->f1) return false; \
235 return true; \
236 } \
239 #define HASHING2(class_name, enabled, f1, f2) \
240 virtual intx hash() const { \
241 return (enabled) ? HASH3(name(), f1, f2) : 0; \
242 } \
243 virtual bool is_equal(Value v) const { \
244 if (!(enabled) ) return false; \
245 class_name* _v = v->as_##class_name(); \
246 if (_v == NULL ) return false; \
247 if (f1 != _v->f1) return false; \
248 if (f2 != _v->f2) return false; \
249 return true; \
250 } \
253 #define HASHING3(class_name, enabled, f1, f2, f3) \
254 virtual intx hash() const { \
255 return (enabled) ? HASH4(name(), f1, f2, f3) : 0; \
256 } \
257 virtual bool is_equal(Value v) const { \
258 if (!(enabled) ) return false; \
259 class_name* _v = v->as_##class_name(); \
260 if (_v == NULL ) return false; \
261 if (f1 != _v->f1) return false; \
262 if (f2 != _v->f2) return false; \
263 if (f3 != _v->f3) return false; \
264 return true; \
265 } \
268 // The mother of all instructions...
270 class Instruction: public CompilationResourceObj {
271 private:
272 int _id; // the unique instruction id
273 #ifndef PRODUCT
274 int _printable_bci; // the bci of the instruction for printing
275 #endif
276 int _use_count; // the number of instructions refering to this value (w/o prev/next); only roots can have use count = 0 or > 1
277 int _pin_state; // set of PinReason describing the reason for pinning
278 ValueType* _type; // the instruction value type
279 Instruction* _next; // the next instruction if any (NULL for BlockEnd instructions)
280 Instruction* _subst; // the substitution instruction if any
281 LIR_Opr _operand; // LIR specific information
282 unsigned int _flags; // Flag bits
284 ValueStack* _state_before; // Copy of state with input operands still on stack (or NULL)
285 ValueStack* _exception_state; // Copy of state for exception handling
286 XHandlers* _exception_handlers; // Flat list of exception handlers covering this instruction
288 friend class UseCountComputer;
289 friend class BlockBegin;
291 void update_exception_state(ValueStack* state);
293 bool has_printable_bci() const { return NOT_PRODUCT(_printable_bci != -99) PRODUCT_ONLY(false); }
295 protected:
296 void set_type(ValueType* type) {
297 assert(type != NULL, "type must exist");
298 _type = type;
299 }
301 public:
302 void* operator new(size_t size) {
303 Compilation* c = Compilation::current();
304 void* res = c->arena()->Amalloc(size);
305 ((Instruction*)res)->_id = c->get_next_id();
306 return res;
307 }
309 enum InstructionFlag {
310 NeedsNullCheckFlag = 0,
311 CanTrapFlag,
312 DirectCompareFlag,
313 IsEliminatedFlag,
314 IsInitializedFlag,
315 IsLoadedFlag,
316 IsSafepointFlag,
317 IsStaticFlag,
318 IsStrictfpFlag,
319 NeedsStoreCheckFlag,
320 NeedsWriteBarrierFlag,
321 PreservesStateFlag,
322 TargetIsFinalFlag,
323 TargetIsLoadedFlag,
324 TargetIsStrictfpFlag,
325 UnorderedIsTrueFlag,
326 NeedsPatchingFlag,
327 ThrowIncompatibleClassChangeErrorFlag,
328 ProfileMDOFlag,
329 IsLinkedInBlockFlag,
330 InstructionLastFlag
331 };
333 public:
334 bool check_flag(InstructionFlag id) const { return (_flags & (1 << id)) != 0; }
335 void set_flag(InstructionFlag id, bool f) { _flags = f ? (_flags | (1 << id)) : (_flags & ~(1 << id)); };
337 // 'globally' used condition values
338 enum Condition {
339 eql, neq, lss, leq, gtr, geq
340 };
342 // Instructions may be pinned for many reasons and under certain conditions
343 // with enough knowledge it's possible to safely unpin them.
344 enum PinReason {
345 PinUnknown = 1 << 0
346 , PinExplicitNullCheck = 1 << 3
347 , PinStackForStateSplit= 1 << 12
348 , PinStateSplitConstructor= 1 << 13
349 , PinGlobalValueNumbering= 1 << 14
350 };
352 static Condition mirror(Condition cond);
353 static Condition negate(Condition cond);
355 // initialization
356 static int number_of_instructions() {
357 return Compilation::current()->number_of_instructions();
358 }
360 // creation
361 Instruction(ValueType* type, ValueStack* state_before = NULL, bool type_is_constant = false)
362 : _use_count(0)
363 #ifndef PRODUCT
364 , _printable_bci(-99)
365 #endif
366 , _pin_state(0)
367 , _type(type)
368 , _next(NULL)
369 , _subst(NULL)
370 , _flags(0)
371 , _operand(LIR_OprFact::illegalOpr)
372 , _state_before(state_before)
373 , _exception_handlers(NULL)
374 {
375 check_state(state_before);
376 assert(type != NULL && (!type->is_constant() || type_is_constant), "type must exist");
377 update_exception_state(_state_before);
378 }
380 // accessors
381 int id() const { return _id; }
382 #ifndef PRODUCT
383 int printable_bci() const { assert(has_printable_bci(), "_printable_bci should have been set"); return _printable_bci; }
384 void set_printable_bci(int bci) { NOT_PRODUCT(_printable_bci = bci;) }
385 #endif
386 int use_count() const { return _use_count; }
387 int pin_state() const { return _pin_state; }
388 bool is_pinned() const { return _pin_state != 0 || PinAllInstructions; }
389 ValueType* type() const { return _type; }
390 Instruction* prev(BlockBegin* block); // use carefully, expensive operation
391 Instruction* next() const { return _next; }
392 bool has_subst() const { return _subst != NULL; }
393 Instruction* subst() { return _subst == NULL ? this : _subst->subst(); }
394 LIR_Opr operand() const { return _operand; }
396 void set_needs_null_check(bool f) { set_flag(NeedsNullCheckFlag, f); }
397 bool needs_null_check() const { return check_flag(NeedsNullCheckFlag); }
398 bool is_linked() const { return check_flag(IsLinkedInBlockFlag); }
399 bool can_be_linked() { return as_Local() == NULL && as_Phi() == NULL; }
401 bool has_uses() const { return use_count() > 0; }
402 ValueStack* state_before() const { return _state_before; }
403 ValueStack* exception_state() const { return _exception_state; }
404 virtual bool needs_exception_state() const { return true; }
405 XHandlers* exception_handlers() const { return _exception_handlers; }
407 // manipulation
408 void pin(PinReason reason) { _pin_state |= reason; }
409 void pin() { _pin_state |= PinUnknown; }
410 // DANGEROUS: only used by EliminateStores
411 void unpin(PinReason reason) { assert((reason & PinUnknown) == 0, "can't unpin unknown state"); _pin_state &= ~reason; }
413 Instruction* set_next(Instruction* next) {
414 assert(next->has_printable_bci(), "_printable_bci should have been set");
415 assert(next != NULL, "must not be NULL");
416 assert(as_BlockEnd() == NULL, "BlockEnd instructions must have no next");
417 assert(next->can_be_linked(), "shouldn't link these instructions into list");
419 next->set_flag(Instruction::IsLinkedInBlockFlag, true);
420 _next = next;
421 return next;
422 }
424 Instruction* set_next(Instruction* next, int bci) {
425 #ifndef PRODUCT
426 next->set_printable_bci(bci);
427 #endif
428 return set_next(next);
429 }
431 void set_subst(Instruction* subst) {
432 assert(subst == NULL ||
433 type()->base() == subst->type()->base() ||
434 subst->type()->base() == illegalType, "type can't change");
435 _subst = subst;
436 }
437 void set_exception_handlers(XHandlers *xhandlers) { _exception_handlers = xhandlers; }
438 void set_exception_state(ValueStack* s) { check_state(s); _exception_state = s; }
440 // machine-specifics
441 void set_operand(LIR_Opr operand) { assert(operand != LIR_OprFact::illegalOpr, "operand must exist"); _operand = operand; }
442 void clear_operand() { _operand = LIR_OprFact::illegalOpr; }
444 // generic
445 virtual Instruction* as_Instruction() { return this; } // to satisfy HASHING1 macro
446 virtual Phi* as_Phi() { return NULL; }
447 virtual Local* as_Local() { return NULL; }
448 virtual Constant* as_Constant() { return NULL; }
449 virtual AccessField* as_AccessField() { return NULL; }
450 virtual LoadField* as_LoadField() { return NULL; }
451 virtual StoreField* as_StoreField() { return NULL; }
452 virtual AccessArray* as_AccessArray() { return NULL; }
453 virtual ArrayLength* as_ArrayLength() { return NULL; }
454 virtual AccessIndexed* as_AccessIndexed() { return NULL; }
455 virtual LoadIndexed* as_LoadIndexed() { return NULL; }
456 virtual StoreIndexed* as_StoreIndexed() { return NULL; }
457 virtual NegateOp* as_NegateOp() { return NULL; }
458 virtual Op2* as_Op2() { return NULL; }
459 virtual ArithmeticOp* as_ArithmeticOp() { return NULL; }
460 virtual ShiftOp* as_ShiftOp() { return NULL; }
461 virtual LogicOp* as_LogicOp() { return NULL; }
462 virtual CompareOp* as_CompareOp() { return NULL; }
463 virtual IfOp* as_IfOp() { return NULL; }
464 virtual Convert* as_Convert() { return NULL; }
465 virtual NullCheck* as_NullCheck() { return NULL; }
466 virtual OsrEntry* as_OsrEntry() { return NULL; }
467 virtual StateSplit* as_StateSplit() { return NULL; }
468 virtual Invoke* as_Invoke() { return NULL; }
469 virtual NewInstance* as_NewInstance() { return NULL; }
470 virtual NewArray* as_NewArray() { return NULL; }
471 virtual NewTypeArray* as_NewTypeArray() { return NULL; }
472 virtual NewObjectArray* as_NewObjectArray() { return NULL; }
473 virtual NewMultiArray* as_NewMultiArray() { return NULL; }
474 virtual TypeCheck* as_TypeCheck() { return NULL; }
475 virtual CheckCast* as_CheckCast() { return NULL; }
476 virtual InstanceOf* as_InstanceOf() { return NULL; }
477 virtual AccessMonitor* as_AccessMonitor() { return NULL; }
478 virtual MonitorEnter* as_MonitorEnter() { return NULL; }
479 virtual MonitorExit* as_MonitorExit() { return NULL; }
480 virtual Intrinsic* as_Intrinsic() { return NULL; }
481 virtual BlockBegin* as_BlockBegin() { return NULL; }
482 virtual BlockEnd* as_BlockEnd() { return NULL; }
483 virtual Goto* as_Goto() { return NULL; }
484 virtual If* as_If() { return NULL; }
485 virtual IfInstanceOf* as_IfInstanceOf() { return NULL; }
486 virtual TableSwitch* as_TableSwitch() { return NULL; }
487 virtual LookupSwitch* as_LookupSwitch() { return NULL; }
488 virtual Return* as_Return() { return NULL; }
489 virtual Throw* as_Throw() { return NULL; }
490 virtual Base* as_Base() { return NULL; }
491 virtual RoundFP* as_RoundFP() { return NULL; }
492 virtual ExceptionObject* as_ExceptionObject() { return NULL; }
493 virtual UnsafeOp* as_UnsafeOp() { return NULL; }
495 virtual void visit(InstructionVisitor* v) = 0;
497 virtual bool can_trap() const { return false; }
499 virtual void input_values_do(ValueVisitor* f) = 0;
500 virtual void state_values_do(ValueVisitor* f);
501 virtual void other_values_do(ValueVisitor* f) { /* usually no other - override on demand */ }
502 void values_do(ValueVisitor* f) { input_values_do(f); state_values_do(f); other_values_do(f); }
504 virtual ciType* exact_type() const { return NULL; }
505 virtual ciType* declared_type() const { return NULL; }
507 // hashing
508 virtual const char* name() const = 0;
509 HASHING1(Instruction, false, id()) // hashing disabled by default
511 // debugging
512 static void check_state(ValueStack* state) PRODUCT_RETURN;
513 void print() PRODUCT_RETURN;
514 void print_line() PRODUCT_RETURN;
515 void print(InstructionPrinter& ip) PRODUCT_RETURN;
516 };
519 // The following macros are used to define base (i.e., non-leaf)
520 // and leaf instruction classes. They define class-name related
521 // generic functionality in one place.
523 #define BASE(class_name, super_class_name) \
524 class class_name: public super_class_name { \
525 public: \
526 virtual class_name* as_##class_name() { return this; } \
529 #define LEAF(class_name, super_class_name) \
530 BASE(class_name, super_class_name) \
531 public: \
532 virtual const char* name() const { return #class_name; } \
533 virtual void visit(InstructionVisitor* v) { v->do_##class_name(this); } \
536 // Debugging support
539 #ifdef ASSERT
540 class AssertValues: public ValueVisitor {
541 void visit(Value* x) { assert((*x) != NULL, "value must exist"); }
542 };
543 #define ASSERT_VALUES { AssertValues assert_value; values_do(&assert_value); }
544 #else
545 #define ASSERT_VALUES
546 #endif // ASSERT
549 // A Phi is a phi function in the sense of SSA form. It stands for
550 // the value of a local variable at the beginning of a join block.
551 // A Phi consists of n operands, one for every incoming branch.
553 LEAF(Phi, Instruction)
554 private:
555 BlockBegin* _block; // the block to which the phi function belongs
556 int _pf_flags; // the flags of the phi function
557 int _index; // to value on operand stack (index < 0) or to local
558 public:
559 // creation
560 Phi(ValueType* type, BlockBegin* b, int index)
561 : Instruction(type->base())
562 , _pf_flags(0)
563 , _block(b)
564 , _index(index)
565 {
566 if (type->is_illegal()) {
567 make_illegal();
568 }
569 }
571 // flags
572 enum Flag {
573 no_flag = 0,
574 visited = 1 << 0,
575 cannot_simplify = 1 << 1
576 };
578 // accessors
579 bool is_local() const { return _index >= 0; }
580 bool is_on_stack() const { return !is_local(); }
581 int local_index() const { assert(is_local(), ""); return _index; }
582 int stack_index() const { assert(is_on_stack(), ""); return -(_index+1); }
584 Value operand_at(int i) const;
585 int operand_count() const;
587 BlockBegin* block() const { return _block; }
589 void set(Flag f) { _pf_flags |= f; }
590 void clear(Flag f) { _pf_flags &= ~f; }
591 bool is_set(Flag f) const { return (_pf_flags & f) != 0; }
593 // Invalidates phis corresponding to merges of locals of two different types
594 // (these should never be referenced, otherwise the bytecodes are illegal)
595 void make_illegal() {
596 set(cannot_simplify);
597 set_type(illegalType);
598 }
600 bool is_illegal() const {
601 return type()->is_illegal();
602 }
604 // generic
605 virtual void input_values_do(ValueVisitor* f) {
606 }
607 };
610 // A local is a placeholder for an incoming argument to a function call.
611 LEAF(Local, Instruction)
612 private:
613 int _java_index; // the local index within the method to which the local belongs
614 public:
615 // creation
616 Local(ValueType* type, int index)
617 : Instruction(type)
618 , _java_index(index)
619 {}
621 // accessors
622 int java_index() const { return _java_index; }
624 // generic
625 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
626 };
629 LEAF(Constant, Instruction)
630 public:
631 // creation
632 Constant(ValueType* type):
633 Instruction(type, NULL, true)
634 {
635 assert(type->is_constant(), "must be a constant");
636 }
638 Constant(ValueType* type, ValueStack* state_before):
639 Instruction(type, state_before, true)
640 {
641 assert(state_before != NULL, "only used for constants which need patching");
642 assert(type->is_constant(), "must be a constant");
643 // since it's patching it needs to be pinned
644 pin();
645 }
647 virtual bool can_trap() const { return state_before() != NULL; }
648 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
650 virtual intx hash() const;
651 virtual bool is_equal(Value v) const;
654 enum CompareResult { not_comparable = -1, cond_false, cond_true };
656 virtual CompareResult compare(Instruction::Condition condition, Value right) const;
657 BlockBegin* compare(Instruction::Condition cond, Value right,
658 BlockBegin* true_sux, BlockBegin* false_sux) const {
659 switch (compare(cond, right)) {
660 case not_comparable:
661 return NULL;
662 case cond_false:
663 return false_sux;
664 case cond_true:
665 return true_sux;
666 default:
667 ShouldNotReachHere();
668 return NULL;
669 }
670 }
671 };
674 BASE(AccessField, Instruction)
675 private:
676 Value _obj;
677 int _offset;
678 ciField* _field;
679 NullCheck* _explicit_null_check; // For explicit null check elimination
681 public:
682 // creation
683 AccessField(Value obj, int offset, ciField* field, bool is_static,
684 ValueStack* state_before, bool is_loaded, bool is_initialized)
685 : Instruction(as_ValueType(field->type()->basic_type()), state_before)
686 , _obj(obj)
687 , _offset(offset)
688 , _field(field)
689 , _explicit_null_check(NULL)
690 {
691 set_needs_null_check(!is_static);
692 set_flag(IsLoadedFlag, is_loaded);
693 set_flag(IsInitializedFlag, is_initialized);
694 set_flag(IsStaticFlag, is_static);
695 ASSERT_VALUES
696 if (!is_loaded || (PatchALot && !field->is_volatile())) {
697 // need to patch if the holder wasn't loaded or we're testing
698 // using PatchALot. Don't allow PatchALot for fields which are
699 // known to be volatile they aren't patchable.
700 set_flag(NeedsPatchingFlag, true);
701 }
702 // pin of all instructions with memory access
703 pin();
704 }
706 // accessors
707 Value obj() const { return _obj; }
708 int offset() const { return _offset; }
709 ciField* field() const { return _field; }
710 BasicType field_type() const { return _field->type()->basic_type(); }
711 bool is_static() const { return check_flag(IsStaticFlag); }
712 bool is_loaded() const { return check_flag(IsLoadedFlag); }
713 bool is_initialized() const { return check_flag(IsInitializedFlag); }
714 NullCheck* explicit_null_check() const { return _explicit_null_check; }
715 bool needs_patching() const { return check_flag(NeedsPatchingFlag); }
717 // manipulation
719 // Under certain circumstances, if a previous NullCheck instruction
720 // proved the target object non-null, we can eliminate the explicit
721 // null check and do an implicit one, simply specifying the debug
722 // information from the NullCheck. This field should only be consulted
723 // if needs_null_check() is true.
724 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
726 // generic
727 virtual bool can_trap() const { return needs_null_check() || needs_patching(); }
728 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
729 };
732 LEAF(LoadField, AccessField)
733 public:
734 // creation
735 LoadField(Value obj, int offset, ciField* field, bool is_static,
736 ValueStack* state_before, bool is_loaded, bool is_initialized)
737 : AccessField(obj, offset, field, is_static, state_before, is_loaded, is_initialized)
738 {}
740 ciType* declared_type() const;
741 ciType* exact_type() const;
743 // generic
744 HASHING2(LoadField, is_loaded() && !field()->is_volatile(), obj()->subst(), offset()) // cannot be eliminated if not yet loaded or if volatile
745 };
748 LEAF(StoreField, AccessField)
749 private:
750 Value _value;
752 public:
753 // creation
754 StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
755 ValueStack* state_before, bool is_loaded, bool is_initialized)
756 : AccessField(obj, offset, field, is_static, state_before, is_loaded, is_initialized)
757 , _value(value)
758 {
759 set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
760 ASSERT_VALUES
761 pin();
762 }
764 // accessors
765 Value value() const { return _value; }
766 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
768 // generic
769 virtual void input_values_do(ValueVisitor* f) { AccessField::input_values_do(f); f->visit(&_value); }
770 };
773 BASE(AccessArray, Instruction)
774 private:
775 Value _array;
777 public:
778 // creation
779 AccessArray(ValueType* type, Value array, ValueStack* state_before)
780 : Instruction(type, state_before)
781 , _array(array)
782 {
783 set_needs_null_check(true);
784 ASSERT_VALUES
785 pin(); // instruction with side effect (null exception or range check throwing)
786 }
788 Value array() const { return _array; }
790 // generic
791 virtual bool can_trap() const { return needs_null_check(); }
792 virtual void input_values_do(ValueVisitor* f) { f->visit(&_array); }
793 };
796 LEAF(ArrayLength, AccessArray)
797 private:
798 NullCheck* _explicit_null_check; // For explicit null check elimination
800 public:
801 // creation
802 ArrayLength(Value array, ValueStack* state_before)
803 : AccessArray(intType, array, state_before)
804 , _explicit_null_check(NULL) {}
806 // accessors
807 NullCheck* explicit_null_check() const { return _explicit_null_check; }
809 // setters
810 // See LoadField::set_explicit_null_check for documentation
811 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
813 // generic
814 HASHING1(ArrayLength, true, array()->subst())
815 };
818 BASE(AccessIndexed, AccessArray)
819 private:
820 Value _index;
821 Value _length;
822 BasicType _elt_type;
824 public:
825 // creation
826 AccessIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
827 : AccessArray(as_ValueType(elt_type), array, state_before)
828 , _index(index)
829 , _length(length)
830 , _elt_type(elt_type)
831 {
832 ASSERT_VALUES
833 }
835 // accessors
836 Value index() const { return _index; }
837 Value length() const { return _length; }
838 BasicType elt_type() const { return _elt_type; }
840 // perform elimination of range checks involving constants
841 bool compute_needs_range_check();
843 // generic
844 virtual void input_values_do(ValueVisitor* f) { AccessArray::input_values_do(f); f->visit(&_index); if (_length != NULL) f->visit(&_length); }
845 };
848 LEAF(LoadIndexed, AccessIndexed)
849 private:
850 NullCheck* _explicit_null_check; // For explicit null check elimination
852 public:
853 // creation
854 LoadIndexed(Value array, Value index, Value length, BasicType elt_type, ValueStack* state_before)
855 : AccessIndexed(array, index, length, elt_type, state_before)
856 , _explicit_null_check(NULL) {}
858 // accessors
859 NullCheck* explicit_null_check() const { return _explicit_null_check; }
861 // setters
862 // See LoadField::set_explicit_null_check for documentation
863 void set_explicit_null_check(NullCheck* check) { _explicit_null_check = check; }
865 ciType* exact_type() const;
866 ciType* declared_type() const;
868 // generic
869 HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
870 };
873 LEAF(StoreIndexed, AccessIndexed)
874 private:
875 Value _value;
877 ciMethod* _profiled_method;
878 int _profiled_bci;
879 public:
880 // creation
881 StoreIndexed(Value array, Value index, Value length, BasicType elt_type, Value value, ValueStack* state_before)
882 : AccessIndexed(array, index, length, elt_type, state_before)
883 , _value(value), _profiled_method(NULL), _profiled_bci(0)
884 {
885 set_flag(NeedsWriteBarrierFlag, (as_ValueType(elt_type)->is_object()));
886 set_flag(NeedsStoreCheckFlag, (as_ValueType(elt_type)->is_object()));
887 ASSERT_VALUES
888 pin();
889 }
891 // accessors
892 Value value() const { return _value; }
893 bool needs_write_barrier() const { return check_flag(NeedsWriteBarrierFlag); }
894 bool needs_store_check() const { return check_flag(NeedsStoreCheckFlag); }
895 // Helpers for methodDataOop profiling
896 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
897 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
898 void set_profiled_bci(int bci) { _profiled_bci = bci; }
899 bool should_profile() const { return check_flag(ProfileMDOFlag); }
900 ciMethod* profiled_method() const { return _profiled_method; }
901 int profiled_bci() const { return _profiled_bci; }
902 // generic
903 virtual void input_values_do(ValueVisitor* f) { AccessIndexed::input_values_do(f); f->visit(&_value); }
904 };
907 LEAF(NegateOp, Instruction)
908 private:
909 Value _x;
911 public:
912 // creation
913 NegateOp(Value x) : Instruction(x->type()->base()), _x(x) {
914 ASSERT_VALUES
915 }
917 // accessors
918 Value x() const { return _x; }
920 // generic
921 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); }
922 };
925 BASE(Op2, Instruction)
926 private:
927 Bytecodes::Code _op;
928 Value _x;
929 Value _y;
931 public:
932 // creation
933 Op2(ValueType* type, Bytecodes::Code op, Value x, Value y, ValueStack* state_before = NULL)
934 : Instruction(type, state_before)
935 , _op(op)
936 , _x(x)
937 , _y(y)
938 {
939 ASSERT_VALUES
940 }
942 // accessors
943 Bytecodes::Code op() const { return _op; }
944 Value x() const { return _x; }
945 Value y() const { return _y; }
947 // manipulators
948 void swap_operands() {
949 assert(is_commutative(), "operation must be commutative");
950 Value t = _x; _x = _y; _y = t;
951 }
953 // generic
954 virtual bool is_commutative() const { return false; }
955 virtual void input_values_do(ValueVisitor* f) { f->visit(&_x); f->visit(&_y); }
956 };
959 LEAF(ArithmeticOp, Op2)
960 public:
961 // creation
962 ArithmeticOp(Bytecodes::Code op, Value x, Value y, bool is_strictfp, ValueStack* state_before)
963 : Op2(x->type()->meet(y->type()), op, x, y, state_before)
964 {
965 set_flag(IsStrictfpFlag, is_strictfp);
966 if (can_trap()) pin();
967 }
969 // accessors
970 bool is_strictfp() const { return check_flag(IsStrictfpFlag); }
972 // generic
973 virtual bool is_commutative() const;
974 virtual bool can_trap() const;
975 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
976 };
979 LEAF(ShiftOp, Op2)
980 public:
981 // creation
982 ShiftOp(Bytecodes::Code op, Value x, Value s) : Op2(x->type()->base(), op, x, s) {}
984 // generic
985 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
986 };
989 LEAF(LogicOp, Op2)
990 public:
991 // creation
992 LogicOp(Bytecodes::Code op, Value x, Value y) : Op2(x->type()->meet(y->type()), op, x, y) {}
994 // generic
995 virtual bool is_commutative() const;
996 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
997 };
1000 LEAF(CompareOp, Op2)
1001 public:
1002 // creation
1003 CompareOp(Bytecodes::Code op, Value x, Value y, ValueStack* state_before)
1004 : Op2(intType, op, x, y, state_before)
1005 {}
1007 // generic
1008 HASHING3(Op2, true, op(), x()->subst(), y()->subst())
1009 };
1012 LEAF(IfOp, Op2)
1013 private:
1014 Value _tval;
1015 Value _fval;
1017 public:
1018 // creation
1019 IfOp(Value x, Condition cond, Value y, Value tval, Value fval)
1020 : Op2(tval->type()->meet(fval->type()), (Bytecodes::Code)cond, x, y)
1021 , _tval(tval)
1022 , _fval(fval)
1023 {
1024 ASSERT_VALUES
1025 assert(tval->type()->tag() == fval->type()->tag(), "types must match");
1026 }
1028 // accessors
1029 virtual bool is_commutative() const;
1030 Bytecodes::Code op() const { ShouldNotCallThis(); return Bytecodes::_illegal; }
1031 Condition cond() const { return (Condition)Op2::op(); }
1032 Value tval() const { return _tval; }
1033 Value fval() const { return _fval; }
1035 // generic
1036 virtual void input_values_do(ValueVisitor* f) { Op2::input_values_do(f); f->visit(&_tval); f->visit(&_fval); }
1037 };
1040 LEAF(Convert, Instruction)
1041 private:
1042 Bytecodes::Code _op;
1043 Value _value;
1045 public:
1046 // creation
1047 Convert(Bytecodes::Code op, Value value, ValueType* to_type) : Instruction(to_type), _op(op), _value(value) {
1048 ASSERT_VALUES
1049 }
1051 // accessors
1052 Bytecodes::Code op() const { return _op; }
1053 Value value() const { return _value; }
1055 // generic
1056 virtual void input_values_do(ValueVisitor* f) { f->visit(&_value); }
1057 HASHING2(Convert, true, op(), value()->subst())
1058 };
1061 LEAF(NullCheck, Instruction)
1062 private:
1063 Value _obj;
1065 public:
1066 // creation
1067 NullCheck(Value obj, ValueStack* state_before)
1068 : Instruction(obj->type()->base(), state_before)
1069 , _obj(obj)
1070 {
1071 ASSERT_VALUES
1072 set_can_trap(true);
1073 assert(_obj->type()->is_object(), "null check must be applied to objects only");
1074 pin(Instruction::PinExplicitNullCheck);
1075 }
1077 // accessors
1078 Value obj() const { return _obj; }
1080 // setters
1081 void set_can_trap(bool can_trap) { set_flag(CanTrapFlag, can_trap); }
1083 // generic
1084 virtual bool can_trap() const { return check_flag(CanTrapFlag); /* null-check elimination sets to false */ }
1085 virtual void input_values_do(ValueVisitor* f) { f->visit(&_obj); }
1086 HASHING1(NullCheck, true, obj()->subst())
1087 };
1090 BASE(StateSplit, Instruction)
1091 private:
1092 ValueStack* _state;
1094 protected:
1095 static void substitute(BlockList& list, BlockBegin* old_block, BlockBegin* new_block);
1097 public:
1098 // creation
1099 StateSplit(ValueType* type, ValueStack* state_before = NULL)
1100 : Instruction(type, state_before)
1101 , _state(NULL)
1102 {
1103 pin(PinStateSplitConstructor);
1104 }
1106 // accessors
1107 ValueStack* state() const { return _state; }
1108 IRScope* scope() const; // the state's scope
1110 // manipulation
1111 void set_state(ValueStack* state) { assert(_state == NULL, "overwriting existing state"); check_state(state); _state = state; }
1113 // generic
1114 virtual void input_values_do(ValueVisitor* f) { /* no values */ }
1115 virtual void state_values_do(ValueVisitor* f);
1116 };
1119 LEAF(Invoke, StateSplit)
1120 private:
1121 Bytecodes::Code _code;
1122 Value _recv;
1123 Values* _args;
1124 BasicTypeList* _signature;
1125 int _vtable_index;
1126 ciMethod* _target;
1128 public:
1129 // creation
1130 Invoke(Bytecodes::Code code, ValueType* result_type, Value recv, Values* args,
1131 int vtable_index, ciMethod* target, ValueStack* state_before);
1133 // accessors
1134 Bytecodes::Code code() const { return _code; }
1135 Value receiver() const { return _recv; }
1136 bool has_receiver() const { return receiver() != NULL; }
1137 int number_of_arguments() const { return _args->length(); }
1138 Value argument_at(int i) const { return _args->at(i); }
1139 int vtable_index() const { return _vtable_index; }
1140 BasicTypeList* signature() const { return _signature; }
1141 ciMethod* target() const { return _target; }
1143 // Returns false if target is not loaded
1144 bool target_is_final() const { return check_flag(TargetIsFinalFlag); }
1145 bool target_is_loaded() const { return check_flag(TargetIsLoadedFlag); }
1146 // Returns false if target is not loaded
1147 bool target_is_strictfp() const { return check_flag(TargetIsStrictfpFlag); }
1149 // JSR 292 support
1150 bool is_invokedynamic() const { return code() == Bytecodes::_invokedynamic; }
1152 virtual bool needs_exception_state() const { return false; }
1154 // generic
1155 virtual bool can_trap() const { return true; }
1156 virtual void input_values_do(ValueVisitor* f) {
1157 StateSplit::input_values_do(f);
1158 if (has_receiver()) f->visit(&_recv);
1159 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1160 }
1161 virtual void state_values_do(ValueVisitor *f);
1162 };
1165 LEAF(NewInstance, StateSplit)
1166 private:
1167 ciInstanceKlass* _klass;
1169 public:
1170 // creation
1171 NewInstance(ciInstanceKlass* klass, ValueStack* state_before)
1172 : StateSplit(instanceType, state_before)
1173 , _klass(klass)
1174 {}
1176 // accessors
1177 ciInstanceKlass* klass() const { return _klass; }
1179 virtual bool needs_exception_state() const { return false; }
1181 // generic
1182 virtual bool can_trap() const { return true; }
1183 ciType* exact_type() const;
1184 };
1187 BASE(NewArray, StateSplit)
1188 private:
1189 Value _length;
1191 public:
1192 // creation
1193 NewArray(Value length, ValueStack* state_before)
1194 : StateSplit(objectType, state_before)
1195 , _length(length)
1196 {
1197 // Do not ASSERT_VALUES since length is NULL for NewMultiArray
1198 }
1200 // accessors
1201 Value length() const { return _length; }
1203 virtual bool needs_exception_state() const { return false; }
1205 // generic
1206 virtual bool can_trap() const { return true; }
1207 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_length); }
1208 };
1211 LEAF(NewTypeArray, NewArray)
1212 private:
1213 BasicType _elt_type;
1215 public:
1216 // creation
1217 NewTypeArray(Value length, BasicType elt_type, ValueStack* state_before)
1218 : NewArray(length, state_before)
1219 , _elt_type(elt_type)
1220 {}
1222 // accessors
1223 BasicType elt_type() const { return _elt_type; }
1224 ciType* exact_type() const;
1225 };
1228 LEAF(NewObjectArray, NewArray)
1229 private:
1230 ciKlass* _klass;
1232 public:
1233 // creation
1234 NewObjectArray(ciKlass* klass, Value length, ValueStack* state_before) : NewArray(length, state_before), _klass(klass) {}
1236 // accessors
1237 ciKlass* klass() const { return _klass; }
1238 ciType* exact_type() const;
1239 };
1242 LEAF(NewMultiArray, NewArray)
1243 private:
1244 ciKlass* _klass;
1245 Values* _dims;
1247 public:
1248 // creation
1249 NewMultiArray(ciKlass* klass, Values* dims, ValueStack* state_before) : NewArray(NULL, state_before), _klass(klass), _dims(dims) {
1250 ASSERT_VALUES
1251 }
1253 // accessors
1254 ciKlass* klass() const { return _klass; }
1255 Values* dims() const { return _dims; }
1256 int rank() const { return dims()->length(); }
1258 // generic
1259 virtual void input_values_do(ValueVisitor* f) {
1260 // NOTE: we do not call NewArray::input_values_do since "length"
1261 // is meaningless for a multi-dimensional array; passing the
1262 // zeroth element down to NewArray as its length is a bad idea
1263 // since there will be a copy in the "dims" array which doesn't
1264 // get updated, and the value must not be traversed twice. Was bug
1265 // - kbr 4/10/2001
1266 StateSplit::input_values_do(f);
1267 for (int i = 0; i < _dims->length(); i++) f->visit(_dims->adr_at(i));
1268 }
1269 };
1272 BASE(TypeCheck, StateSplit)
1273 private:
1274 ciKlass* _klass;
1275 Value _obj;
1277 ciMethod* _profiled_method;
1278 int _profiled_bci;
1280 public:
1281 // creation
1282 TypeCheck(ciKlass* klass, Value obj, ValueType* type, ValueStack* state_before)
1283 : StateSplit(type, state_before), _klass(klass), _obj(obj),
1284 _profiled_method(NULL), _profiled_bci(0) {
1285 ASSERT_VALUES
1286 set_direct_compare(false);
1287 }
1289 // accessors
1290 ciKlass* klass() const { return _klass; }
1291 Value obj() const { return _obj; }
1292 bool is_loaded() const { return klass() != NULL; }
1293 bool direct_compare() const { return check_flag(DirectCompareFlag); }
1295 // manipulation
1296 void set_direct_compare(bool flag) { set_flag(DirectCompareFlag, flag); }
1298 // generic
1299 virtual bool can_trap() const { return true; }
1300 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1302 // Helpers for methodDataOop profiling
1303 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1304 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1305 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1306 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1307 ciMethod* profiled_method() const { return _profiled_method; }
1308 int profiled_bci() const { return _profiled_bci; }
1309 };
1312 LEAF(CheckCast, TypeCheck)
1313 public:
1314 // creation
1315 CheckCast(ciKlass* klass, Value obj, ValueStack* state_before)
1316 : TypeCheck(klass, obj, objectType, state_before) {}
1318 void set_incompatible_class_change_check() {
1319 set_flag(ThrowIncompatibleClassChangeErrorFlag, true);
1320 }
1321 bool is_incompatible_class_change_check() const {
1322 return check_flag(ThrowIncompatibleClassChangeErrorFlag);
1323 }
1325 ciType* declared_type() const;
1326 ciType* exact_type() const;
1327 };
1330 LEAF(InstanceOf, TypeCheck)
1331 public:
1332 // creation
1333 InstanceOf(ciKlass* klass, Value obj, ValueStack* state_before) : TypeCheck(klass, obj, intType, state_before) {}
1335 virtual bool needs_exception_state() const { return false; }
1336 };
1339 BASE(AccessMonitor, StateSplit)
1340 private:
1341 Value _obj;
1342 int _monitor_no;
1344 public:
1345 // creation
1346 AccessMonitor(Value obj, int monitor_no, ValueStack* state_before = NULL)
1347 : StateSplit(illegalType, state_before)
1348 , _obj(obj)
1349 , _monitor_no(monitor_no)
1350 {
1351 set_needs_null_check(true);
1352 ASSERT_VALUES
1353 }
1355 // accessors
1356 Value obj() const { return _obj; }
1357 int monitor_no() const { return _monitor_no; }
1359 // generic
1360 virtual void input_values_do(ValueVisitor* f) { StateSplit::input_values_do(f); f->visit(&_obj); }
1361 };
1364 LEAF(MonitorEnter, AccessMonitor)
1365 public:
1366 // creation
1367 MonitorEnter(Value obj, int monitor_no, ValueStack* state_before)
1368 : AccessMonitor(obj, monitor_no, state_before)
1369 {
1370 ASSERT_VALUES
1371 }
1373 // generic
1374 virtual bool can_trap() const { return true; }
1375 };
1378 LEAF(MonitorExit, AccessMonitor)
1379 public:
1380 // creation
1381 MonitorExit(Value obj, int monitor_no)
1382 : AccessMonitor(obj, monitor_no, NULL)
1383 {
1384 ASSERT_VALUES
1385 }
1386 };
1389 LEAF(Intrinsic, StateSplit)
1390 private:
1391 vmIntrinsics::ID _id;
1392 Values* _args;
1393 Value _recv;
1395 public:
1396 // preserves_state can be set to true for Intrinsics
1397 // which are guaranteed to preserve register state across any slow
1398 // cases; setting it to true does not mean that the Intrinsic can
1399 // not trap, only that if we continue execution in the same basic
1400 // block after the Intrinsic, all of the registers are intact. This
1401 // allows load elimination and common expression elimination to be
1402 // performed across the Intrinsic. The default value is false.
1403 Intrinsic(ValueType* type,
1404 vmIntrinsics::ID id,
1405 Values* args,
1406 bool has_receiver,
1407 ValueStack* state_before,
1408 bool preserves_state,
1409 bool cantrap = true)
1410 : StateSplit(type, state_before)
1411 , _id(id)
1412 , _args(args)
1413 , _recv(NULL)
1414 {
1415 assert(args != NULL, "args must exist");
1416 ASSERT_VALUES
1417 set_flag(PreservesStateFlag, preserves_state);
1418 set_flag(CanTrapFlag, cantrap);
1419 if (has_receiver) {
1420 _recv = argument_at(0);
1421 }
1422 set_needs_null_check(has_receiver);
1424 // some intrinsics can't trap, so don't force them to be pinned
1425 if (!can_trap()) {
1426 unpin(PinStateSplitConstructor);
1427 }
1428 }
1430 // accessors
1431 vmIntrinsics::ID id() const { return _id; }
1432 int number_of_arguments() const { return _args->length(); }
1433 Value argument_at(int i) const { return _args->at(i); }
1435 bool has_receiver() const { return (_recv != NULL); }
1436 Value receiver() const { assert(has_receiver(), "must have receiver"); return _recv; }
1437 bool preserves_state() const { return check_flag(PreservesStateFlag); }
1439 // generic
1440 virtual bool can_trap() const { return check_flag(CanTrapFlag); }
1441 virtual void input_values_do(ValueVisitor* f) {
1442 StateSplit::input_values_do(f);
1443 for (int i = 0; i < _args->length(); i++) f->visit(_args->adr_at(i));
1444 }
1445 };
1448 class LIR_List;
1450 LEAF(BlockBegin, StateSplit)
1451 private:
1452 int _block_id; // the unique block id
1453 int _bci; // start-bci of block
1454 int _depth_first_number; // number of this block in a depth-first ordering
1455 int _linear_scan_number; // number of this block in linear-scan ordering
1456 int _loop_depth; // the loop nesting level of this block
1457 int _loop_index; // number of the innermost loop of this block
1458 int _flags; // the flags associated with this block
1460 // fields used by BlockListBuilder
1461 int _total_preds; // number of predecessors found by BlockListBuilder
1462 BitMap _stores_to_locals; // bit is set when a local variable is stored in the block
1464 // SSA specific fields: (factor out later)
1465 BlockList _successors; // the successors of this block
1466 BlockList _predecessors; // the predecessors of this block
1467 BlockBegin* _dominator; // the dominator of this block
1468 // SSA specific ends
1469 BlockEnd* _end; // the last instruction of this block
1470 BlockList _exception_handlers; // the exception handlers potentially invoked by this block
1471 ValueStackStack* _exception_states; // only for xhandler entries: states of all instructions that have an edge to this xhandler
1472 int _exception_handler_pco; // if this block is the start of an exception handler,
1473 // this records the PC offset in the assembly code of the
1474 // first instruction in this block
1475 Label _label; // the label associated with this block
1476 LIR_List* _lir; // the low level intermediate representation for this block
1478 BitMap _live_in; // set of live LIR_Opr registers at entry to this block
1479 BitMap _live_out; // set of live LIR_Opr registers at exit from this block
1480 BitMap _live_gen; // set of registers used before any redefinition in this block
1481 BitMap _live_kill; // set of registers defined in this block
1483 BitMap _fpu_register_usage;
1484 intArray* _fpu_stack_state; // For x86 FPU code generation with UseLinearScan
1485 int _first_lir_instruction_id; // ID of first LIR instruction in this block
1486 int _last_lir_instruction_id; // ID of last LIR instruction in this block
1488 void iterate_preorder (boolArray& mark, BlockClosure* closure);
1489 void iterate_postorder(boolArray& mark, BlockClosure* closure);
1491 friend class SuxAndWeightAdjuster;
1493 public:
1494 void* operator new(size_t size) {
1495 Compilation* c = Compilation::current();
1496 void* res = c->arena()->Amalloc(size);
1497 ((BlockBegin*)res)->_id = c->get_next_id();
1498 ((BlockBegin*)res)->_block_id = c->get_next_block_id();
1499 return res;
1500 }
1502 // initialization/counting
1503 static int number_of_blocks() {
1504 return Compilation::current()->number_of_blocks();
1505 }
1507 // creation
1508 BlockBegin(int bci)
1509 : StateSplit(illegalType)
1510 , _bci(bci)
1511 , _depth_first_number(-1)
1512 , _linear_scan_number(-1)
1513 , _loop_depth(0)
1514 , _flags(0)
1515 , _dominator(NULL)
1516 , _end(NULL)
1517 , _predecessors(2)
1518 , _successors(2)
1519 , _exception_handlers(1)
1520 , _exception_states(NULL)
1521 , _exception_handler_pco(-1)
1522 , _lir(NULL)
1523 , _loop_index(-1)
1524 , _live_in()
1525 , _live_out()
1526 , _live_gen()
1527 , _live_kill()
1528 , _fpu_register_usage()
1529 , _fpu_stack_state(NULL)
1530 , _first_lir_instruction_id(-1)
1531 , _last_lir_instruction_id(-1)
1532 , _total_preds(0)
1533 , _stores_to_locals()
1534 {
1535 #ifndef PRODUCT
1536 set_printable_bci(bci);
1537 #endif
1538 }
1540 // accessors
1541 int block_id() const { return _block_id; }
1542 int bci() const { return _bci; }
1543 BlockList* successors() { return &_successors; }
1544 BlockBegin* dominator() const { return _dominator; }
1545 int loop_depth() const { return _loop_depth; }
1546 int depth_first_number() const { return _depth_first_number; }
1547 int linear_scan_number() const { return _linear_scan_number; }
1548 BlockEnd* end() const { return _end; }
1549 Label* label() { return &_label; }
1550 LIR_List* lir() const { return _lir; }
1551 int exception_handler_pco() const { return _exception_handler_pco; }
1552 BitMap& live_in() { return _live_in; }
1553 BitMap& live_out() { return _live_out; }
1554 BitMap& live_gen() { return _live_gen; }
1555 BitMap& live_kill() { return _live_kill; }
1556 BitMap& fpu_register_usage() { return _fpu_register_usage; }
1557 intArray* fpu_stack_state() const { return _fpu_stack_state; }
1558 int first_lir_instruction_id() const { return _first_lir_instruction_id; }
1559 int last_lir_instruction_id() const { return _last_lir_instruction_id; }
1560 int total_preds() const { return _total_preds; }
1561 BitMap& stores_to_locals() { return _stores_to_locals; }
1563 // manipulation
1564 void set_dominator(BlockBegin* dom) { _dominator = dom; }
1565 void set_loop_depth(int d) { _loop_depth = d; }
1566 void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
1567 void set_linear_scan_number(int lsn) { _linear_scan_number = lsn; }
1568 void set_end(BlockEnd* end);
1569 void disconnect_from_graph();
1570 static void disconnect_edge(BlockBegin* from, BlockBegin* to);
1571 BlockBegin* insert_block_between(BlockBegin* sux);
1572 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1573 void set_lir(LIR_List* lir) { _lir = lir; }
1574 void set_exception_handler_pco(int pco) { _exception_handler_pco = pco; }
1575 void set_live_in (BitMap map) { _live_in = map; }
1576 void set_live_out (BitMap map) { _live_out = map; }
1577 void set_live_gen (BitMap map) { _live_gen = map; }
1578 void set_live_kill (BitMap map) { _live_kill = map; }
1579 void set_fpu_register_usage(BitMap map) { _fpu_register_usage = map; }
1580 void set_fpu_stack_state(intArray* state) { _fpu_stack_state = state; }
1581 void set_first_lir_instruction_id(int id) { _first_lir_instruction_id = id; }
1582 void set_last_lir_instruction_id(int id) { _last_lir_instruction_id = id; }
1583 void increment_total_preds(int n = 1) { _total_preds += n; }
1584 void init_stores_to_locals(int locals_count) { _stores_to_locals = BitMap(locals_count); _stores_to_locals.clear(); }
1586 // generic
1587 virtual void state_values_do(ValueVisitor* f);
1589 // successors and predecessors
1590 int number_of_sux() const;
1591 BlockBegin* sux_at(int i) const;
1592 void add_successor(BlockBegin* sux);
1593 void remove_successor(BlockBegin* pred);
1594 bool is_successor(BlockBegin* sux) const { return _successors.contains(sux); }
1596 void add_predecessor(BlockBegin* pred);
1597 void remove_predecessor(BlockBegin* pred);
1598 bool is_predecessor(BlockBegin* pred) const { return _predecessors.contains(pred); }
1599 int number_of_preds() const { return _predecessors.length(); }
1600 BlockBegin* pred_at(int i) const { return _predecessors[i]; }
1602 // exception handlers potentially invoked by this block
1603 void add_exception_handler(BlockBegin* b);
1604 bool is_exception_handler(BlockBegin* b) const { return _exception_handlers.contains(b); }
1605 int number_of_exception_handlers() const { return _exception_handlers.length(); }
1606 BlockBegin* exception_handler_at(int i) const { return _exception_handlers.at(i); }
1608 // states of the instructions that have an edge to this exception handler
1609 int number_of_exception_states() { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states == NULL ? 0 : _exception_states->length(); }
1610 ValueStack* exception_state_at(int idx) const { assert(is_set(exception_entry_flag), "only for xhandlers"); return _exception_states->at(idx); }
1611 int add_exception_state(ValueStack* state);
1613 // flags
1614 enum Flag {
1615 no_flag = 0,
1616 std_entry_flag = 1 << 0,
1617 osr_entry_flag = 1 << 1,
1618 exception_entry_flag = 1 << 2,
1619 subroutine_entry_flag = 1 << 3,
1620 backward_branch_target_flag = 1 << 4,
1621 is_on_work_list_flag = 1 << 5,
1622 was_visited_flag = 1 << 6,
1623 parser_loop_header_flag = 1 << 7, // set by parser to identify blocks where phi functions can not be created on demand
1624 critical_edge_split_flag = 1 << 8, // set for all blocks that are introduced when critical edges are split
1625 linear_scan_loop_header_flag = 1 << 9, // set during loop-detection for LinearScan
1626 linear_scan_loop_end_flag = 1 << 10 // set during loop-detection for LinearScan
1627 };
1629 void set(Flag f) { _flags |= f; }
1630 void clear(Flag f) { _flags &= ~f; }
1631 bool is_set(Flag f) const { return (_flags & f) != 0; }
1632 bool is_entry_block() const {
1633 const int entry_mask = std_entry_flag | osr_entry_flag | exception_entry_flag;
1634 return (_flags & entry_mask) != 0;
1635 }
1637 // iteration
1638 void iterate_preorder (BlockClosure* closure);
1639 void iterate_postorder (BlockClosure* closure);
1641 void block_values_do(ValueVisitor* f);
1643 // loops
1644 void set_loop_index(int ix) { _loop_index = ix; }
1645 int loop_index() const { return _loop_index; }
1647 // merging
1648 bool try_merge(ValueStack* state); // try to merge states at block begin
1649 void merge(ValueStack* state) { bool b = try_merge(state); assert(b, "merge failed"); }
1651 // debugging
1652 void print_block() PRODUCT_RETURN;
1653 void print_block(InstructionPrinter& ip, bool live_only = false) PRODUCT_RETURN;
1654 };
1657 BASE(BlockEnd, StateSplit)
1658 private:
1659 BlockBegin* _begin;
1660 BlockList* _sux;
1662 protected:
1663 BlockList* sux() const { return _sux; }
1665 void set_sux(BlockList* sux) {
1666 #ifdef ASSERT
1667 assert(sux != NULL, "sux must exist");
1668 for (int i = sux->length() - 1; i >= 0; i--) assert(sux->at(i) != NULL, "sux must exist");
1669 #endif
1670 _sux = sux;
1671 }
1673 public:
1674 // creation
1675 BlockEnd(ValueType* type, ValueStack* state_before, bool is_safepoint)
1676 : StateSplit(type, state_before)
1677 , _begin(NULL)
1678 , _sux(NULL)
1679 {
1680 set_flag(IsSafepointFlag, is_safepoint);
1681 }
1683 // accessors
1684 bool is_safepoint() const { return check_flag(IsSafepointFlag); }
1685 BlockBegin* begin() const { return _begin; }
1687 // manipulation
1688 void set_begin(BlockBegin* begin);
1690 // successors
1691 int number_of_sux() const { return _sux != NULL ? _sux->length() : 0; }
1692 BlockBegin* sux_at(int i) const { return _sux->at(i); }
1693 BlockBegin* default_sux() const { return sux_at(number_of_sux() - 1); }
1694 BlockBegin** addr_sux_at(int i) const { return _sux->adr_at(i); }
1695 int sux_index(BlockBegin* sux) const { return _sux->find(sux); }
1696 void substitute_sux(BlockBegin* old_sux, BlockBegin* new_sux);
1697 };
1700 LEAF(Goto, BlockEnd)
1701 public:
1702 enum Direction {
1703 none, // Just a regular goto
1704 taken, not_taken // Goto produced from If
1705 };
1706 private:
1707 ciMethod* _profiled_method;
1708 int _profiled_bci;
1709 Direction _direction;
1710 public:
1711 // creation
1712 Goto(BlockBegin* sux, ValueStack* state_before, bool is_safepoint = false)
1713 : BlockEnd(illegalType, state_before, is_safepoint)
1714 , _direction(none)
1715 , _profiled_method(NULL)
1716 , _profiled_bci(0) {
1717 BlockList* s = new BlockList(1);
1718 s->append(sux);
1719 set_sux(s);
1720 }
1722 Goto(BlockBegin* sux, bool is_safepoint) : BlockEnd(illegalType, NULL, is_safepoint)
1723 , _direction(none)
1724 , _profiled_method(NULL)
1725 , _profiled_bci(0) {
1726 BlockList* s = new BlockList(1);
1727 s->append(sux);
1728 set_sux(s);
1729 }
1731 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1732 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1733 int profiled_bci() const { return _profiled_bci; }
1734 Direction direction() const { return _direction; }
1736 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1737 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1738 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1739 void set_direction(Direction d) { _direction = d; }
1740 };
1743 LEAF(If, BlockEnd)
1744 private:
1745 Value _x;
1746 Condition _cond;
1747 Value _y;
1748 ciMethod* _profiled_method;
1749 int _profiled_bci; // Canonicalizer may alter bci of If node
1750 bool _swapped; // Is the order reversed with respect to the original If in the
1751 // bytecode stream?
1752 public:
1753 // creation
1754 // unordered_is_true is valid for float/double compares only
1755 If(Value x, Condition cond, bool unordered_is_true, Value y, BlockBegin* tsux, BlockBegin* fsux, ValueStack* state_before, bool is_safepoint)
1756 : BlockEnd(illegalType, state_before, is_safepoint)
1757 , _x(x)
1758 , _cond(cond)
1759 , _y(y)
1760 , _profiled_method(NULL)
1761 , _profiled_bci(0)
1762 , _swapped(false)
1763 {
1764 ASSERT_VALUES
1765 set_flag(UnorderedIsTrueFlag, unordered_is_true);
1766 assert(x->type()->tag() == y->type()->tag(), "types must match");
1767 BlockList* s = new BlockList(2);
1768 s->append(tsux);
1769 s->append(fsux);
1770 set_sux(s);
1771 }
1773 // accessors
1774 Value x() const { return _x; }
1775 Condition cond() const { return _cond; }
1776 bool unordered_is_true() const { return check_flag(UnorderedIsTrueFlag); }
1777 Value y() const { return _y; }
1778 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1779 BlockBegin* tsux() const { return sux_for(true); }
1780 BlockBegin* fsux() const { return sux_for(false); }
1781 BlockBegin* usux() const { return sux_for(unordered_is_true()); }
1782 bool should_profile() const { return check_flag(ProfileMDOFlag); }
1783 ciMethod* profiled_method() const { return _profiled_method; } // set only for profiled branches
1784 int profiled_bci() const { return _profiled_bci; } // set for profiled branches and tiered
1785 bool is_swapped() const { return _swapped; }
1787 // manipulation
1788 void swap_operands() {
1789 Value t = _x; _x = _y; _y = t;
1790 _cond = mirror(_cond);
1791 }
1793 void swap_sux() {
1794 assert(number_of_sux() == 2, "wrong number of successors");
1795 BlockList* s = sux();
1796 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1797 _cond = negate(_cond);
1798 set_flag(UnorderedIsTrueFlag, !check_flag(UnorderedIsTrueFlag));
1799 }
1801 void set_should_profile(bool value) { set_flag(ProfileMDOFlag, value); }
1802 void set_profiled_method(ciMethod* method) { _profiled_method = method; }
1803 void set_profiled_bci(int bci) { _profiled_bci = bci; }
1804 void set_swapped(bool value) { _swapped = value; }
1805 // generic
1806 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_x); f->visit(&_y); }
1807 };
1810 LEAF(IfInstanceOf, BlockEnd)
1811 private:
1812 ciKlass* _klass;
1813 Value _obj;
1814 bool _test_is_instance; // jump if instance
1815 int _instanceof_bci;
1817 public:
1818 IfInstanceOf(ciKlass* klass, Value obj, bool test_is_instance, int instanceof_bci, BlockBegin* tsux, BlockBegin* fsux)
1819 : BlockEnd(illegalType, NULL, false) // temporary set to false
1820 , _klass(klass)
1821 , _obj(obj)
1822 , _test_is_instance(test_is_instance)
1823 , _instanceof_bci(instanceof_bci)
1824 {
1825 ASSERT_VALUES
1826 assert(instanceof_bci >= 0, "illegal bci");
1827 BlockList* s = new BlockList(2);
1828 s->append(tsux);
1829 s->append(fsux);
1830 set_sux(s);
1831 }
1833 // accessors
1834 //
1835 // Note 1: If test_is_instance() is true, IfInstanceOf tests if obj *is* an
1836 // instance of klass; otherwise it tests if it is *not* and instance
1837 // of klass.
1838 //
1839 // Note 2: IfInstanceOf instructions are created by combining an InstanceOf
1840 // and an If instruction. The IfInstanceOf bci() corresponds to the
1841 // bci that the If would have had; the (this->) instanceof_bci() is
1842 // the bci of the original InstanceOf instruction.
1843 ciKlass* klass() const { return _klass; }
1844 Value obj() const { return _obj; }
1845 int instanceof_bci() const { return _instanceof_bci; }
1846 bool test_is_instance() const { return _test_is_instance; }
1847 BlockBegin* sux_for(bool is_true) const { return sux_at(is_true ? 0 : 1); }
1848 BlockBegin* tsux() const { return sux_for(true); }
1849 BlockBegin* fsux() const { return sux_for(false); }
1851 // manipulation
1852 void swap_sux() {
1853 assert(number_of_sux() == 2, "wrong number of successors");
1854 BlockList* s = sux();
1855 BlockBegin* t = s->at(0); s->at_put(0, s->at(1)); s->at_put(1, t);
1856 _test_is_instance = !_test_is_instance;
1857 }
1859 // generic
1860 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_obj); }
1861 };
1864 BASE(Switch, BlockEnd)
1865 private:
1866 Value _tag;
1868 public:
1869 // creation
1870 Switch(Value tag, BlockList* sux, ValueStack* state_before, bool is_safepoint)
1871 : BlockEnd(illegalType, state_before, is_safepoint)
1872 , _tag(tag) {
1873 ASSERT_VALUES
1874 set_sux(sux);
1875 }
1877 // accessors
1878 Value tag() const { return _tag; }
1879 int length() const { return number_of_sux() - 1; }
1881 virtual bool needs_exception_state() const { return false; }
1883 // generic
1884 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_tag); }
1885 };
1888 LEAF(TableSwitch, Switch)
1889 private:
1890 int _lo_key;
1892 public:
1893 // creation
1894 TableSwitch(Value tag, BlockList* sux, int lo_key, ValueStack* state_before, bool is_safepoint)
1895 : Switch(tag, sux, state_before, is_safepoint)
1896 , _lo_key(lo_key) {}
1898 // accessors
1899 int lo_key() const { return _lo_key; }
1900 int hi_key() const { return _lo_key + length() - 1; }
1901 };
1904 LEAF(LookupSwitch, Switch)
1905 private:
1906 intArray* _keys;
1908 public:
1909 // creation
1910 LookupSwitch(Value tag, BlockList* sux, intArray* keys, ValueStack* state_before, bool is_safepoint)
1911 : Switch(tag, sux, state_before, is_safepoint)
1912 , _keys(keys) {
1913 assert(keys != NULL, "keys must exist");
1914 assert(keys->length() == length(), "sux & keys have incompatible lengths");
1915 }
1917 // accessors
1918 int key_at(int i) const { return _keys->at(i); }
1919 };
1922 LEAF(Return, BlockEnd)
1923 private:
1924 Value _result;
1926 public:
1927 // creation
1928 Return(Value result) :
1929 BlockEnd(result == NULL ? voidType : result->type()->base(), NULL, true),
1930 _result(result) {}
1932 // accessors
1933 Value result() const { return _result; }
1934 bool has_result() const { return result() != NULL; }
1936 // generic
1937 virtual void input_values_do(ValueVisitor* f) {
1938 BlockEnd::input_values_do(f);
1939 if (has_result()) f->visit(&_result);
1940 }
1941 };
1944 LEAF(Throw, BlockEnd)
1945 private:
1946 Value _exception;
1948 public:
1949 // creation
1950 Throw(Value exception, ValueStack* state_before) : BlockEnd(illegalType, state_before, true), _exception(exception) {
1951 ASSERT_VALUES
1952 }
1954 // accessors
1955 Value exception() const { return _exception; }
1957 // generic
1958 virtual bool can_trap() const { return true; }
1959 virtual void input_values_do(ValueVisitor* f) { BlockEnd::input_values_do(f); f->visit(&_exception); }
1960 };
1963 LEAF(Base, BlockEnd)
1964 public:
1965 // creation
1966 Base(BlockBegin* std_entry, BlockBegin* osr_entry) : BlockEnd(illegalType, NULL, false) {
1967 assert(std_entry->is_set(BlockBegin::std_entry_flag), "std entry must be flagged");
1968 assert(osr_entry == NULL || osr_entry->is_set(BlockBegin::osr_entry_flag), "osr entry must be flagged");
1969 BlockList* s = new BlockList(2);
1970 if (osr_entry != NULL) s->append(osr_entry);
1971 s->append(std_entry); // must be default sux!
1972 set_sux(s);
1973 }
1975 // accessors
1976 BlockBegin* std_entry() const { return default_sux(); }
1977 BlockBegin* osr_entry() const { return number_of_sux() < 2 ? NULL : sux_at(0); }
1978 };
1981 LEAF(OsrEntry, Instruction)
1982 public:
1983 // creation
1984 #ifdef _LP64
1985 OsrEntry() : Instruction(longType) { pin(); }
1986 #else
1987 OsrEntry() : Instruction(intType) { pin(); }
1988 #endif
1990 // generic
1991 virtual void input_values_do(ValueVisitor* f) { }
1992 };
1995 // Models the incoming exception at a catch site
1996 LEAF(ExceptionObject, Instruction)
1997 public:
1998 // creation
1999 ExceptionObject() : Instruction(objectType) {
2000 pin();
2001 }
2003 // generic
2004 virtual void input_values_do(ValueVisitor* f) { }
2005 };
2008 // Models needed rounding for floating-point values on Intel.
2009 // Currently only used to represent rounding of double-precision
2010 // values stored into local variables, but could be used to model
2011 // intermediate rounding of single-precision values as well.
2012 LEAF(RoundFP, Instruction)
2013 private:
2014 Value _input; // floating-point value to be rounded
2016 public:
2017 RoundFP(Value input)
2018 : Instruction(input->type()) // Note: should not be used for constants
2019 , _input(input)
2020 {
2021 ASSERT_VALUES
2022 }
2024 // accessors
2025 Value input() const { return _input; }
2027 // generic
2028 virtual void input_values_do(ValueVisitor* f) { f->visit(&_input); }
2029 };
2032 BASE(UnsafeOp, Instruction)
2033 private:
2034 BasicType _basic_type; // ValueType can not express byte-sized integers
2036 protected:
2037 // creation
2038 UnsafeOp(BasicType basic_type, bool is_put)
2039 : Instruction(is_put ? voidType : as_ValueType(basic_type))
2040 , _basic_type(basic_type)
2041 {
2042 //Note: Unsafe ops are not not guaranteed to throw NPE.
2043 // Convservatively, Unsafe operations must be pinned though we could be
2044 // looser about this if we wanted to..
2045 pin();
2046 }
2048 public:
2049 // accessors
2050 BasicType basic_type() { return _basic_type; }
2052 // generic
2053 virtual void input_values_do(ValueVisitor* f) { }
2054 };
2057 BASE(UnsafeRawOp, UnsafeOp)
2058 private:
2059 Value _base; // Base address (a Java long)
2060 Value _index; // Index if computed by optimizer; initialized to NULL
2061 int _log2_scale; // Scale factor: 0, 1, 2, or 3.
2062 // Indicates log2 of number of bytes (1, 2, 4, or 8)
2063 // to scale index by.
2065 protected:
2066 UnsafeRawOp(BasicType basic_type, Value addr, bool is_put)
2067 : UnsafeOp(basic_type, is_put)
2068 , _base(addr)
2069 , _index(NULL)
2070 , _log2_scale(0)
2071 {
2072 // Can not use ASSERT_VALUES because index may be NULL
2073 assert(addr != NULL && addr->type()->is_long(), "just checking");
2074 }
2076 UnsafeRawOp(BasicType basic_type, Value base, Value index, int log2_scale, bool is_put)
2077 : UnsafeOp(basic_type, is_put)
2078 , _base(base)
2079 , _index(index)
2080 , _log2_scale(log2_scale)
2081 {
2082 }
2084 public:
2085 // accessors
2086 Value base() { return _base; }
2087 Value index() { return _index; }
2088 bool has_index() { return (_index != NULL); }
2089 int log2_scale() { return _log2_scale; }
2091 // setters
2092 void set_base (Value base) { _base = base; }
2093 void set_index(Value index) { _index = index; }
2094 void set_log2_scale(int log2_scale) { _log2_scale = log2_scale; }
2096 // generic
2097 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2098 f->visit(&_base);
2099 if (has_index()) f->visit(&_index); }
2100 };
2103 LEAF(UnsafeGetRaw, UnsafeRawOp)
2104 private:
2105 bool _may_be_unaligned; // For OSREntry
2107 public:
2108 UnsafeGetRaw(BasicType basic_type, Value addr, bool may_be_unaligned)
2109 : UnsafeRawOp(basic_type, addr, false) {
2110 _may_be_unaligned = may_be_unaligned;
2111 }
2113 UnsafeGetRaw(BasicType basic_type, Value base, Value index, int log2_scale, bool may_be_unaligned)
2114 : UnsafeRawOp(basic_type, base, index, log2_scale, false) {
2115 _may_be_unaligned = may_be_unaligned;
2116 }
2118 bool may_be_unaligned() { return _may_be_unaligned; }
2119 };
2122 LEAF(UnsafePutRaw, UnsafeRawOp)
2123 private:
2124 Value _value; // Value to be stored
2126 public:
2127 UnsafePutRaw(BasicType basic_type, Value addr, Value value)
2128 : UnsafeRawOp(basic_type, addr, true)
2129 , _value(value)
2130 {
2131 assert(value != NULL, "just checking");
2132 ASSERT_VALUES
2133 }
2135 UnsafePutRaw(BasicType basic_type, Value base, Value index, int log2_scale, Value value)
2136 : UnsafeRawOp(basic_type, base, index, log2_scale, true)
2137 , _value(value)
2138 {
2139 assert(value != NULL, "just checking");
2140 ASSERT_VALUES
2141 }
2143 // accessors
2144 Value value() { return _value; }
2146 // generic
2147 virtual void input_values_do(ValueVisitor* f) { UnsafeRawOp::input_values_do(f);
2148 f->visit(&_value); }
2149 };
2152 BASE(UnsafeObjectOp, UnsafeOp)
2153 private:
2154 Value _object; // Object to be fetched from or mutated
2155 Value _offset; // Offset within object
2156 bool _is_volatile; // true if volatile - dl/JSR166
2157 public:
2158 UnsafeObjectOp(BasicType basic_type, Value object, Value offset, bool is_put, bool is_volatile)
2159 : UnsafeOp(basic_type, is_put), _object(object), _offset(offset), _is_volatile(is_volatile)
2160 {
2161 }
2163 // accessors
2164 Value object() { return _object; }
2165 Value offset() { return _offset; }
2166 bool is_volatile() { return _is_volatile; }
2167 // generic
2168 virtual void input_values_do(ValueVisitor* f) { UnsafeOp::input_values_do(f);
2169 f->visit(&_object);
2170 f->visit(&_offset); }
2171 };
2174 LEAF(UnsafeGetObject, UnsafeObjectOp)
2175 public:
2176 UnsafeGetObject(BasicType basic_type, Value object, Value offset, bool is_volatile)
2177 : UnsafeObjectOp(basic_type, object, offset, false, is_volatile)
2178 {
2179 ASSERT_VALUES
2180 }
2181 };
2184 LEAF(UnsafePutObject, UnsafeObjectOp)
2185 private:
2186 Value _value; // Value to be stored
2187 public:
2188 UnsafePutObject(BasicType basic_type, Value object, Value offset, Value value, bool is_volatile)
2189 : UnsafeObjectOp(basic_type, object, offset, true, is_volatile)
2190 , _value(value)
2191 {
2192 ASSERT_VALUES
2193 }
2195 // accessors
2196 Value value() { return _value; }
2198 // generic
2199 virtual void input_values_do(ValueVisitor* f) { UnsafeObjectOp::input_values_do(f);
2200 f->visit(&_value); }
2201 };
2204 BASE(UnsafePrefetch, UnsafeObjectOp)
2205 public:
2206 UnsafePrefetch(Value object, Value offset)
2207 : UnsafeObjectOp(T_VOID, object, offset, false, false)
2208 {
2209 }
2210 };
2213 LEAF(UnsafePrefetchRead, UnsafePrefetch)
2214 public:
2215 UnsafePrefetchRead(Value object, Value offset)
2216 : UnsafePrefetch(object, offset)
2217 {
2218 ASSERT_VALUES
2219 }
2220 };
2223 LEAF(UnsafePrefetchWrite, UnsafePrefetch)
2224 public:
2225 UnsafePrefetchWrite(Value object, Value offset)
2226 : UnsafePrefetch(object, offset)
2227 {
2228 ASSERT_VALUES
2229 }
2230 };
2232 LEAF(ProfileCall, Instruction)
2233 private:
2234 ciMethod* _method;
2235 int _bci_of_invoke;
2236 Value _recv;
2237 ciKlass* _known_holder;
2239 public:
2240 ProfileCall(ciMethod* method, int bci, Value recv, ciKlass* known_holder)
2241 : Instruction(voidType)
2242 , _method(method)
2243 , _bci_of_invoke(bci)
2244 , _recv(recv)
2245 , _known_holder(known_holder)
2246 {
2247 // The ProfileCall has side-effects and must occur precisely where located
2248 pin();
2249 }
2251 ciMethod* method() { return _method; }
2252 int bci_of_invoke() { return _bci_of_invoke; }
2253 Value recv() { return _recv; }
2254 ciKlass* known_holder() { return _known_holder; }
2256 virtual void input_values_do(ValueVisitor* f) { if (_recv != NULL) f->visit(&_recv); }
2257 };
2259 // Use to trip invocation counter of an inlined method
2261 LEAF(ProfileInvoke, Instruction)
2262 private:
2263 ciMethod* _inlinee;
2264 ValueStack* _state;
2266 public:
2267 ProfileInvoke(ciMethod* inlinee, ValueStack* state)
2268 : Instruction(voidType)
2269 , _inlinee(inlinee)
2270 , _state(state)
2271 {
2272 // The ProfileInvoke has side-effects and must occur precisely where located QQQ???
2273 pin();
2274 }
2276 ciMethod* inlinee() { return _inlinee; }
2277 ValueStack* state() { return _state; }
2278 virtual void input_values_do(ValueVisitor*) {}
2279 virtual void state_values_do(ValueVisitor*);
2280 };
2282 class BlockPair: public CompilationResourceObj {
2283 private:
2284 BlockBegin* _from;
2285 BlockBegin* _to;
2286 public:
2287 BlockPair(BlockBegin* from, BlockBegin* to): _from(from), _to(to) {}
2288 BlockBegin* from() const { return _from; }
2289 BlockBegin* to() const { return _to; }
2290 bool is_same(BlockBegin* from, BlockBegin* to) const { return _from == from && _to == to; }
2291 bool is_same(BlockPair* p) const { return _from == p->from() && _to == p->to(); }
2292 void set_to(BlockBegin* b) { _to = b; }
2293 void set_from(BlockBegin* b) { _from = b; }
2294 };
2297 define_array(BlockPairArray, BlockPair*)
2298 define_stack(BlockPairList, BlockPairArray)
2301 inline int BlockBegin::number_of_sux() const { assert(_end == NULL || _end->number_of_sux() == _successors.length(), "mismatch"); return _successors.length(); }
2302 inline BlockBegin* BlockBegin::sux_at(int i) const { assert(_end == NULL || _end->sux_at(i) == _successors.at(i), "mismatch"); return _successors.at(i); }
2303 inline void BlockBegin::add_successor(BlockBegin* sux) { assert(_end == NULL, "Would create mismatch with successors of BlockEnd"); _successors.append(sux); }
2305 #undef ASSERT_VALUES