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