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