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