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);
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,
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
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
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;
|
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 bool _in_conditional_code;
175
176 LIRGenerator* gen() {
177 return this;
178 }
179
180 void print_if_not_loaded(const NewInstance* new_instance) PRODUCT_RETURN;
181
182 public:
183 #ifdef ASSERT
184 LIR_List* lir(const char * file, int line) const {
185 _lir->set_file_and_line(file, line);
186 return _lir;
187 }
188 #endif
189 LIR_List* lir() const {
190 return _lir;
191 }
192
193 private:
194 // a simple cache of constants used within a block
195 GrowableArray<LIR_Const*> _constants;
196 LIR_OprList _reg_for_constants;
197 Values _unpinned_constants;
198
199 friend class PhiResolver;
200
201 void set_in_conditional_code(bool v);
202 public:
203 // unified bailout support
204 void bailout(const char* msg) const { compilation()->bailout(msg); }
205 bool bailed_out() const { return compilation()->bailed_out(); }
206
207 void block_do_prolog(BlockBegin* block);
208 void block_do_epilog(BlockBegin* block);
209
210 // register allocation
211 LIR_Opr rlock(Value instr); // lock a free register
212 LIR_Opr rlock_result(Value instr);
213 LIR_Opr rlock_result(Value instr, BasicType type);
214 LIR_Opr rlock_byte(BasicType type);
215 LIR_Opr rlock_callee_saved(BasicType type);
216
217 // get a constant into a register and get track of what register was used
218 LIR_Opr load_constant(Constant* x);
219 LIR_Opr load_constant(LIR_Const* constant);
220
221 bool in_conditional_code() { return _in_conditional_code; }
222 // Given an immediate value, return an operand usable in logical ops.
223 LIR_Opr load_immediate(jlong x, BasicType type);
224
225 void set_result(Value x, LIR_Opr opr) {
226 assert(opr->is_valid(), "must set to valid value");
227 assert(x->operand()->is_illegal(), "operand should never change");
228 assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register");
229 x->set_operand(opr);
230 assert(opr == x->operand(), "must be");
231 #ifdef ASSERT
232 if (opr->is_virtual()) {
233 _instruction_for_operand.at_put_grow(opr->vreg_number(), x, nullptr);
234 }
235 #endif
236 }
237 void set_no_result(Value x) { assert(!x->has_uses(), "can't have use"); x->clear_operand(); }
238
239 friend class LIRItem;
240
241 LIR_Opr round_item(LIR_Opr opr);
263 void do_getModifiers(Intrinsic* x);
264 void do_getClass(Intrinsic* x);
265 void do_getObjectSize(Intrinsic* x);
266 void do_currentCarrierThread(Intrinsic* x);
267 void do_scopedValueCache(Intrinsic* x);
268 void do_vthread(Intrinsic* x);
269 void do_JavaThreadField(Intrinsic* x, ByteSize offset);
270 void do_FmaIntrinsic(Intrinsic* x);
271 void do_MathIntrinsic(Intrinsic* x);
272 void do_LibmIntrinsic(Intrinsic* x);
273 void do_ArrayCopy(Intrinsic* x);
274 void do_CompareAndSwap(Intrinsic* x, ValueType* type);
275 void do_PreconditionsCheckIndex(Intrinsic* x, BasicType type);
276 void do_FPIntrinsics(Intrinsic* x);
277 void do_Reference_get(Intrinsic* x);
278 void do_update_CRC32(Intrinsic* x);
279 void do_update_CRC32C(Intrinsic* x);
280 void do_vectorizedMismatch(Intrinsic* x);
281 void do_blackhole(Intrinsic* x);
282
283 void access_flat_array(bool is_load, LIRItem& array, LIRItem& index, LIRItem& obj_item, ciField* field = nullptr, int offset = 0);
284 void access_sub_element(LIRItem& array, LIRItem& index, LIR_Opr& result, ciField* field, int sub_offset);
285 LIR_Opr get_and_load_element_address(LIRItem& array, LIRItem& index);
286 bool needs_flat_array_store_check(StoreIndexed* x);
287 void check_flat_array(LIR_Opr array, LIR_Opr value, CodeStub* slow_path);
288 bool needs_null_free_array_store_check(StoreIndexed* x);
289 void check_null_free_array(LIRItem& array, LIRItem& value, CodeEmitInfo* info);
290 void substitutability_check(IfOp* x, LIRItem& left, LIRItem& right, LIRItem& t_val, LIRItem& f_val);
291 void substitutability_check(If* x, LIRItem& left, LIRItem& right);
292 void substitutability_check_common(Value left_val, Value right_val, LIRItem& left, LIRItem& right,
293 LIR_Opr equal_result, LIR_Opr not_equal_result, LIR_Opr result, CodeEmitInfo* info);
294 void init_temps_for_substitutability_check(LIR_Opr& tmp1, LIR_Opr& tmp2);
295
296 public:
297 LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
298 LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
299
300 // convenience functions
301 LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info);
302 LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info);
303
304 // Access API
305
306 private:
307 BarrierSetC1 *_barrier_set;
308
309 public:
310 void access_store_at(DecoratorSet decorators, BasicType type,
311 LIRItem& base, LIR_Opr offset, LIR_Opr value,
312 CodeEmitInfo* patch_info = nullptr, CodeEmitInfo* store_emit_info = nullptr);
313
314 void access_load_at(DecoratorSet decorators, BasicType type,
315 LIRItem& base, LIR_Opr offset, LIR_Opr result,
329
330 // These need to guarantee JMM volatile semantics are preserved on each platform
331 // and requires one implementation per architecture.
332 LIR_Opr atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value);
333 LIR_Opr atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& new_value);
334 LIR_Opr atomic_add(BasicType type, LIR_Opr addr, LIRItem& new_value);
335
336 #ifdef CARDTABLEBARRIERSET_POST_BARRIER_HELPER
337 virtual void CardTableBarrierSet_post_barrier_helper(LIR_Opr addr, LIR_Const* card_table_base);
338 #endif
339
340 // specific implementations
341 void array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci);
342
343 static LIR_Opr result_register_for(ValueType* type, bool callee = false);
344
345 ciObject* get_jobject_constant(Value value);
346
347 LIRItemList* invoke_visit_arguments(Invoke* x);
348 void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list);
349 void invoke_load_one_argument(LIRItem* param, LIR_Opr loc);
350 void trace_block_entry(BlockBegin* block);
351
352 // volatile field operations are never patchable because a klass
353 // must be loaded to know it's volatile which means that the offset
354 // it always known as well.
355 void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info);
356 void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info);
357
358 void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile);
359 void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile);
360
361 void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args);
362
363 void increment_counter(address counter, BasicType type, int step = 1);
364 void increment_counter(LIR_Address* addr, int step = 1);
365
366 void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp, CodeEmitInfo* info = nullptr);
367 // machine dependent. returns true if it emitted code for the multiply
368 bool strength_reduce_multiply(LIR_Opr left, jint constant, LIR_Opr result, LIR_Opr tmp);
369
370 void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes);
371
372 void klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve = false);
373
374 // this loads the length and compares against the index
375 void array_range_check (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info);
376
377 void arithmetic_op_int (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp);
378 void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = nullptr);
379 void arithmetic_op_fpu (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp = LIR_OprFact::illegalOpr);
380
381 void shift_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp);
382
383 void logic_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right);
384
385 void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info, CodeStub* throw_ie_stub);
386 void monitor_exit (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no);
387
388 void new_instance(LIR_Opr dst, ciInstanceKlass* klass, bool is_unresolved, bool allow_inline, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info);
389
390 // machine dependent
391 void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
392 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info);
393
394 void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type);
395
396 // returns a LIR_Address to address an array location. May also
397 // emit some code as part of address calculation. If
398 // needs_card_mark is true then compute the full address for use by
399 // both the store and the card mark.
400 LIR_Address* generate_address(LIR_Opr base,
401 LIR_Opr index, int shift,
402 int disp,
403 BasicType type);
404 LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) {
405 return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type);
406 }
407 LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type);
408
480 };
481 return l;
482 }
483
484 #ifdef __SOFTFP__
485 void do_soft_float_compare(If *x);
486 #endif // __SOFTFP__
487
488 SwitchRangeArray* create_lookup_ranges(TableSwitch* x);
489 SwitchRangeArray* create_lookup_ranges(LookupSwitch* x);
490 void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux);
491
492 void do_RuntimeCall(address routine, Intrinsic* x);
493
494 ciKlass* profile_type(ciMethodData* md, int md_first_offset, int md_offset, intptr_t profiled_k,
495 Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,
496 ciKlass* callee_signature_k);
497 void profile_arguments(ProfileCall* x);
498 void profile_parameters(Base* x);
499 void profile_parameters_at_call(ProfileCall* x);
500 void profile_flags(ciMethodData* md, ciProfileData* load_store, int flag, LIR_Condition condition = lir_cond_always);
501 template <class ArrayData> void profile_null_free_array(LIRItem array, ciMethodData* md, ArrayData* load_store);
502 template <class ArrayData> void profile_array_type(AccessIndexed* x, ciMethodData*& md, ArrayData*& load_store);
503 void profile_element_type(Value element, ciMethodData* md, ciArrayLoadData* load_store);
504 bool profile_inline_klass(ciMethodData* md, ciProfileData* data, Value value, int flag);
505 LIR_Opr mask_boolean(LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info);
506
507 public:
508 Compilation* compilation() const { return _compilation; }
509 FrameMap* frame_map() const { return _compilation->frame_map(); }
510 ciMethod* method() const { return _method; }
511 BlockBegin* block() const { return _block; }
512 IRScope* scope() const { return block()->scope(); }
513
514 int max_virtual_register_number() const { return _virtual_register_number; }
515
516 void block_do(BlockBegin* block);
517
518 // Flags that can be set on vregs
519 enum VregFlag {
520 must_start_in_memory = 0 // needs to be assigned a memory location at beginning, but may then be loaded in a register
521 , callee_saved = 1 // must be in a callee saved register
522 , byte_reg = 2 // must be in a byte register
523 , num_vreg_flags
524
525 };
526
527 LIRGenerator(Compilation* compilation, ciMethod* method)
528 : _compilation(compilation)
529 , _method(method)
530 , _virtual_register_number(LIR_Opr::vreg_base)
531 , _vreg_flags(num_vreg_flags)
532 , _in_conditional_code(false)
533 , _barrier_set(BarrierSet::barrier_set()->barrier_set_c1()) {
534 }
535
536 #ifdef ASSERT
537 // for virtual registers, maps them back to Phi's or Local's
538 Instruction* instruction_for_vreg(int reg_num);
539 #endif
540
541 void set_vreg_flag (int vreg_num, VregFlag f);
542 bool is_vreg_flag_set(int vreg_num, VregFlag f);
543 void set_vreg_flag (LIR_Opr opr, VregFlag f) { set_vreg_flag(opr->vreg_number(), f); }
544 bool is_vreg_flag_set(LIR_Opr opr, VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); }
545
546 // statics
547 static LIR_Opr exceptionOopOpr();
548 static LIR_Opr exceptionPcOpr();
549 static LIR_Opr divInOpr();
550 static LIR_Opr divOutOpr();
551 static LIR_Opr remOutOpr();
552 #ifdef S390
592 virtual void do_MonitorEnter (MonitorEnter* x);
593 virtual void do_MonitorExit (MonitorExit* x);
594 virtual void do_Intrinsic (Intrinsic* x);
595 virtual void do_BlockBegin (BlockBegin* x);
596 virtual void do_Goto (Goto* x);
597 virtual void do_If (If* x);
598 virtual void do_TableSwitch (TableSwitch* x);
599 virtual void do_LookupSwitch (LookupSwitch* x);
600 virtual void do_Return (Return* x);
601 virtual void do_Throw (Throw* x);
602 virtual void do_Base (Base* x);
603 virtual void do_OsrEntry (OsrEntry* x);
604 virtual void do_ExceptionObject(ExceptionObject* x);
605 virtual void do_RoundFP (RoundFP* x);
606 virtual void do_UnsafeGet (UnsafeGet* x);
607 virtual void do_UnsafePut (UnsafePut* x);
608 virtual void do_UnsafeGetAndSet(UnsafeGetAndSet* x);
609 virtual void do_ProfileCall (ProfileCall* x);
610 virtual void do_ProfileReturnType (ProfileReturnType* x);
611 virtual void do_ProfileInvoke (ProfileInvoke* x);
612 virtual void do_ProfileACmpTypes(ProfileACmpTypes* x);
613 virtual void do_RuntimeCall (RuntimeCall* x);
614 virtual void do_MemBar (MemBar* x);
615 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x);
616 #ifdef ASSERT
617 virtual void do_Assert (Assert* x);
618 #endif
619
620 #ifdef C1_LIRGENERATOR_MD_HPP
621 #include C1_LIRGENERATOR_MD_HPP
622 #endif
623 };
624
625
626 class LIRItem: public CompilationResourceObj {
627 private:
628 Value _value;
629 LIRGenerator* _gen;
630 LIR_Opr _result;
631 bool _destroys_register;
632 LIR_Opr _new_result;
|