src/share/vm/c1/c1_Instruction.hpp

Wed, 31 Aug 2011 16:46:11 -0700

author
never
date
Wed, 31 Aug 2011 16:46:11 -0700
changeset 3099
c124e2e7463e
parent 2728
13bc79b5c9c8
child 3100
a32de5085326
permissions
-rw-r--r--

7083786: dead various dead chunks of code
Reviewed-by: iveresov, kvn

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

mercurial