Fri, 29 Apr 2016 00:06:10 +0800
Added MIPS 64-bit port.
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 #ifdef ASSERT
179 LIR_List* lir(const char * file, int line) const {
180 _lir->set_file_and_line(file, line);
181 return _lir;
182 }
183 #endif
184 LIR_List* lir() const {
185 return _lir;
186 }
188 // a simple cache of constants used within a block
189 GrowableArray<LIR_Const*> _constants;
190 LIR_OprList _reg_for_constants;
191 Values _unpinned_constants;
193 #ifdef MIPS64
194 LIR_Const* _card_table_base;
195 #endif
196 friend class PhiResolver;
198 // unified bailout support
199 void bailout(const char* msg) const { compilation()->bailout(msg); }
200 bool bailed_out() const { return compilation()->bailed_out(); }
202 void block_do_prolog(BlockBegin* block);
203 void block_do_epilog(BlockBegin* block);
205 // register allocation
206 LIR_Opr rlock(Value instr); // lock a free register
207 LIR_Opr rlock_result(Value instr);
208 LIR_Opr rlock_result(Value instr, BasicType type);
209 LIR_Opr rlock_byte(BasicType type);
210 LIR_Opr rlock_callee_saved(BasicType type);
212 // get a constant into a register and get track of what register was used
213 LIR_Opr load_constant(Constant* x);
214 LIR_Opr load_constant(LIR_Const* constant);
216 #ifdef MIPS64
217 LIR_Const* card_table_base() const {
218 return _card_table_base;
219 }
220 #endif
221 // Given an immediate value, return an operand usable in logical ops.
222 LIR_Opr load_immediate(int x, BasicType type);
224 void set_result(Value x, LIR_Opr opr) {
225 assert(opr->is_valid(), "must set to valid value");
226 assert(x->operand()->is_illegal(), "operand should never change");
227 assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register");
228 x->set_operand(opr);
229 assert(opr == x->operand(), "must be");
230 if (opr->is_virtual()) {
231 _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL);
232 }
233 }
234 void set_no_result(Value x) { assert(!x->has_uses(), "can't have use"); x->clear_operand(); }
236 friend class LIRItem;
238 LIR_Opr round_item(LIR_Opr opr);
239 LIR_Opr force_to_spill(LIR_Opr value, BasicType t);
241 #ifdef MIPS64
242 void profile_branch(If* if_instr, If::Condition cond, LIR_Opr left, LIR_Opr right);
243 #endif
244 PhiResolverState& resolver_state() { return _resolver_state; }
246 void move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val);
247 void move_to_phi(ValueStack* cur_state);
249 // code emission
250 void do_ArithmeticOp_Long (ArithmeticOp* x);
251 void do_ArithmeticOp_Int (ArithmeticOp* x);
252 void do_ArithmeticOp_FPU (ArithmeticOp* x);
254 // platform dependent
255 LIR_Opr getThreadPointer();
257 void do_RegisterFinalizer(Intrinsic* x);
258 void do_isInstance(Intrinsic* x);
259 void do_getClass(Intrinsic* x);
260 void do_currentThread(Intrinsic* x);
261 void do_MathIntrinsic(Intrinsic* x);
262 void do_ArrayCopy(Intrinsic* x);
263 void do_CompareAndSwap(Intrinsic* x, ValueType* type);
264 void do_NIOCheckIndex(Intrinsic* x);
265 void do_FPIntrinsics(Intrinsic* x);
266 void do_Reference_get(Intrinsic* x);
267 void do_update_CRC32(Intrinsic* x);
269 void do_UnsafePrefetch(UnsafePrefetch* x, bool is_store);
271 LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
272 LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
274 // convenience functions
275 LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info);
276 LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info);
278 // GC Barriers
280 // generic interface
282 void pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val, bool do_load, bool patch, CodeEmitInfo* info);
283 void post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
285 // specific implementations
286 // pre barriers
288 void G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,
289 bool do_load, bool patch, CodeEmitInfo* info);
291 // post barriers
293 void G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
294 void CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
297 static LIR_Opr result_register_for(ValueType* type, bool callee = false);
299 ciObject* get_jobject_constant(Value value);
301 LIRItemList* invoke_visit_arguments(Invoke* x);
302 void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list);
304 void trace_block_entry(BlockBegin* block);
306 // volatile field operations are never patchable because a klass
307 // must be loaded to know it's volatile which means that the offset
308 // it always known as well.
309 void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info);
310 void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info);
312 void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile);
313 void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile);
315 void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args);
317 void increment_counter(address counter, BasicType type, int step = 1);
318 void increment_counter(LIR_Address* addr, int step = 1);
320 // is_strictfp is only needed for mul and div (and only generates different code on i486)
321 void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp, CodeEmitInfo* info = NULL);
322 // machine dependent. returns true if it emitted code for the multiply
323 bool strength_reduce_multiply(LIR_Opr left, int constant, LIR_Opr result, LIR_Opr tmp);
325 void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes);
327 void klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info);
329 // this loads the length and compares against the index
330 void array_range_check (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info);
331 // For java.nio.Buffer.checkIndex
332 void nio_range_check (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info);
334 void arithmetic_op_int (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp);
335 void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL);
336 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);
338 void shift_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp);
340 void logic_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right);
342 void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info);
343 void monitor_exit (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no);
344 #ifndef MIPS64
345 void new_instance (LIR_Opr dst, ciInstanceKlass* klass, LIR_Opr scratch1, LIR_Opr scratch2, LIR_Opr scratch3, LIR_Opr scratch4, LIR_Opr klass_reg, CodeEmitInfo* info);
346 #else
347 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);
348 #endif
349 // machine dependent
350 void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
351 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info);
352 void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info);
354 void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type);
356 // returns a LIR_Address to address an array location. May also
357 // emit some code as part of address calculation. If
358 // needs_card_mark is true then compute the full address for use by
359 // both the store and the card mark.
360 LIR_Address* generate_address(LIR_Opr base,
361 LIR_Opr index, int shift,
362 int disp,
363 BasicType type);
364 LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) {
365 return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type);
366 }
367 LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type, bool needs_card_mark);
369 #ifdef MIPS64
370 void write_barrier(LIR_Opr addr);
371 #endif
372 // the helper for generate_address
373 void add_large_constant(LIR_Opr src, int c, LIR_Opr dest);
375 // machine preferences and characteristics
376 bool can_inline_as_constant(Value i) const;
377 bool can_inline_as_constant(LIR_Const* c) const;
378 bool can_store_as_constant(Value i, BasicType type) const;
380 LIR_Opr safepoint_poll_register();
382 void profile_branch(If* if_instr, If::Condition cond);
383 void increment_event_counter_impl(CodeEmitInfo* info,
384 ciMethod *method, int frequency,
385 int bci, bool backedge, bool notify);
386 void increment_event_counter(CodeEmitInfo* info, int bci, bool backedge);
387 void increment_invocation_counter(CodeEmitInfo *info) {
388 if (compilation()->count_invocations()) {
389 increment_event_counter(info, InvocationEntryBci, false);
390 }
391 }
392 void increment_backedge_counter(CodeEmitInfo* info, int bci) {
393 if (compilation()->count_backedges()) {
394 increment_event_counter(info, bci, true);
395 }
396 }
398 CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false);
399 CodeEmitInfo* state_for(Instruction* x);
401 // allocates a virtual register for this instruction if
402 // one isn't already allocated. Only for Phi and Local.
403 LIR_Opr operand_for_instruction(Instruction *x);
405 void set_block(BlockBegin* block) { _block = block; }
407 void block_prolog(BlockBegin* block);
408 void block_epilog(BlockBegin* block);
410 void do_root (Instruction* instr);
411 void walk (Instruction* instr);
413 void bind_block_entry(BlockBegin* block);
414 void start_block(BlockBegin* block);
416 LIR_Opr new_register(BasicType type);
417 LIR_Opr new_register(Value value) { return new_register(as_BasicType(value->type())); }
418 LIR_Opr new_register(ValueType* type) { return new_register(as_BasicType(type)); }
420 // returns a register suitable for doing pointer math
421 LIR_Opr new_pointer_register() {
422 #ifdef _LP64
423 return new_register(T_LONG);
424 #else
425 return new_register(T_INT);
426 #endif
427 }
429 static LIR_Condition lir_cond(If::Condition cond) {
430 LIR_Condition l;
431 switch (cond) {
432 case If::eql: l = lir_cond_equal; break;
433 case If::neq: l = lir_cond_notEqual; break;
434 case If::lss: l = lir_cond_less; break;
435 case If::leq: l = lir_cond_lessEqual; break;
436 case If::geq: l = lir_cond_greaterEqual; break;
437 case If::gtr: l = lir_cond_greater; break;
438 case If::aeq: l = lir_cond_aboveEqual; break;
439 case If::beq: l = lir_cond_belowEqual; break;
440 };
441 return l;
442 }
444 #ifdef __SOFTFP__
445 void do_soft_float_compare(If *x);
446 #endif // __SOFTFP__
448 void init();
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);
454 void do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x);
455 #ifdef TRACE_HAVE_INTRINSICS
456 void do_ThreadIDIntrinsic(Intrinsic* x);
457 void do_ClassIDIntrinsic(Intrinsic* x);
458 #endif
459 ciKlass* profile_type(ciMethodData* md, int md_first_offset, int md_offset, intptr_t profiled_k,
460 Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,
461 ciKlass* callee_signature_k);
462 void profile_arguments(ProfileCall* x);
463 void profile_parameters(Base* x);
464 void profile_parameters_at_call(ProfileCall* x);
466 public:
467 Compilation* compilation() const { return _compilation; }
468 FrameMap* frame_map() const { return _compilation->frame_map(); }
469 ciMethod* method() const { return _method; }
470 BlockBegin* block() const { return _block; }
471 IRScope* scope() const { return block()->scope(); }
473 int max_virtual_register_number() const { return _virtual_register_number; }
475 void block_do(BlockBegin* block);
477 // Flags that can be set on vregs
478 enum VregFlag {
479 must_start_in_memory = 0 // needs to be assigned a memory location at beginning, but may then be loaded in a register
480 , callee_saved = 1 // must be in a callee saved register
481 , byte_reg = 2 // must be in a byte register
482 , num_vreg_flags
484 };
486 LIRGenerator(Compilation* compilation, ciMethod* method)
487 : _compilation(compilation)
488 , _method(method)
489 , _virtual_register_number(LIR_OprDesc::vreg_base)
490 , _vreg_flags(NULL, 0, num_vreg_flags) {
491 init();
492 }
494 // for virtual registers, maps them back to Phi's or Local's
495 Instruction* instruction_for_opr(LIR_Opr opr);
496 Instruction* instruction_for_vreg(int reg_num);
498 void set_vreg_flag (int vreg_num, VregFlag f);
499 bool is_vreg_flag_set(int vreg_num, VregFlag f);
500 void set_vreg_flag (LIR_Opr opr, VregFlag f) { set_vreg_flag(opr->vreg_number(), f); }
501 bool is_vreg_flag_set(LIR_Opr opr, VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); }
503 // statics
504 static LIR_Opr exceptionOopOpr();
505 static LIR_Opr exceptionPcOpr();
506 static LIR_Opr divInOpr();
507 static LIR_Opr divOutOpr();
508 static LIR_Opr remOutOpr();
509 static LIR_Opr shiftCountOpr();
510 LIR_Opr syncTempOpr();
511 LIR_Opr atomicLockOpr();
513 // returns a register suitable for saving the thread in a
514 // call_runtime_leaf if one is needed.
515 LIR_Opr getThreadTemp();
517 // visitor functionality
518 virtual void do_Phi (Phi* x);
519 virtual void do_Local (Local* x);
520 virtual void do_Constant (Constant* x);
521 virtual void do_LoadField (LoadField* x);
522 virtual void do_StoreField (StoreField* x);
523 virtual void do_ArrayLength (ArrayLength* x);
524 virtual void do_LoadIndexed (LoadIndexed* x);
525 virtual void do_StoreIndexed (StoreIndexed* x);
526 virtual void do_NegateOp (NegateOp* x);
527 virtual void do_ArithmeticOp (ArithmeticOp* x);
528 virtual void do_ShiftOp (ShiftOp* x);
529 virtual void do_LogicOp (LogicOp* x);
530 virtual void do_CompareOp (CompareOp* x);
531 virtual void do_IfOp (IfOp* x);
532 virtual void do_Convert (Convert* x);
533 virtual void do_NullCheck (NullCheck* x);
534 virtual void do_TypeCast (TypeCast* x);
535 virtual void do_Invoke (Invoke* x);
536 virtual void do_NewInstance (NewInstance* x);
537 virtual void do_NewTypeArray (NewTypeArray* x);
538 virtual void do_NewObjectArray (NewObjectArray* x);
539 virtual void do_NewMultiArray (NewMultiArray* x);
540 virtual void do_CheckCast (CheckCast* x);
541 virtual void do_InstanceOf (InstanceOf* x);
542 virtual void do_MonitorEnter (MonitorEnter* x);
543 virtual void do_MonitorExit (MonitorExit* x);
544 virtual void do_Intrinsic (Intrinsic* x);
545 virtual void do_BlockBegin (BlockBegin* x);
546 virtual void do_Goto (Goto* x);
547 virtual void do_If (If* x);
548 virtual void do_IfInstanceOf (IfInstanceOf* x);
549 virtual void do_TableSwitch (TableSwitch* x);
550 virtual void do_LookupSwitch (LookupSwitch* x);
551 virtual void do_Return (Return* x);
552 virtual void do_Throw (Throw* x);
553 virtual void do_Base (Base* x);
554 virtual void do_OsrEntry (OsrEntry* x);
555 virtual void do_ExceptionObject(ExceptionObject* x);
556 virtual void do_RoundFP (RoundFP* x);
557 virtual void do_UnsafeGetRaw (UnsafeGetRaw* x);
558 virtual void do_UnsafePutRaw (UnsafePutRaw* x);
559 virtual void do_UnsafeGetObject(UnsafeGetObject* x);
560 virtual void do_UnsafePutObject(UnsafePutObject* x);
561 virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x);
562 virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x);
563 virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x);
564 virtual void do_ProfileCall (ProfileCall* x);
565 virtual void do_ProfileReturnType (ProfileReturnType* x);
566 virtual void do_ProfileInvoke (ProfileInvoke* x);
567 virtual void do_RuntimeCall (RuntimeCall* x);
568 virtual void do_MemBar (MemBar* x);
569 virtual void do_RangeCheckPredicate(RangeCheckPredicate* x);
570 #ifdef ASSERT
571 virtual void do_Assert (Assert* x);
572 #endif
573 };
576 class LIRItem: public CompilationResourceObj {
577 private:
578 Value _value;
579 LIRGenerator* _gen;
580 LIR_Opr _result;
581 bool _destroys_register;
582 LIR_Opr _new_result;
584 LIRGenerator* gen() const { return _gen; }
586 public:
587 LIRItem(Value value, LIRGenerator* gen) {
588 _destroys_register = false;
589 _gen = gen;
590 set_instruction(value);
591 }
593 LIRItem(LIRGenerator* gen) {
594 _destroys_register = false;
595 _gen = gen;
596 _result = LIR_OprFact::illegalOpr;
597 set_instruction(NULL);
598 }
600 void set_instruction(Value value) {
601 _value = value;
602 _result = LIR_OprFact::illegalOpr;
603 if (_value != NULL) {
604 _gen->walk(_value);
605 _result = _value->operand();
606 }
607 _new_result = LIR_OprFact::illegalOpr;
608 }
610 Value value() const { return _value; }
611 ValueType* type() const { return value()->type(); }
612 LIR_Opr result() {
613 assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()),
614 "shouldn't use set_destroys_register with physical regsiters");
615 if (_destroys_register && _result->is_register()) {
616 if (_new_result->is_illegal()) {
617 _new_result = _gen->new_register(type());
618 gen()->lir()->move(_result, _new_result);
619 }
620 return _new_result;
621 } else {
622 return _result;
623 }
624 return _result;
625 }
627 void set_result(LIR_Opr opr);
629 void load_item();
630 void load_byte_item();
631 void load_nonconstant();
632 // load any values which can't be expressed as part of a single store instruction
633 void load_for_store(BasicType store_type);
634 void load_item_force(LIR_Opr reg);
636 void dont_load_item() {
637 // do nothing
638 }
640 void set_destroys_register() {
641 _destroys_register = true;
642 }
644 bool is_constant() const { return value()->as_Constant() != NULL; }
645 bool is_stack() { return result()->is_stack(); }
646 bool is_register() { return result()->is_register(); }
648 ciObject* get_jobject_constant() const;
649 jint get_jint_constant() const;
650 jlong get_jlong_constant() const;
651 jfloat get_jfloat_constant() const;
652 jdouble get_jdouble_constant() const;
653 jint get_address_constant() const;
654 };
656 #endif // SHARE_VM_C1_C1_LIRGENERATOR_HPP