1 /* 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #ifndef SHARE_VM_C1_C1_LIRGENERATOR_HPP 26 #define SHARE_VM_C1_C1_LIRGENERATOR_HPP 27 28 #include "c1/c1_Instruction.hpp" 29 #include "c1/c1_LIR.hpp" 30 #include "ci/ciMethodData.hpp" 31 #if INCLUDE_JFR 32 #include "jfr/support/jfrIntrinsics.hpp" 33 #endif 34 #include "utilities/sizes.hpp" 35 36 // The classes responsible for code emission and register allocation 37 38 39 class LIRGenerator; 40 class LIREmitter; 41 class Invoke; 42 class SwitchRange; 43 class LIRItem; 44 45 define_array(LIRItemArray, LIRItem*) 46 define_stack(LIRItemList, LIRItemArray) 47 48 class SwitchRange: public CompilationResourceObj { 49 private: 50 int _low_key; 51 int _high_key; 52 BlockBegin* _sux; 53 public: 54 SwitchRange(int start_key, BlockBegin* sux): _low_key(start_key), _high_key(start_key), _sux(sux) {} 55 void set_high_key(int key) { _high_key = key; } 56 57 int high_key() const { return _high_key; } 58 int low_key() const { return _low_key; } 59 BlockBegin* sux() const { return _sux; } 60 }; 61 62 define_array(SwitchRangeArray, SwitchRange*) 63 define_stack(SwitchRangeList, SwitchRangeArray) 64 65 66 class ResolveNode; 67 68 define_array(NodeArray, ResolveNode*); 69 define_stack(NodeList, NodeArray); 70 71 72 // Node objects form a directed graph of LIR_Opr 73 // Edges between Nodes represent moves from one Node to its destinations 74 class ResolveNode: public CompilationResourceObj { 75 private: 76 LIR_Opr _operand; // the source or destinaton 77 NodeList _destinations; // for the operand 78 bool _assigned; // Value assigned to this Node? 79 bool _visited; // Node already visited? 80 bool _start_node; // Start node already visited? 81 82 public: 83 ResolveNode(LIR_Opr operand) 84 : _operand(operand) 85 , _assigned(false) 86 , _visited(false) 87 , _start_node(false) {}; 88 89 // accessors 90 LIR_Opr operand() const { return _operand; } 91 int no_of_destinations() const { return _destinations.length(); } 92 ResolveNode* destination_at(int i) { return _destinations[i]; } 93 bool assigned() const { return _assigned; } 94 bool visited() const { return _visited; } 95 bool start_node() const { return _start_node; } 96 97 // modifiers 98 void append(ResolveNode* dest) { _destinations.append(dest); } 99 void set_assigned() { _assigned = true; } 100 void set_visited() { _visited = true; } 101 void set_start_node() { _start_node = true; } 102 }; 103 104 105 // This is shared state to be used by the PhiResolver so the operand 106 // arrays don't have to be reallocated for reach resolution. 107 class PhiResolverState: public CompilationResourceObj { 108 friend class PhiResolver; 109 110 private: 111 NodeList _virtual_operands; // Nodes where the operand is a virtual register 112 NodeList _other_operands; // Nodes where the operand is not a virtual register 113 NodeList _vreg_table; // Mapping from virtual register to Node 114 115 public: 116 PhiResolverState() {} 117 118 void reset(int max_vregs); 119 }; 120 121 122 // class used to move value of phi operand to phi function 123 class PhiResolver: public CompilationResourceObj { 124 private: 125 LIRGenerator* _gen; 126 PhiResolverState& _state; // temporary state cached by LIRGenerator 127 128 ResolveNode* _loop; 129 LIR_Opr _temp; 130 131 // access to shared state arrays 132 NodeList& virtual_operands() { return _state._virtual_operands; } 133 NodeList& other_operands() { return _state._other_operands; } 134 NodeList& vreg_table() { return _state._vreg_table; } 135 136 ResolveNode* create_node(LIR_Opr opr, bool source); 137 ResolveNode* source_node(LIR_Opr opr) { return create_node(opr, true); } 138 ResolveNode* destination_node(LIR_Opr opr) { return create_node(opr, false); } 139 140 void emit_move(LIR_Opr src, LIR_Opr dest); 141 void move_to_temp(LIR_Opr src); 142 void move_temp_to(LIR_Opr dest); 143 void move(ResolveNode* src, ResolveNode* dest); 144 145 LIRGenerator* gen() { 146 return _gen; 147 } 148 149 public: 150 PhiResolver(LIRGenerator* _lir_gen, int max_vregs); 151 ~PhiResolver(); 152 153 void move(LIR_Opr src, LIR_Opr dest); 154 }; 155 156 157 // only the classes below belong in the same file 158 class LIRGenerator: public InstructionVisitor, public BlockClosure { 159 160 private: 161 Compilation* _compilation; 162 ciMethod* _method; // method that we are compiling 163 PhiResolverState _resolver_state; 164 BlockBegin* _block; 165 int _virtual_register_number; 166 Values _instruction_for_operand; 167 BitMap2D _vreg_flags; // flags which can be set on a per-vreg basis 168 LIR_List* _lir; 169 BarrierSet* _bs; 170 171 LIRGenerator* gen() { 172 return this; 173 } 174 175 void print_if_not_loaded(const NewInstance* new_instance) PRODUCT_RETURN; 176 177 #ifdef ASSERT 178 LIR_List* lir(const char * file, int line) const { 179 _lir->set_file_and_line(file, line); 180 return _lir; 181 } 182 #endif 183 LIR_List* lir() const { 184 return _lir; 185 } 186 187 // a simple cache of constants used within a block 188 GrowableArray<LIR_Const*> _constants; 189 LIR_OprList _reg_for_constants; 190 Values _unpinned_constants; 191 192 friend class PhiResolver; 193 194 // unified bailout support 195 void bailout(const char* msg) const { compilation()->bailout(msg); } 196 bool bailed_out() const { return compilation()->bailed_out(); } 197 198 void block_do_prolog(BlockBegin* block); 199 void block_do_epilog(BlockBegin* block); 200 201 // register allocation 202 LIR_Opr rlock(Value instr); // lock a free register 203 LIR_Opr rlock_result(Value instr); 204 LIR_Opr rlock_result(Value instr, BasicType type); 205 LIR_Opr rlock_byte(BasicType type); 206 LIR_Opr rlock_callee_saved(BasicType type); 207 208 // get a constant into a register and get track of what register was used 209 LIR_Opr load_constant(Constant* x); 210 LIR_Opr load_constant(LIR_Const* constant); 211 212 // Given an immediate value, return an operand usable in logical ops. 213 LIR_Opr load_immediate(int x, BasicType type); 214 215 void set_result(Value x, LIR_Opr opr) { 216 assert(opr->is_valid(), "must set to valid value"); 217 assert(x->operand()->is_illegal(), "operand should never change"); 218 assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register"); 219 x->set_operand(opr); 220 assert(opr == x->operand(), "must be"); 221 if (opr->is_virtual()) { 222 _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL); 223 } 224 } 225 void set_no_result(Value x) { assert(!x->has_uses(), "can't have use"); x->clear_operand(); } 226 227 friend class LIRItem; 228 229 LIR_Opr round_item(LIR_Opr opr); 230 LIR_Opr force_to_spill(LIR_Opr value, BasicType t); 231 232 PhiResolverState& resolver_state() { return _resolver_state; } 233 234 void move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val); 235 void move_to_phi(ValueStack* cur_state); 236 237 // code emission 238 void do_ArithmeticOp_Long (ArithmeticOp* x); 239 void do_ArithmeticOp_Int (ArithmeticOp* x); 240 void do_ArithmeticOp_FPU (ArithmeticOp* x); 241 242 // platform dependent 243 LIR_Opr getThreadPointer(); 244 245 void do_RegisterFinalizer(Intrinsic* x); 246 void do_isInstance(Intrinsic* x); 247 void do_getClass(Intrinsic* x); 248 void do_currentThread(Intrinsic* x); 249 void do_MathIntrinsic(Intrinsic* x); 250 void do_ArrayCopy(Intrinsic* x); 251 void do_CompareAndSwap(Intrinsic* x, ValueType* type); 252 void do_NIOCheckIndex(Intrinsic* x); 253 void do_FPIntrinsics(Intrinsic* x); 254 void do_Reference_get(Intrinsic* x); 255 void do_update_CRC32(Intrinsic* x); 256 257 void do_UnsafePrefetch(UnsafePrefetch* x, bool is_store); 258 259 LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info); 260 LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info); 261 262 // convenience functions 263 LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info); 264 LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info); 265 266 // GC Barriers 267 268 // generic interface 269 270 void pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val, bool do_load, bool patch, CodeEmitInfo* info); 271 void post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val); 272 273 // specific implementations 274 // pre barriers 275 276 void G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val, 277 bool do_load, bool patch, CodeEmitInfo* info); 278 279 // post barriers 280 281 void G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val); 282 void CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val); 283 #ifdef CARDTABLEMODREF_POST_BARRIER_HELPER 284 void CardTableModRef_post_barrier_helper(LIR_OprDesc* addr, LIR_Const* card_table_base); 285 #endif 286 287 288 static LIR_Opr result_register_for(ValueType* type, bool callee = false); 289 290 ciObject* get_jobject_constant(Value value); 291 292 LIRItemList* invoke_visit_arguments(Invoke* x); 293 void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list); 294 295 void trace_block_entry(BlockBegin* block); 296 297 // volatile field operations are never patchable because a klass 298 // must be loaded to know it's volatile which means that the offset 299 // it always known as well. 300 void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info); 301 void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info); 302 303 void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile); 304 void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile); 305 306 void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args); 307 308 void increment_counter(address counter, BasicType type, int step = 1); 309 void increment_counter(LIR_Address* addr, int step = 1); 310 311 // is_strictfp is only needed for mul and div (and only generates different code on i486) 312 void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp, CodeEmitInfo* info = NULL); 313 // machine dependent. returns true if it emitted code for the multiply 314 bool strength_reduce_multiply(LIR_Opr left, int constant, LIR_Opr result, LIR_Opr tmp); 315 316 void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes); 317 318 void klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve = false); 319 320 // this loads the length and compares against the index 321 void array_range_check (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info); 322 // For java.nio.Buffer.checkIndex 323 void nio_range_check (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info); 324 325 void arithmetic_op_int (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp); 326 void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL); 327 void arithmetic_op_fpu (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp = LIR_OprFact::illegalOpr); 328 329 void shift_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp); 330 331 void logic_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right); 332 333 void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info); 334 void monitor_exit (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no); 335 336 void new_instance (LIR_Opr dst, ciInstanceKlass* klass, bool is_unresolved, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info); 337 338 // machine dependent 339 void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info); 340 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info); 341 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info); 342 343 void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type); 344 345 // returns a LIR_Address to address an array location. May also 346 // emit some code as part of address calculation. If 347 // needs_card_mark is true then compute the full address for use by 348 // both the store and the card mark. 349 LIR_Address* generate_address(LIR_Opr base, 350 LIR_Opr index, int shift, 351 int disp, 352 BasicType type); 353 LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) { 354 return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type); 355 } 356 LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type, bool needs_card_mark); 357 358 // the helper for generate_address 359 void add_large_constant(LIR_Opr src, int c, LIR_Opr dest); 360 361 // machine preferences and characteristics 362 bool can_inline_as_constant(Value i) const; 363 bool can_inline_as_constant(LIR_Const* c) const; 364 bool can_store_as_constant(Value i, BasicType type) const; 365 366 LIR_Opr safepoint_poll_register(); 367 368 void profile_branch(If* if_instr, If::Condition cond); 369 void increment_event_counter_impl(CodeEmitInfo* info, 370 ciMethod *method, int frequency, 371 int bci, bool backedge, bool notify); 372 void increment_event_counter(CodeEmitInfo* info, int bci, bool backedge); 373 void increment_invocation_counter(CodeEmitInfo *info) { 374 if (compilation()->count_invocations()) { 375 increment_event_counter(info, InvocationEntryBci, false); 376 } 377 } 378 void increment_backedge_counter(CodeEmitInfo* info, int bci) { 379 if (compilation()->count_backedges()) { 380 increment_event_counter(info, bci, true); 381 } 382 } 383 384 CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false); 385 CodeEmitInfo* state_for(Instruction* x); 386 387 // allocates a virtual register for this instruction if 388 // one isn't already allocated. Only for Phi and Local. 389 LIR_Opr operand_for_instruction(Instruction *x); 390 391 void set_block(BlockBegin* block) { _block = block; } 392 393 void block_prolog(BlockBegin* block); 394 void block_epilog(BlockBegin* block); 395 396 void do_root (Instruction* instr); 397 void walk (Instruction* instr); 398 399 void bind_block_entry(BlockBegin* block); 400 void start_block(BlockBegin* block); 401 402 LIR_Opr new_register(BasicType type); 403 LIR_Opr new_register(Value value) { return new_register(as_BasicType(value->type())); } 404 LIR_Opr new_register(ValueType* type) { return new_register(as_BasicType(type)); } 405 406 // returns a register suitable for doing pointer math 407 LIR_Opr new_pointer_register() { 408 #ifdef _LP64 409 return new_register(T_LONG); 410 #else 411 return new_register(T_INT); 412 #endif 413 } 414 415 static LIR_Condition lir_cond(If::Condition cond) { 416 LIR_Condition l = lir_cond_unknown; 417 switch (cond) { 418 case If::eql: l = lir_cond_equal; break; 419 case If::neq: l = lir_cond_notEqual; break; 420 case If::lss: l = lir_cond_less; break; 421 case If::leq: l = lir_cond_lessEqual; break; 422 case If::geq: l = lir_cond_greaterEqual; break; 423 case If::gtr: l = lir_cond_greater; break; 424 case If::aeq: l = lir_cond_aboveEqual; break; 425 case If::beq: l = lir_cond_belowEqual; break; 426 default: fatal("You must pass valid If::Condition"); 427 }; 428 return l; 429 } 430 431 #ifdef __SOFTFP__ 432 void do_soft_float_compare(If *x); 433 #endif // __SOFTFP__ 434 435 void init(); 436 437 SwitchRangeArray* create_lookup_ranges(TableSwitch* x); 438 SwitchRangeArray* create_lookup_ranges(LookupSwitch* x); 439 void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux); 440 441 void do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x); 442 #ifdef JFR_HAVE_INTRINSICS 443 void do_ClassIDIntrinsic(Intrinsic* x); 444 void do_getEventWriter(Intrinsic* x); 445 #endif 446 ciKlass* profile_type(ciMethodData* md, int md_first_offset, int md_offset, intptr_t profiled_k, 447 Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k, 448 ciKlass* callee_signature_k); 449 void profile_arguments(ProfileCall* x); 450 void profile_parameters(Base* x); 451 void profile_parameters_at_call(ProfileCall* x); 452 LIR_Opr maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info); 453 454 public: 455 Compilation* compilation() const { return _compilation; } 456 FrameMap* frame_map() const { return _compilation->frame_map(); } 457 ciMethod* method() const { return _method; } 458 BlockBegin* block() const { return _block; } 459 IRScope* scope() const { return block()->scope(); } 460 461 int max_virtual_register_number() const { return _virtual_register_number; } 462 463 void block_do(BlockBegin* block); 464 465 // Flags that can be set on vregs 466 enum VregFlag { 467 must_start_in_memory = 0 // needs to be assigned a memory location at beginning, but may then be loaded in a register 468 , callee_saved = 1 // must be in a callee saved register 469 , byte_reg = 2 // must be in a byte register 470 , num_vreg_flags 471 472 }; 473 474 LIRGenerator(Compilation* compilation, ciMethod* method) 475 : _compilation(compilation) 476 , _method(method) 477 , _virtual_register_number(LIR_OprDesc::vreg_base) 478 , _vreg_flags(NULL, 0, num_vreg_flags) { 479 init(); 480 } 481 482 // for virtual registers, maps them back to Phi's or Local's 483 Instruction* instruction_for_opr(LIR_Opr opr); 484 Instruction* instruction_for_vreg(int reg_num); 485 486 void set_vreg_flag (int vreg_num, VregFlag f); 487 bool is_vreg_flag_set(int vreg_num, VregFlag f); 488 void set_vreg_flag (LIR_Opr opr, VregFlag f) { set_vreg_flag(opr->vreg_number(), f); } 489 bool is_vreg_flag_set(LIR_Opr opr, VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); } 490 491 // statics 492 static LIR_Opr exceptionOopOpr(); 493 static LIR_Opr exceptionPcOpr(); 494 static LIR_Opr divInOpr(); 495 static LIR_Opr divOutOpr(); 496 static LIR_Opr remOutOpr(); 497 static LIR_Opr shiftCountOpr(); 498 LIR_Opr syncTempOpr(); 499 LIR_Opr atomicLockOpr(); 500 501 // returns a register suitable for saving the thread in a 502 // call_runtime_leaf if one is needed. 503 LIR_Opr getThreadTemp(); 504 505 // visitor functionality 506 virtual void do_Phi (Phi* x); 507 virtual void do_Local (Local* x); 508 virtual void do_Constant (Constant* x); 509 virtual void do_LoadField (LoadField* x); 510 virtual void do_StoreField (StoreField* x); 511 virtual void do_ArrayLength (ArrayLength* x); 512 virtual void do_LoadIndexed (LoadIndexed* x); 513 virtual void do_StoreIndexed (StoreIndexed* x); 514 virtual void do_NegateOp (NegateOp* x); 515 virtual void do_ArithmeticOp (ArithmeticOp* x); 516 virtual void do_ShiftOp (ShiftOp* x); 517 virtual void do_LogicOp (LogicOp* x); 518 virtual void do_CompareOp (CompareOp* x); 519 virtual void do_IfOp (IfOp* x); 520 virtual void do_Convert (Convert* x); 521 virtual void do_NullCheck (NullCheck* x); 522 virtual void do_TypeCast (TypeCast* x); 523 virtual void do_Invoke (Invoke* x); 524 virtual void do_NewInstance (NewInstance* x); 525 virtual void do_NewTypeArray (NewTypeArray* x); 526 virtual void do_NewObjectArray (NewObjectArray* x); 527 virtual void do_NewMultiArray (NewMultiArray* x); 528 virtual void do_CheckCast (CheckCast* x); 529 virtual void do_InstanceOf (InstanceOf* x); 530 virtual void do_MonitorEnter (MonitorEnter* x); 531 virtual void do_MonitorExit (MonitorExit* x); 532 virtual void do_Intrinsic (Intrinsic* x); 533 virtual void do_BlockBegin (BlockBegin* x); 534 virtual void do_Goto (Goto* x); 535 virtual void do_If (If* x); 536 virtual void do_IfInstanceOf (IfInstanceOf* x); 537 virtual void do_TableSwitch (TableSwitch* x); 538 virtual void do_LookupSwitch (LookupSwitch* x); 539 virtual void do_Return (Return* x); 540 virtual void do_Throw (Throw* x); 541 virtual void do_Base (Base* x); 542 virtual void do_OsrEntry (OsrEntry* x); 543 virtual void do_ExceptionObject(ExceptionObject* x); 544 virtual void do_RoundFP (RoundFP* x); 545 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x); 546 virtual void do_UnsafePutRaw (UnsafePutRaw* x); 547 virtual void do_UnsafeGetObject(UnsafeGetObject* x); 548 virtual void do_UnsafePutObject(UnsafePutObject* x); 549 virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x); 550 virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x); 551 virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x); 552 virtual void do_ProfileCall (ProfileCall* x); 553 virtual void do_ProfileReturnType (ProfileReturnType* x); 554 virtual void do_ProfileInvoke (ProfileInvoke* x); 555 virtual void do_RuntimeCall (RuntimeCall* x); 556 virtual void do_MemBar (MemBar* x); 557 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x); 558 #ifdef ASSERT 559 virtual void do_Assert (Assert* x); 560 #endif 561 562 #ifdef C1_LIRGENERATOR_MD_HPP 563 #include C1_LIRGENERATOR_MD_HPP 564 #endif 565 }; 566 567 568 class LIRItem: public CompilationResourceObj { 569 private: 570 Value _value; 571 LIRGenerator* _gen; 572 LIR_Opr _result; 573 bool _destroys_register; 574 LIR_Opr _new_result; 575 576 LIRGenerator* gen() const { return _gen; } 577 578 public: 579 LIRItem(Value value, LIRGenerator* gen) { 580 _destroys_register = false; 581 _gen = gen; 582 set_instruction(value); 583 } 584 585 LIRItem(LIRGenerator* gen) { 586 _destroys_register = false; 587 _gen = gen; 588 _result = LIR_OprFact::illegalOpr; 589 set_instruction(NULL); 590 } 591 592 void set_instruction(Value value) { 593 _value = value; 594 _result = LIR_OprFact::illegalOpr; 595 if (_value != NULL) { 596 _gen->walk(_value); 597 _result = _value->operand(); 598 } 599 _new_result = LIR_OprFact::illegalOpr; 600 } 601 602 Value value() const { return _value; } 603 ValueType* type() const { return value()->type(); } 604 LIR_Opr result() { 605 assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()), 606 "shouldn't use set_destroys_register with physical regsiters"); 607 if (_destroys_register && _result->is_register()) { 608 if (_new_result->is_illegal()) { 609 _new_result = _gen->new_register(type()); 610 gen()->lir()->move(_result, _new_result); 611 } 612 return _new_result; 613 } else { 614 return _result; 615 } 616 return _result; 617 } 618 619 void set_result(LIR_Opr opr); 620 621 void load_item(); 622 void load_byte_item(); 623 void load_nonconstant(); 624 // load any values which can't be expressed as part of a single store instruction 625 void load_for_store(BasicType store_type); 626 void load_item_force(LIR_Opr reg); 627 628 void dont_load_item() { 629 // do nothing 630 } 631 632 void set_destroys_register() { 633 _destroys_register = true; 634 } 635 636 bool is_constant() const { return value()->as_Constant() != NULL; } 637 bool is_stack() { return result()->is_stack(); } 638 bool is_register() { return result()->is_register(); } 639 640 ciObject* get_jobject_constant() const; 641 jint get_jint_constant() const; 642 jlong get_jlong_constant() const; 643 jfloat get_jfloat_constant() const; 644 jdouble get_jdouble_constant() const; 645 jint get_address_constant() const; 646 }; 647 648 #endif // SHARE_VM_C1_C1_LIRGENERATOR_HPP