1 /*
   2  * Copyright (c) 2005, 2015, 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 "utilities/sizes.hpp"
  32 
  33 // The classes responsible for code emission and register allocation
  34 
  35 
  36 class LIRGenerator;
  37 class LIREmitter;
  38 class Invoke;
  39 class SwitchRange;
  40 class LIRItem;
  41 
  42 define_array(LIRItemArray, LIRItem*)
  43 define_stack(LIRItemList, LIRItemArray)
  44 
  45 class SwitchRange: public CompilationResourceObj {
  46  private:
  47   int _low_key;
  48   int _high_key;
  49   BlockBegin* _sux;
  50  public:
  51   SwitchRange(int start_key, BlockBegin* sux): _low_key(start_key), _high_key(start_key), _sux(sux) {}
  52   void set_high_key(int key) { _high_key = key; }
  53 
  54   int high_key() const { return _high_key; }
  55   int low_key() const { return _low_key; }
  56   BlockBegin* sux() const { return _sux; }
  57 };
  58 
  59 define_array(SwitchRangeArray, SwitchRange*)
  60 define_stack(SwitchRangeList, SwitchRangeArray)
  61 
  62 
  63 class ResolveNode;
  64 
  65 define_array(NodeArray, ResolveNode*);
  66 define_stack(NodeList, NodeArray);
  67 
  68 
  69 // Node objects form a directed graph of LIR_Opr
  70 // Edges between Nodes represent moves from one Node to its destinations
  71 class ResolveNode: public CompilationResourceObj {
  72  private:
  73   LIR_Opr    _operand;       // the source or destinaton
  74   NodeList   _destinations;  // for the operand
  75   bool       _assigned;      // Value assigned to this Node?
  76   bool       _visited;       // Node already visited?
  77   bool       _start_node;    // Start node already visited?
  78 
  79  public:
  80   ResolveNode(LIR_Opr operand)
  81     : _operand(operand)
  82     , _assigned(false)
  83     , _visited(false)
  84     , _start_node(false) {};
  85 
  86   // accessors
  87   LIR_Opr operand() const           { return _operand; }
  88   int no_of_destinations() const    { return _destinations.length(); }
  89   ResolveNode* destination_at(int i)     { return _destinations[i]; }
  90   bool assigned() const             { return _assigned; }
  91   bool visited() const              { return _visited; }
  92   bool start_node() const           { return _start_node; }
  93 
  94   // modifiers
  95   void append(ResolveNode* dest)         { _destinations.append(dest); }
  96   void set_assigned()               { _assigned = true; }
  97   void set_visited()                { _visited = true; }
  98   void set_start_node()             { _start_node = true; }
  99 };
 100 
 101 
 102 // This is shared state to be used by the PhiResolver so the operand
 103 // arrays don't have to be reallocated for reach resolution.
 104 class PhiResolverState: public CompilationResourceObj {
 105   friend class PhiResolver;
 106 
 107  private:
 108   NodeList _virtual_operands; // Nodes where the operand is a virtual register
 109   NodeList _other_operands;   // Nodes where the operand is not a virtual register
 110   NodeList _vreg_table;       // Mapping from virtual register to Node
 111 
 112  public:
 113   PhiResolverState() {}
 114 
 115   void reset(int max_vregs);
 116 };
 117 
 118 
 119 // class used to move value of phi operand to phi function
 120 class PhiResolver: public CompilationResourceObj {
 121  private:
 122   LIRGenerator*     _gen;
 123   PhiResolverState& _state; // temporary state cached by LIRGenerator
 124 
 125   ResolveNode*   _loop;
 126   LIR_Opr _temp;
 127 
 128   // access to shared state arrays
 129   NodeList& virtual_operands() { return _state._virtual_operands; }
 130   NodeList& other_operands()   { return _state._other_operands;   }
 131   NodeList& vreg_table()       { return _state._vreg_table;       }
 132 
 133   ResolveNode* create_node(LIR_Opr opr, bool source);
 134   ResolveNode* source_node(LIR_Opr opr)      { return create_node(opr, true); }
 135   ResolveNode* destination_node(LIR_Opr opr) { return create_node(opr, false); }
 136 
 137   void emit_move(LIR_Opr src, LIR_Opr dest);
 138   void move_to_temp(LIR_Opr src);
 139   void move_temp_to(LIR_Opr dest);
 140   void move(ResolveNode* src, ResolveNode* dest);
 141 
 142   LIRGenerator* gen() {
 143     return _gen;
 144   }
 145 
 146  public:
 147   PhiResolver(LIRGenerator* _lir_gen, int max_vregs);
 148   ~PhiResolver();
 149 
 150   void move(LIR_Opr src, LIR_Opr dest);
 151 };
 152 
 153 
 154 // only the classes below belong in the same file
 155 class LIRGenerator: public InstructionVisitor, public BlockClosure {
 156 
 157  private:
 158   Compilation*  _compilation;
 159   ciMethod*     _method;    // method that we are compiling
 160   PhiResolverState  _resolver_state;
 161   BlockBegin*   _block;
 162   int           _virtual_register_number;
 163   Values        _instruction_for_operand;
 164   BitMap2D      _vreg_flags; // flags which can be set on a per-vreg basis
 165   LIR_List*     _lir;
 166   BarrierSet*   _bs;
 167 
 168   LIRGenerator* gen() {
 169     return this;
 170   }
 171 
 172   void print_if_not_loaded(const NewInstance* new_instance) PRODUCT_RETURN;
 173 
 174 #ifdef ASSERT
 175   LIR_List* lir(const char * file, int line) const {
 176     _lir->set_file_and_line(file, line);
 177     return _lir;
 178   }
 179 #endif
 180   LIR_List* lir() const {
 181     return _lir;
 182   }
 183 
 184   // a simple cache of constants used within a block
 185   GrowableArray<LIR_Const*>       _constants;
 186   LIR_OprList                     _reg_for_constants;
 187   Values                          _unpinned_constants;
 188 
 189   friend class PhiResolver;
 190 
 191   // unified bailout support
 192   void bailout(const char* msg) const            { compilation()->bailout(msg); }
 193   bool bailed_out() const                        { return compilation()->bailed_out(); }
 194 
 195   void block_do_prolog(BlockBegin* block);
 196   void block_do_epilog(BlockBegin* block);
 197 
 198   // register allocation
 199   LIR_Opr rlock(Value instr);                      // lock a free register
 200   LIR_Opr rlock_result(Value instr);
 201   LIR_Opr rlock_result(Value instr, BasicType type);
 202   LIR_Opr rlock_byte(BasicType type);
 203   LIR_Opr rlock_callee_saved(BasicType type);
 204 
 205   // get a constant into a register and get track of what register was used
 206   LIR_Opr load_constant(Constant* x);
 207   LIR_Opr load_constant(LIR_Const* constant);
 208 
 209   // Given an immediate value, return an operand usable in logical ops.
 210   LIR_Opr load_immediate(int x, BasicType type);
 211 
 212   void  set_result(Value x, LIR_Opr opr)           {
 213     assert(opr->is_valid(), "must set to valid value");
 214     assert(x->operand()->is_illegal(), "operand should never change");
 215     assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register");
 216     x->set_operand(opr);
 217     assert(opr == x->operand(), "must be");
 218     if (opr->is_virtual()) {
 219       _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL);
 220     }
 221   }
 222   void  set_no_result(Value x)                     { assert(!x->has_uses(), "can't have use"); x->clear_operand(); }
 223 
 224   friend class LIRItem;
 225 
 226   LIR_Opr round_item(LIR_Opr opr);
 227   LIR_Opr force_to_spill(LIR_Opr value, BasicType t);
 228 
 229   PhiResolverState& resolver_state() { return _resolver_state; }
 230 
 231   void  move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val);
 232   void  move_to_phi(ValueStack* cur_state);
 233 
 234   // code emission
 235   void do_ArithmeticOp_Long   (ArithmeticOp*    x);
 236   void do_ArithmeticOp_Int    (ArithmeticOp*    x);
 237   void do_ArithmeticOp_FPU    (ArithmeticOp*    x);
 238 
 239   // platform dependent
 240   LIR_Opr getThreadPointer();
 241 
 242   void do_RegisterFinalizer(Intrinsic* x);
 243   void do_isInstance(Intrinsic* x);
 244   void do_getClass(Intrinsic* x);
 245   void do_currentThread(Intrinsic* x);
 246   void do_MathIntrinsic(Intrinsic* x);
 247   void do_ArrayCopy(Intrinsic* x);
 248   void do_CompareAndSwap(Intrinsic* x, ValueType* type);
 249   void do_NIOCheckIndex(Intrinsic* x);
 250   void do_FPIntrinsics(Intrinsic* x);
 251   void do_Reference_get(Intrinsic* x);
 252   void do_update_CRC32(Intrinsic* x);
 253 
 254   LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
 255   LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
 256 
 257   // convenience functions
 258   LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info);
 259   LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info);
 260 
 261   // GC Barriers
 262 
 263   // generic interface
 264 
 265   void pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val, bool do_load, bool patch, CodeEmitInfo* info);
 266   void post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
 267 
 268   // specific implementations
 269   // pre barriers
 270 
 271   void G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val,
 272                                          bool do_load, bool patch, CodeEmitInfo* info);
 273 
 274   // post barriers
 275 
 276   void G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
 277   void CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
 278 #ifdef CARDTABLEMODREF_POST_BARRIER_HELPER
 279   void CardTableModRef_post_barrier_helper(LIR_OprDesc* addr, LIR_Const* card_table_base);
 280 #endif
 281 
 282 
 283   static LIR_Opr result_register_for(ValueType* type, bool callee = false);
 284 
 285   ciObject* get_jobject_constant(Value value);
 286 
 287   LIRItemList* invoke_visit_arguments(Invoke* x);
 288   void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list);
 289 
 290   void trace_block_entry(BlockBegin* block);
 291 
 292   // volatile field operations are never patchable because a klass
 293   // must be loaded to know it's volatile which means that the offset
 294   // it always known as well.
 295   void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info);
 296   void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info);
 297 


 298   void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile);
 299   void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile);
 300 
 301   void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args);
 302 
 303   void increment_counter(address counter, BasicType type, int step = 1);
 304   void increment_counter(LIR_Address* addr, int step = 1);
 305 
 306   // is_strictfp is only needed for mul and div (and only generates different code on i486)
 307   void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp, CodeEmitInfo* info = NULL);
 308   // machine dependent.  returns true if it emitted code for the multiply
 309   bool strength_reduce_multiply(LIR_Opr left, int constant, LIR_Opr result, LIR_Opr tmp);
 310 
 311   void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes);
 312 
 313   void klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve = false);
 314 
 315   // this loads the length and compares against the index
 316   void array_range_check          (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info);
 317   // For java.nio.Buffer.checkIndex
 318   void nio_range_check            (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info);
 319 
 320   void arithmetic_op_int  (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp);
 321   void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL);
 322   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);
 323 
 324   void shift_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp);
 325 
 326   void logic_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right);
 327 
 328   void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info);
 329   void monitor_exit  (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no);
 330 
 331   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);
 332 
 333   // machine dependent
 334   void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
 335   void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info);
 336   void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info);
 337 
 338   void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type);
 339 
 340   // returns a LIR_Address to address an array location.  May also
 341   // emit some code as part of address calculation.  If
 342   // needs_card_mark is true then compute the full address for use by
 343   // both the store and the card mark.
 344   LIR_Address* generate_address(LIR_Opr base,
 345                                 LIR_Opr index, int shift,
 346                                 int disp,
 347                                 BasicType type);
 348   LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) {
 349     return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type);
 350   }
 351   LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type, bool needs_card_mark);
 352 
 353   // the helper for generate_address
 354   void add_large_constant(LIR_Opr src, int c, LIR_Opr dest);
 355 
 356   // machine preferences and characteristics
 357   bool can_inline_as_constant(Value i) const;
 358   bool can_inline_as_constant(LIR_Const* c) const;
 359   bool can_store_as_constant(Value i, BasicType type) const;
 360 
 361   LIR_Opr safepoint_poll_register();
 362 
 363   void profile_branch(If* if_instr, If::Condition cond);
 364   void increment_event_counter_impl(CodeEmitInfo* info,
 365                                     ciMethod *method, int frequency,
 366                                     int bci, bool backedge, bool notify);
 367   void increment_event_counter(CodeEmitInfo* info, int bci, bool backedge);
 368   void increment_invocation_counter(CodeEmitInfo *info) {
 369     if (compilation()->count_invocations()) {
 370       increment_event_counter(info, InvocationEntryBci, false);
 371     }
 372   }
 373   void increment_backedge_counter(CodeEmitInfo* info, int bci) {
 374     if (compilation()->count_backedges()) {
 375       increment_event_counter(info, bci, true);
 376     }
 377   }
 378   void decrement_age(CodeEmitInfo* info);
 379   CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false);
 380   CodeEmitInfo* state_for(Instruction* x);
 381 
 382   // allocates a virtual register for this instruction if
 383   // one isn't already allocated.  Only for Phi and Local.
 384   LIR_Opr operand_for_instruction(Instruction *x);
 385 
 386   void set_block(BlockBegin* block)              { _block = block; }
 387 
 388   void block_prolog(BlockBegin* block);
 389   void block_epilog(BlockBegin* block);
 390 
 391   void do_root (Instruction* instr);
 392   void walk    (Instruction* instr);
 393 
 394   void bind_block_entry(BlockBegin* block);
 395   void start_block(BlockBegin* block);
 396 
 397   LIR_Opr new_register(BasicType type);
 398   LIR_Opr new_register(Value value)              { return new_register(as_BasicType(value->type())); }
 399   LIR_Opr new_register(ValueType* type)          { return new_register(as_BasicType(type)); }
 400 
 401   // returns a register suitable for doing pointer math
 402   LIR_Opr new_pointer_register() {
 403 #ifdef _LP64
 404     return new_register(T_LONG);
 405 #else
 406     return new_register(T_INT);
 407 #endif
 408   }
 409 
 410   static LIR_Condition lir_cond(If::Condition cond) {
 411     LIR_Condition l;
 412     switch (cond) {
 413     case If::eql: l = lir_cond_equal;        break;
 414     case If::neq: l = lir_cond_notEqual;     break;
 415     case If::lss: l = lir_cond_less;         break;
 416     case If::leq: l = lir_cond_lessEqual;    break;
 417     case If::geq: l = lir_cond_greaterEqual; break;
 418     case If::gtr: l = lir_cond_greater;      break;
 419     case If::aeq: l = lir_cond_aboveEqual;   break;
 420     case If::beq: l = lir_cond_belowEqual;   break;
 421     };
 422     return l;
 423   }
 424 
 425 #ifdef __SOFTFP__
 426   void do_soft_float_compare(If *x);
 427 #endif // __SOFTFP__
 428 
 429   void init();
 430 
 431   SwitchRangeArray* create_lookup_ranges(TableSwitch* x);
 432   SwitchRangeArray* create_lookup_ranges(LookupSwitch* x);
 433   void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux);
 434 
 435   void do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x);
 436 #ifdef TRACE_HAVE_INTRINSICS
 437   void do_ThreadIDIntrinsic(Intrinsic* x);
 438   void do_ClassIDIntrinsic(Intrinsic* x);
 439 #endif
 440   ciKlass* profile_type(ciMethodData* md, int md_first_offset, int md_offset, intptr_t profiled_k,
 441                         Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k,
 442                         ciKlass* callee_signature_k);
 443   void profile_arguments(ProfileCall* x);
 444   void profile_parameters(Base* x);
 445   void profile_parameters_at_call(ProfileCall* x);
 446 
 447  public:
 448   Compilation*  compilation() const              { return _compilation; }
 449   FrameMap*     frame_map() const                { return _compilation->frame_map(); }
 450   ciMethod*     method() const                   { return _method; }
 451   BlockBegin*   block() const                    { return _block; }
 452   IRScope*      scope() const                    { return block()->scope(); }
 453 
 454   int max_virtual_register_number() const        { return _virtual_register_number; }
 455 
 456   void block_do(BlockBegin* block);
 457 
 458   // Flags that can be set on vregs
 459   enum VregFlag {
 460       must_start_in_memory = 0  // needs to be assigned a memory location at beginning, but may then be loaded in a register
 461     , callee_saved     = 1    // must be in a callee saved register
 462     , byte_reg         = 2    // must be in a byte register
 463     , num_vreg_flags
 464 
 465   };
 466 
 467   LIRGenerator(Compilation* compilation, ciMethod* method)
 468     : _compilation(compilation)
 469     , _method(method)
 470     , _virtual_register_number(LIR_OprDesc::vreg_base)
 471     , _vreg_flags(NULL, 0, num_vreg_flags) {
 472     init();
 473   }
 474 
 475   // for virtual registers, maps them back to Phi's or Local's
 476   Instruction* instruction_for_opr(LIR_Opr opr);
 477   Instruction* instruction_for_vreg(int reg_num);
 478 
 479   void set_vreg_flag   (int vreg_num, VregFlag f);
 480   bool is_vreg_flag_set(int vreg_num, VregFlag f);
 481   void set_vreg_flag   (LIR_Opr opr,  VregFlag f) { set_vreg_flag(opr->vreg_number(), f); }
 482   bool is_vreg_flag_set(LIR_Opr opr,  VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); }
 483 
 484   // statics
 485   static LIR_Opr exceptionOopOpr();
 486   static LIR_Opr exceptionPcOpr();
 487   static LIR_Opr divInOpr();
 488   static LIR_Opr divOutOpr();
 489   static LIR_Opr remOutOpr();
 490   static LIR_Opr shiftCountOpr();
 491   LIR_Opr syncTempOpr();
 492   LIR_Opr atomicLockOpr();
 493 
 494   // returns a register suitable for saving the thread in a
 495   // call_runtime_leaf if one is needed.
 496   LIR_Opr getThreadTemp();
 497 
 498   // visitor functionality
 499   virtual void do_Phi            (Phi*             x);
 500   virtual void do_Local          (Local*           x);
 501   virtual void do_Constant       (Constant*        x);
 502   virtual void do_LoadField      (LoadField*       x);
 503   virtual void do_StoreField     (StoreField*      x);
 504   virtual void do_ArrayLength    (ArrayLength*     x);
 505   virtual void do_LoadIndexed    (LoadIndexed*     x);
 506   virtual void do_StoreIndexed   (StoreIndexed*    x);
 507   virtual void do_NegateOp       (NegateOp*        x);
 508   virtual void do_ArithmeticOp   (ArithmeticOp*    x);
 509   virtual void do_ShiftOp        (ShiftOp*         x);
 510   virtual void do_LogicOp        (LogicOp*         x);
 511   virtual void do_CompareOp      (CompareOp*       x);
 512   virtual void do_IfOp           (IfOp*            x);
 513   virtual void do_Convert        (Convert*         x);
 514   virtual void do_NullCheck      (NullCheck*       x);
 515   virtual void do_TypeCast       (TypeCast*        x);
 516   virtual void do_Invoke         (Invoke*          x);
 517   virtual void do_NewInstance    (NewInstance*     x);
 518   virtual void do_NewTypeArray   (NewTypeArray*    x);
 519   virtual void do_NewObjectArray (NewObjectArray*  x);
 520   virtual void do_NewMultiArray  (NewMultiArray*   x);
 521   virtual void do_CheckCast      (CheckCast*       x);
 522   virtual void do_InstanceOf     (InstanceOf*      x);
 523   virtual void do_MonitorEnter   (MonitorEnter*    x);
 524   virtual void do_MonitorExit    (MonitorExit*     x);
 525   virtual void do_Intrinsic      (Intrinsic*       x);
 526   virtual void do_BlockBegin     (BlockBegin*      x);
 527   virtual void do_Goto           (Goto*            x);
 528   virtual void do_If             (If*              x);
 529   virtual void do_IfInstanceOf   (IfInstanceOf*    x);
 530   virtual void do_TableSwitch    (TableSwitch*     x);
 531   virtual void do_LookupSwitch   (LookupSwitch*    x);
 532   virtual void do_Return         (Return*          x);
 533   virtual void do_Throw          (Throw*           x);
 534   virtual void do_Base           (Base*            x);
 535   virtual void do_OsrEntry       (OsrEntry*        x);
 536   virtual void do_ExceptionObject(ExceptionObject* x);
 537   virtual void do_RoundFP        (RoundFP*         x);
 538   virtual void do_UnsafeGetRaw   (UnsafeGetRaw*    x);
 539   virtual void do_UnsafePutRaw   (UnsafePutRaw*    x);
 540   virtual void do_UnsafeGetObject(UnsafeGetObject* x);
 541   virtual void do_UnsafePutObject(UnsafePutObject* x);
 542   virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x);
 543   virtual void do_ProfileCall    (ProfileCall*     x);
 544   virtual void do_ProfileReturnType (ProfileReturnType* x);
 545   virtual void do_ProfileInvoke  (ProfileInvoke*   x);
 546   virtual void do_RuntimeCall    (RuntimeCall*     x);
 547   virtual void do_MemBar         (MemBar*          x);
 548   virtual void do_RangeCheckPredicate(RangeCheckPredicate* x);
 549 #ifdef ASSERT
 550   virtual void do_Assert         (Assert*          x);
 551 #endif
 552 
 553 #ifdef C1_LIRGENERATOR_MD_HPP
 554 #include C1_LIRGENERATOR_MD_HPP
 555 #endif
 556 };
 557 
 558 
 559 class LIRItem: public CompilationResourceObj {
 560  private:
 561   Value         _value;
 562   LIRGenerator* _gen;
 563   LIR_Opr       _result;
 564   bool          _destroys_register;
 565   LIR_Opr       _new_result;
 566 
 567   LIRGenerator* gen() const { return _gen; }
 568 
 569  public:
 570   LIRItem(Value value, LIRGenerator* gen) {
 571     _destroys_register = false;
 572     _gen = gen;
 573     set_instruction(value);
 574   }
 575 
 576   LIRItem(LIRGenerator* gen) {
 577     _destroys_register = false;
 578     _gen = gen;
 579     _result = LIR_OprFact::illegalOpr;
 580     set_instruction(NULL);
 581   }
 582 
 583   void set_instruction(Value value) {
 584     _value = value;
 585     _result = LIR_OprFact::illegalOpr;
 586     if (_value != NULL) {
 587       _gen->walk(_value);
 588       _result = _value->operand();
 589     }
 590     _new_result = LIR_OprFact::illegalOpr;
 591   }
 592 
 593   Value value() const          { return _value;          }
 594   ValueType* type() const      { return value()->type(); }
 595   LIR_Opr result()             {
 596     assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()),
 597            "shouldn't use set_destroys_register with physical regsiters");
 598     if (_destroys_register && _result->is_register()) {
 599       if (_new_result->is_illegal()) {
 600         _new_result = _gen->new_register(type());
 601         gen()->lir()->move(_result, _new_result);
 602       }
 603       return _new_result;
 604     } else {
 605       return _result;
 606     }
 607     return _result;
 608   }
 609 
 610   void set_result(LIR_Opr opr);
 611 
 612   void load_item();
 613   void load_byte_item();
 614   void load_nonconstant();
 615   // load any values which can't be expressed as part of a single store instruction
 616   void load_for_store(BasicType store_type);
 617   void load_item_force(LIR_Opr reg);
 618 
 619   void dont_load_item() {
 620     // do nothing
 621   }
 622 
 623   void set_destroys_register() {
 624     _destroys_register = true;
 625   }
 626 
 627   bool is_constant() const { return value()->as_Constant() != NULL; }
 628   bool is_stack()          { return result()->is_stack(); }
 629   bool is_register()       { return result()->is_register(); }
 630 
 631   ciObject* get_jobject_constant() const;
 632   jint      get_jint_constant() const;
 633   jlong     get_jlong_constant() const;
 634   jfloat    get_jfloat_constant() const;
 635   jdouble   get_jdouble_constant() const;
 636   jint      get_address_constant() const;
 637 };
 638 
 639 #endif // SHARE_VM_C1_C1_LIRGENERATOR_HPP
--- EOF ---