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