src/share/vm/c1/c1_Instruction.hpp

Mon, 13 Sep 2010 12:10:49 -0700

author
iveresov
date
Mon, 13 Sep 2010 12:10:49 -0700
changeset 2146
3a294e483abc
parent 2138
d5d065957597
child 2174
f02a8bbe6ed4
permissions
-rw-r--r--

6919069: client compiler needs to capture more profile information for tiered work
Summary: Added profiling of instanceof and aastore.
Reviewed-by: kvn, jrose, never

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

mercurial