1 /*
  2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #ifndef SHARE_VM_C1_C1_LIRGENERATOR_HPP
 26 #define SHARE_VM_C1_C1_LIRGENERATOR_HPP
 27 
 28 #include "c1/c1_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 "utilities/macros.hpp"
 34 #include "utilities/sizes.hpp"
 35 
 36 class BarrierSetC1;
 37 
 38 // The classes responsible for code emission and register allocation
 39 
 40 
 41 class LIRGenerator;
 42 class LIREmitter;
 43 class Invoke;
 44 class SwitchRange;
 45 class LIRItem;
 46 
 47 typedef GrowableArray<LIRItem*> LIRItemList;
 48 
 49 class SwitchRange: public CompilationResourceObj {
 50  private:
 51   int _low_key;
 52   int _high_key;
 53   BlockBegin* _sux;
 54  public:
 55   SwitchRange(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<SwitchRange*> SwitchRangeArray;
 64 typedef GrowableArray<SwitchRange*> 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 reach 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(int max_vregs);
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, int max_vregs);
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   Values        _instruction_for_operand;
170   BitMap2D      _vreg_flags; // flags which can be set on a per-vreg basis
171   LIR_List*     _lir;
172 
173   LIRGenerator* gen() {
174     return this;
175   }
176 
177   void print_if_not_loaded(const NewInstance* new_instance) PRODUCT_RETURN;
178 
179  public:
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   }
189 
190  private:
191   // a simple cache of constants used within a block
192   GrowableArray<LIR_Const*>       _constants;
193   LIR_OprList                     _reg_for_constants;
194   Values                          _unpinned_constants;
195 
196   friend class PhiResolver;
197 
198  public:
199   // unified bailout support
200   void bailout(const char* msg) const            { compilation()->bailout(msg); }
201   bool bailed_out() const                        { return compilation()->bailed_out(); }
202 
203   void block_do_prolog(BlockBegin* block);
204   void block_do_epilog(BlockBegin* block);
205 
206   // register allocation
207   LIR_Opr rlock(Value instr);                      // lock a free register
208   LIR_Opr rlock_result(Value instr);
209   LIR_Opr rlock_result(Value instr, BasicType type);
210   LIR_Opr rlock_byte(BasicType type);
211   LIR_Opr rlock_callee_saved(BasicType type);
212 
213   // get a constant into a register and get track of what register was used
214   LIR_Opr load_constant(Constant* x);
215   LIR_Opr load_constant(LIR_Const* constant);
216 
217   // Given an immediate value, return an operand usable in logical ops.
218   LIR_Opr load_immediate(int x, BasicType type);
219 
220   void  set_result(Value x, LIR_Opr opr)           {
221     assert(opr->is_valid(), "must set to valid value");
222     assert(x->operand()->is_illegal(), "operand should never change");
223     assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register");
224     x->set_operand(opr);
225     assert(opr == x->operand(), "must be");
226     if (opr->is_virtual()) {
227       _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL);
228     }
229   }
230   void  set_no_result(Value x)                     { assert(!x->has_uses(), "can't have use"); x->clear_operand(); }
231 
232   friend class LIRItem;
233 
234   LIR_Opr round_item(LIR_Opr opr);
235   LIR_Opr force_to_spill(LIR_Opr value, BasicType t);
236 
237   PhiResolverState& resolver_state() { return _resolver_state; }
238 
239   void  move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val);
240   void  move_to_phi(ValueStack* cur_state);
241 
242   // platform dependent
243   LIR_Opr getThreadPointer();
244 
245  private:
246   // code emission
247   void do_ArithmeticOp_Long(ArithmeticOp* x);
248   void do_ArithmeticOp_Int (ArithmeticOp* x);
249   void do_ArithmeticOp_FPU (ArithmeticOp* x);
250 
251   void do_RegisterFinalizer(Intrinsic* x);
252   void do_isInstance(Intrinsic* x);
253   void do_isPrimitive(Intrinsic* x);
254   void do_getClass(Intrinsic* x);
255   void do_currentThread(Intrinsic* x);
256   void do_FmaIntrinsic(Intrinsic* x);
257   void do_MathIntrinsic(Intrinsic* x);
258   void do_LibmIntrinsic(Intrinsic* x);
259   void do_ArrayCopy(Intrinsic* x);
260   void do_CompareAndSwap(Intrinsic* x, ValueType* type);
261   void do_NIOCheckIndex(Intrinsic* x);
262   void do_FPIntrinsics(Intrinsic* x);
263   void do_Reference_get(Intrinsic* x);
264   void do_update_CRC32(Intrinsic* x);
265   void do_update_CRC32C(Intrinsic* x);
266   void do_vectorizedMismatch(Intrinsic* x);
267 
268  public:
269   LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
270   LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
271 
272   // convenience functions
273   LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info);
274   LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info);
275 
276   // Access API
277 
278  private:
279   BarrierSetC1 *_barrier_set;
280 
281  public:
282   void access_store_at(DecoratorSet decorators, BasicType type,
283                        LIRItem& base, LIR_Opr offset, LIR_Opr value,
284                        CodeEmitInfo* patch_info = NULL, CodeEmitInfo* store_emit_info = NULL);
285 
286   void access_load_at(DecoratorSet decorators, BasicType type,
287                       LIRItem& base, LIR_Opr offset, LIR_Opr result,
288                       CodeEmitInfo* patch_info = NULL, CodeEmitInfo* load_emit_info = NULL);
289 
290   LIR_Opr access_atomic_cmpxchg_at(DecoratorSet decorators, BasicType type,
291                                    LIRItem& base, LIRItem& offset, LIRItem& cmp_value, LIRItem& new_value);
292 
293   LIR_Opr access_atomic_xchg_at(DecoratorSet decorators, BasicType type,
294                                 LIRItem& base, LIRItem& offset, LIRItem& value);
295 
296   LIR_Opr access_atomic_add_at(DecoratorSet decorators, BasicType type,
297                                LIRItem& base, LIRItem& offset, LIRItem& value);
298 
299   // These need to guarantee JMM volatile semantics are preserved on each platform
300   // and requires one implementation per architecture.
301   LIR_Opr atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value);
302   LIR_Opr atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& new_value);
303   LIR_Opr atomic_add(BasicType type, LIR_Opr addr, LIRItem& new_value);
304 
305   // specific implementations
306   void array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci);
307 
308   static LIR_Opr result_register_for(ValueType* type, bool callee = false);
309 
310   ciObject* get_jobject_constant(Value value);
311 
312   LIRItemList* invoke_visit_arguments(Invoke* x);
313   void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list);
314 
315   void trace_block_entry(BlockBegin* block);
316 
317   // volatile field operations are never patchable because a klass
318   // must be loaded to know it's volatile which means that the offset
319   // it always known as well.
320   void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info);
321   void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info);
322 
323   void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile);
324   void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile);
325 
326   void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args);
327 
328   void increment_counter(address counter, BasicType type, int step = 1);
329   void increment_counter(LIR_Address* addr, int step = 1);
330 
331   // is_strictfp is only needed for mul and div (and only generates different code on i486)
332   void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp, CodeEmitInfo* info = NULL);
333   // machine dependent.  returns true if it emitted code for the multiply
334   bool strength_reduce_multiply(LIR_Opr left, jint constant, LIR_Opr result, LIR_Opr tmp);
335 
336   void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes);
337 
338   void klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve = false);
339 
340   // this loads the length and compares against the index
341   void array_range_check          (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info);
342   // For java.nio.Buffer.checkIndex
343   void nio_range_check            (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info);
344 
345   void arithmetic_op_int  (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp);
346   void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL);
347   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);
348 
349   void shift_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp);
350 
351   void logic_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right);
352 
353   void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info);
354   void monitor_exit  (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no);
355 
356   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);
357 
358   // machine dependent
359   void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
360   void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info);
361 
362   void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type);
363 
364   // returns a LIR_Address to address an array location.  May also
365   // emit some code as part of address calculation.  If
366   // needs_card_mark is true then compute the full address for use by
367   // both the store and the card mark.
368   LIR_Address* generate_address(LIR_Opr base,
369                                 LIR_Opr index, int shift,
370                                 int disp,
371                                 BasicType type);
372   LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) {
373     return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type);
374   }
375   LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type);
376 
377   // the helper for generate_address
378   void add_large_constant(LIR_Opr src, int c, LIR_Opr dest);
379 
380   // machine preferences and characteristics
381   bool can_inline_as_constant(Value i S390_ONLY(COMMA int bits = 20)) const;
382   bool can_inline_as_constant(LIR_Const* c) const;
383   bool can_store_as_constant(Value i, BasicType type) const;
384 
385   LIR_Opr safepoint_poll_register();
386 
387   void profile_branch(If* if_instr, If::Condition cond);
388   void increment_event_counter_impl(CodeEmitInfo* info,
389                                     ciMethod *method, int frequency,
390                                     int bci, bool backedge, bool notify);
391   void increment_event_counter(CodeEmitInfo* info, int bci, bool backedge);
392   void increment_invocation_counter(CodeEmitInfo *info) {
393     if (compilation()->count_invocations()) {
394       increment_event_counter(info, InvocationEntryBci, false);
395     }
396   }
397   void increment_backedge_counter(CodeEmitInfo* info, int bci) {
398     if (compilation()->count_backedges()) {
399       increment_event_counter(info, bci, true);
400     }
401   }
402   void decrement_age(CodeEmitInfo* info);
403   CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false);
404   CodeEmitInfo* state_for(Instruction* x);
405 
406   // allocates a virtual register for this instruction if
407   // one isn't already allocated.  Only for Phi and Local.
408   LIR_Opr operand_for_instruction(Instruction *x);
409 
410   void set_block(BlockBegin* block)              { _block = block; }
411 
412   void block_prolog(BlockBegin* block);
413   void block_epilog(BlockBegin* block);
414 
415   void do_root (Instruction* instr);
416   void walk    (Instruction* instr);
417 
418   void bind_block_entry(BlockBegin* block);
419   void start_block(BlockBegin* block);
420 
421   LIR_Opr new_register(BasicType type);
422   LIR_Opr new_register(Value value)              { return new_register(as_BasicType(value->type())); }
423   LIR_Opr new_register(ValueType* type)          { return new_register(as_BasicType(type)); }
424 
425   // returns a register suitable for doing pointer math
426   LIR_Opr new_pointer_register() {
427 #ifdef _LP64
428     return new_register(T_LONG);
429 #else
430     return new_register(T_INT);
431 #endif
432   }
433 
434   static LIR_Condition lir_cond(If::Condition cond) {
435     LIR_Condition l = lir_cond_unknown;
436     switch (cond) {
437     case If::eql: l = lir_cond_equal;        break;
438     case If::neq: l = lir_cond_notEqual;     break;
439     case If::lss: l = lir_cond_less;         break;
440     case If::leq: l = lir_cond_lessEqual;    break;
441     case If::geq: l = lir_cond_greaterEqual; break;
442     case If::gtr: l = lir_cond_greater;      break;
443     case If::aeq: l = lir_cond_aboveEqual;   break;
444     case If::beq: l = lir_cond_belowEqual;   break;
445     default: fatal("You must pass valid If::Condition");
446     };
447     return l;
448   }
449 
450 #ifdef __SOFTFP__
451   void do_soft_float_compare(If *x);
452 #endif // __SOFTFP__
453 
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);
457 
458 #ifdef TRACE_HAVE_INTRINSICS
459   void do_ClassIDIntrinsic(Intrinsic* x);
460   void do_getBufferWriter(Intrinsic* x);
461 #endif
462 
463   void do_RuntimeCall(address routine, Intrinsic* x);
464 
465   ciKlass* profile_type(ciMethodData* md, int md_first_offset, int md_offset, intptr_t profiled_k,
466                         Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,
467                         ciKlass* callee_signature_k);
468   void profile_arguments(ProfileCall* x);
469   void profile_parameters(Base* x);
470   void profile_parameters_at_call(ProfileCall* x);
471   LIR_Opr mask_boolean(LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info);
472   LIR_Opr maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info);
473 
474  public:
475   Compilation*  compilation() const              { return _compilation; }
476   FrameMap*     frame_map() const                { return _compilation->frame_map(); }
477   ciMethod*     method() const                   { return _method; }
478   BlockBegin*   block() const                    { return _block; }
479   IRScope*      scope() const                    { return block()->scope(); }
480 
481   int max_virtual_register_number() const        { return _virtual_register_number; }
482 
483   void block_do(BlockBegin* block);
484 
485   // Flags that can be set on vregs
486   enum VregFlag {
487       must_start_in_memory = 0  // needs to be assigned a memory location at beginning, but may then be loaded in a register
488     , callee_saved     = 1    // must be in a callee saved register
489     , byte_reg         = 2    // must be in a byte register
490     , num_vreg_flags
491 
492   };
493 
494   LIRGenerator(Compilation* compilation, ciMethod* method)
495     : _compilation(compilation)
496     , _method(method)
497     , _virtual_register_number(LIR_OprDesc::vreg_base)
498     , _vreg_flags(num_vreg_flags)
499     , _barrier_set(BarrierSet::barrier_set()->barrier_set_c1()) {
500   }
501 
502   // for virtual registers, maps them back to Phi's or Local's
503   Instruction* instruction_for_opr(LIR_Opr opr);
504   Instruction* instruction_for_vreg(int reg_num);
505 
506   void set_vreg_flag   (int vreg_num, VregFlag f);
507   bool is_vreg_flag_set(int vreg_num, VregFlag f);
508   void set_vreg_flag   (LIR_Opr opr,  VregFlag f) { set_vreg_flag(opr->vreg_number(), f); }
509   bool is_vreg_flag_set(LIR_Opr opr,  VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); }
510 
511   // statics
512   static LIR_Opr exceptionOopOpr();
513   static LIR_Opr exceptionPcOpr();
514   static LIR_Opr divInOpr();
515   static LIR_Opr divOutOpr();
516   static LIR_Opr remOutOpr();
517 #ifdef S390
518   // On S390 we can do ldiv, lrem without RT call.
519   static LIR_Opr ldivInOpr();
520   static LIR_Opr ldivOutOpr();
521   static LIR_Opr lremOutOpr();
522 #endif
523   static LIR_Opr shiftCountOpr();
524   LIR_Opr syncLockOpr();
525   LIR_Opr syncTempOpr();
526   LIR_Opr atomicLockOpr();
527 
528   // returns a register suitable for saving the thread in a
529   // call_runtime_leaf if one is needed.
530   LIR_Opr getThreadTemp();
531 
532   // visitor functionality
533   virtual void do_Phi            (Phi*             x);
534   virtual void do_Local          (Local*           x);
535   virtual void do_Constant       (Constant*        x);
536   virtual void do_LoadField      (LoadField*       x);
537   virtual void do_StoreField     (StoreField*      x);
538   virtual void do_ArrayLength    (ArrayLength*     x);
539   virtual void do_LoadIndexed    (LoadIndexed*     x);
540   virtual void do_StoreIndexed   (StoreIndexed*    x);
541   virtual void do_NegateOp       (NegateOp*        x);
542   virtual void do_ArithmeticOp   (ArithmeticOp*    x);
543   virtual void do_ShiftOp        (ShiftOp*         x);
544   virtual void do_LogicOp        (LogicOp*         x);
545   virtual void do_CompareOp      (CompareOp*       x);
546   virtual void do_IfOp           (IfOp*            x);
547   virtual void do_Convert        (Convert*         x);
548   virtual void do_NullCheck      (NullCheck*       x);
549   virtual void do_TypeCast       (TypeCast*        x);
550   virtual void do_Invoke         (Invoke*          x);
551   virtual void do_NewInstance    (NewInstance*     x);
552   virtual void do_NewTypeArray   (NewTypeArray*    x);
553   virtual void do_NewObjectArray (NewObjectArray*  x);
554   virtual void do_NewMultiArray  (NewMultiArray*   x);
555   virtual void do_CheckCast      (CheckCast*       x);
556   virtual void do_InstanceOf     (InstanceOf*      x);
557   virtual void do_MonitorEnter   (MonitorEnter*    x);
558   virtual void do_MonitorExit    (MonitorExit*     x);
559   virtual void do_Intrinsic      (Intrinsic*       x);
560   virtual void do_BlockBegin     (BlockBegin*      x);
561   virtual void do_Goto           (Goto*            x);
562   virtual void do_If             (If*              x);
563   virtual void do_IfInstanceOf   (IfInstanceOf*    x);
564   virtual void do_TableSwitch    (TableSwitch*     x);
565   virtual void do_LookupSwitch   (LookupSwitch*    x);
566   virtual void do_Return         (Return*          x);
567   virtual void do_Throw          (Throw*           x);
568   virtual void do_Base           (Base*            x);
569   virtual void do_OsrEntry       (OsrEntry*        x);
570   virtual void do_ExceptionObject(ExceptionObject* x);
571   virtual void do_RoundFP        (RoundFP*         x);
572   virtual void do_UnsafeGetRaw   (UnsafeGetRaw*    x);
573   virtual void do_UnsafePutRaw   (UnsafePutRaw*    x);
574   virtual void do_UnsafeGetObject(UnsafeGetObject* x);
575   virtual void do_UnsafePutObject(UnsafePutObject* x);
576   virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x);
577   virtual void do_ProfileCall    (ProfileCall*     x);
578   virtual void do_ProfileReturnType (ProfileReturnType* x);
579   virtual void do_ProfileInvoke  (ProfileInvoke*   x);
580   virtual void do_RuntimeCall    (RuntimeCall*     x);
581   virtual void do_MemBar         (MemBar*          x);
582   virtual void do_RangeCheckPredicate(RangeCheckPredicate* x);
583 #ifdef ASSERT
584   virtual void do_Assert         (Assert*          x);
585 #endif
586 
587 #ifdef C1_LIRGENERATOR_MD_HPP
588 #include C1_LIRGENERATOR_MD_HPP
589 #endif
590 };
591 
592 
593 class LIRItem: public CompilationResourceObj {
594  private:
595   Value         _value;
596   LIRGenerator* _gen;
597   LIR_Opr       _result;
598   bool          _destroys_register;
599   LIR_Opr       _new_result;
600 
601   LIRGenerator* gen() const { return _gen; }
602 
603  public:
604   LIRItem(Value value, LIRGenerator* gen) {
605     _destroys_register = false;
606     _gen = gen;
607     set_instruction(value);
608   }
609 
610   LIRItem(LIRGenerator* gen) {
611     _destroys_register = false;
612     _gen = gen;
613     _result = LIR_OprFact::illegalOpr;
614     set_instruction(NULL);
615   }
616 
617   void set_instruction(Value value) {
618     _value = value;
619     _result = LIR_OprFact::illegalOpr;
620     if (_value != NULL) {
621       _gen->walk(_value);
622       _result = _value->operand();
623     }
624     _new_result = LIR_OprFact::illegalOpr;
625   }
626 
627   Value value() const          { return _value;          }
628   ValueType* type() const      { return value()->type(); }
629   LIR_Opr result()             {
630     assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()),
631            "shouldn't use set_destroys_register with physical regsiters");
632     if (_destroys_register && _result->is_register()) {
633       if (_new_result->is_illegal()) {
634         _new_result = _gen->new_register(type());
635         gen()->lir()->move(_result, _new_result);
636       }
637       return _new_result;
638     } else {
639       return _result;
640     }
641     return _result;
642   }
643 
644   void set_result(LIR_Opr opr);
645 
646   void load_item();
647   void load_byte_item();
648   void load_nonconstant(S390_ONLY(int bits = 20));
649   // load any values which can't be expressed as part of a single store instruction
650   void load_for_store(BasicType store_type);
651   void load_item_force(LIR_Opr reg);
652 
653   void dont_load_item() {
654     // do nothing
655   }
656 
657   void set_destroys_register() {
658     _destroys_register = true;
659   }
660 
661   bool is_constant() const { return value()->as_Constant() != NULL; }
662   bool is_stack()          { return result()->is_stack(); }
663   bool is_register()       { return result()->is_register(); }
664 
665   ciObject* get_jobject_constant() const;
666   jint      get_jint_constant() const;
667   jlong     get_jlong_constant() const;
668   jfloat    get_jfloat_constant() const;
669   jdouble   get_jdouble_constant() const;
670   jint      get_address_constant() const;
671 };
672 
673 #endif // SHARE_VM_C1_C1_LIRGENERATOR_HPP