1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)c1_LIRGenerator.hpp  1.14 07/06/18 14:25:25 JVM"
   3 #endif
   4 /*
   5  * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 // The classes responsible for code emission and register allocation
  29 
  30 
  31 class LIRGenerator;
  32 class LIREmitter;
  33 class Invoke;
  34 class SwitchRange;
  35 class LIRItem;
  36 
  37 define_array(LIRItemArray, LIRItem*)
  38 define_stack(LIRItemList, LIRItemArray)
  39 
  40 class SwitchRange: public CompilationResourceObj {
  41  private:
  42   int _low_key;
  43   int _high_key;
  44   BlockBegin* _sux;
  45  public:
  46   SwitchRange(int start_key, BlockBegin* sux): _low_key(start_key), _high_key(start_key), _sux(sux) {}
  47   void set_high_key(int key) { _high_key = key; }
  48 
  49   int high_key() const { return _high_key; }
  50   int low_key() const { return _low_key; }
  51   BlockBegin* sux() const { return _sux; }
  52 };
  53 
  54 define_array(SwitchRangeArray, SwitchRange*)
  55 define_stack(SwitchRangeList, SwitchRangeArray)
  56 
  57 
  58 class ResolveNode;
  59 
  60 define_array(NodeArray, ResolveNode*);
  61 define_stack(NodeList, NodeArray);
  62 
  63 
  64 // Node objects form a directed graph of LIR_Opr
  65 // Edges between Nodes represent moves from one Node to its destinations
  66 class ResolveNode: public CompilationResourceObj {
  67  private:
  68   LIR_Opr    _operand;       // the source or destinaton
  69   NodeList   _destinations;  // for the operand
  70   bool       _assigned;      // Value assigned to this Node?
  71   bool       _visited;       // Node already visited?
  72   bool       _start_node;    // Start node already visited?
  73   
  74  public:
  75   ResolveNode(LIR_Opr operand) 
  76     : _operand(operand)
  77     , _assigned(false)
  78     , _visited(false)
  79     , _start_node(false) {};
  80 
  81   // accessors
  82   LIR_Opr operand() const           { return _operand; }
  83   int no_of_destinations() const    { return _destinations.length(); }
  84   ResolveNode* destination_at(int i)     { return _destinations[i]; } 
  85   bool assigned() const             { return _assigned; }
  86   bool visited() const              { return _visited; }
  87   bool start_node() const           { return _start_node; }
  88 
  89   // modifiers
  90   void append(ResolveNode* dest)         { _destinations.append(dest); }
  91   void set_assigned()               { _assigned = true; }
  92   void set_visited()                { _visited = true; }
  93   void set_start_node()             { _start_node = true; }
  94 };
  95 
  96 
  97 // This is shared state to be used by the PhiResolver so the operand
  98 // arrays don't have to be reallocated for reach resolution.
  99 class PhiResolverState: public CompilationResourceObj {
 100   friend class PhiResolver;
 101 
 102  private:
 103   NodeList _virtual_operands; // Nodes where the operand is a virtual register
 104   NodeList _other_operands;   // Nodes where the operand is not a virtual register
 105   NodeList _vreg_table;       // Mapping from virtual register to Node
 106 
 107  public:
 108   PhiResolverState() {}
 109 
 110   void reset(int max_vregs);
 111 };
 112 
 113 
 114 // class used to move value of phi operand to phi function
 115 class PhiResolver: public CompilationResourceObj {
 116  private:
 117   LIRGenerator*     _gen;
 118   PhiResolverState& _state; // temporary state cached by LIRGenerator
 119 
 120   ResolveNode*   _loop;
 121   LIR_Opr _temp;
 122 
 123   // access to shared state arrays
 124   NodeList& virtual_operands() { return _state._virtual_operands; }
 125   NodeList& other_operands()   { return _state._other_operands;   }
 126   NodeList& vreg_table()       { return _state._vreg_table;       }
 127 
 128   ResolveNode* create_node(LIR_Opr opr, bool source);
 129   ResolveNode* source_node(LIR_Opr opr)      { return create_node(opr, true); }
 130   ResolveNode* destination_node(LIR_Opr opr) { return create_node(opr, false); }
 131 
 132   void emit_move(LIR_Opr src, LIR_Opr dest);
 133   void move_to_temp(LIR_Opr src);
 134   void move_temp_to(LIR_Opr dest);
 135   void move(ResolveNode* src, ResolveNode* dest);
 136 
 137   LIRGenerator* gen() {
 138     return _gen;
 139   }
 140 
 141  public:
 142   PhiResolver(LIRGenerator* _lir_gen, int max_vregs);
 143   ~PhiResolver();
 144 
 145   void move(LIR_Opr src, LIR_Opr dest);
 146 };
 147 
 148 
 149 // only the classes below belong in the same file
 150 class LIRGenerator: public InstructionVisitor, public BlockClosure {
 151 
 152  private:
 153   Compilation*  _compilation;
 154   ciMethod*     _method;    // method that we are compiling
 155   PhiResolverState  _resolver_state;
 156   BlockBegin*   _block;
 157   int           _virtual_register_number;
 158   Values        _instruction_for_operand;
 159   BitMap2D      _vreg_flags; // flags which can be set on a per-vreg basis
 160   LIR_List*     _lir;
 161   BarrierSet*   _bs;
 162 
 163   LIRGenerator* gen() {
 164     return this;
 165   }
 166 
 167 #ifdef ASSERT
 168   LIR_List* lir(const char * file, int line) const {
 169     _lir->set_file_and_line(file, line);
 170     return _lir;
 171   }
 172 #endif
 173   LIR_List* lir() const {
 174     return _lir;
 175   }  
 176 
 177   // a simple cache of constants used within a block
 178   GrowableArray<LIR_Const*>       _constants;
 179   LIR_OprList                     _reg_for_constants;
 180   Values                          _unpinned_constants;
 181 
 182   friend class PhiResolver;
 183 
 184   // unified bailout support
 185   void bailout(const char* msg) const            { compilation()->bailout(msg); }
 186   bool bailed_out() const                        { return compilation()->bailed_out(); }
 187 
 188   void block_do_prolog(BlockBegin* block);
 189   void block_do_epilog(BlockBegin* block);
 190 
 191   // register allocation
 192   LIR_Opr rlock(Value instr);                      // lock a free register
 193   LIR_Opr rlock_result(Value instr);
 194   LIR_Opr rlock_result(Value instr, BasicType type);
 195   LIR_Opr rlock_byte(BasicType type);
 196   LIR_Opr rlock_callee_saved(BasicType type);
 197 
 198   // get a constant into a register and get track of what register was used
 199   LIR_Opr load_constant(Constant* x);
 200   LIR_Opr load_constant(LIR_Const* constant);
 201 
 202   void  set_result(Value x, LIR_Opr opr)           {
 203     assert(opr->is_valid(), "must set to valid value");
 204     assert(x->operand()->is_illegal(), "operand should never change");
 205     assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register");
 206     x->set_operand(opr);
 207     assert(opr == x->operand(), "must be");
 208     if (opr->is_virtual()) {
 209       _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL);
 210     }
 211   }
 212   void  set_no_result(Value x)                     { assert(!x->has_uses(), "can't have use"); x->clear_operand(); }
 213 
 214   friend class LIRItem;
 215 
 216   LIR_Opr round_item(LIR_Opr opr);
 217   LIR_Opr force_to_spill(LIR_Opr value, BasicType t);
 218 
 219   void  profile_branch(If* if_instr, If::Condition cond);
 220 
 221   PhiResolverState& resolver_state() { return _resolver_state; }
 222 
 223   void  move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val);
 224   void  move_to_phi(ValueStack* cur_state);
 225 
 226   // code emission
 227   void do_ArithmeticOp_Long   (ArithmeticOp*    x);
 228   void do_ArithmeticOp_Int    (ArithmeticOp*    x);
 229   void do_ArithmeticOp_FPU    (ArithmeticOp*    x);
 230 
 231   // platform dependent
 232   LIR_Opr getThreadPointer();
 233 
 234   void do_RegisterFinalizer(Intrinsic* x);
 235   void do_getClass(Intrinsic* x);
 236   void do_currentThread(Intrinsic* x);
 237   void do_MathIntrinsic(Intrinsic* x);
 238   void do_ArrayCopy(Intrinsic* x);
 239   void do_CompareAndSwap(Intrinsic* x, ValueType* type);
 240   void do_AttemptUpdate(Intrinsic* x);
 241   void do_NIOCheckIndex(Intrinsic* x);
 242   void do_FPIntrinsics(Intrinsic* x);
 243 
 244   void do_UnsafePrefetch(UnsafePrefetch* x, bool is_store);
 245 
 246   LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
 247   LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
 248 
 249   // convenience functions
 250   LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info);
 251   LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info);
 252 
 253   // GC Barriers
 254 
 255   // generic interface
 256 
 257   void pre_barrier(LIR_Opr addr_opr, bool patch,  CodeEmitInfo* info);
 258   void post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
 259 
 260   // specific implementations
 261   // pre barriers
 262 
 263   void G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, bool patch,  CodeEmitInfo* info);
 264 
 265   // post barriers
 266 
 267   void G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
 268   void CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
 269 
 270 
 271   static LIR_Opr result_register_for(ValueType* type, bool callee = false);
 272 
 273   ciObject* get_jobject_constant(Value value);
 274 
 275   LIRItemList* invoke_visit_arguments(Invoke* x);
 276   void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list);
 277 
 278   void trace_block_entry(BlockBegin* block);
 279 
 280   // volatile field operations are never patchable because a klass
 281   // must be loaded to know it's volatile which means that the offset
 282   // it always known as well.
 283   void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info);
 284   void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info);
 285 
 286   void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile);
 287   void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile);
 288 
 289   void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args);
 290 
 291   void increment_counter(address counter, int step = 1);
 292   void increment_counter(LIR_Address* addr, int step = 1);
 293 
 294   // increment a counter returning the incremented value
 295   LIR_Opr increment_and_return_counter(LIR_Opr base, int offset, int increment);
 296 
 297   // is_strictfp is only needed for mul and div (and only generates different code on i486)
 298   void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp, CodeEmitInfo* info = NULL);
 299   // machine dependent.  returns true if it emitted code for the multiply
 300   bool strength_reduce_multiply(LIR_Opr left, int constant, LIR_Opr result, LIR_Opr tmp);
 301 
 302   void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes);
 303 
 304   void jobject2reg_with_patching(LIR_Opr r, ciObject* obj, CodeEmitInfo* info);
 305 
 306   // this loads the length and compares against the index
 307   void array_range_check          (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info);
 308   // For java.nio.Buffer.checkIndex
 309   void nio_range_check            (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info);
 310 
 311   void arithmetic_op_int  (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp);
 312   void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL);
 313   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);
 314 
 315   void shift_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp);
 316 
 317   void logic_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right);
 318 
 319   void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info);
 320   void monitor_exit  (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, int monitor_no);
 321 
 322   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);
 323 
 324   // machine dependent
 325   void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
 326   void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info);
 327   void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info);
 328 
 329   void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type);
 330 
 331   // returns a LIR_Address to address an array location.  May also
 332   // emit some code as part of address calculation.  If
 333   // needs_card_mark is true then compute the full address for use by
 334   // both the store and the card mark.
 335   LIR_Address* generate_address(LIR_Opr base,
 336                                 LIR_Opr index, int shift,
 337                                 int disp,
 338                                 BasicType type);
 339   LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) {
 340     return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type);
 341   }
 342   LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type, bool needs_card_mark);
 343 
 344   // machine preferences and characteristics
 345   bool can_inline_as_constant(Value i) const;
 346   bool can_inline_as_constant(LIR_Const* c) const;
 347   bool can_store_as_constant(Value i, BasicType type) const;
 348 
 349   LIR_Opr safepoint_poll_register();
 350   void increment_invocation_counter(CodeEmitInfo* info, bool backedge = false);
 351   void increment_backedge_counter(CodeEmitInfo* info) {
 352     increment_invocation_counter(info, true);
 353   }
 354 
 355   CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false);
 356   CodeEmitInfo* state_for(Instruction* x);
 357 
 358   // allocates a virtual register for this instruction if
 359   // one isn't already allocated.  Only for Phi and Local.
 360   LIR_Opr operand_for_instruction(Instruction *x);
 361 
 362   void set_block(BlockBegin* block)              { _block = block; }
 363 
 364   void block_prolog(BlockBegin* block);
 365   void block_epilog(BlockBegin* block);
 366 
 367   void do_root (Instruction* instr);
 368   void walk    (Instruction* instr);
 369 
 370   void bind_block_entry(BlockBegin* block);
 371   void start_block(BlockBegin* block);
 372 
 373   LIR_Opr new_register(BasicType type);
 374   LIR_Opr new_register(Value value)              { return new_register(as_BasicType(value->type())); }
 375   LIR_Opr new_register(ValueType* type)          { return new_register(as_BasicType(type)); }
 376 
 377   // returns a register suitable for doing pointer math
 378   LIR_Opr new_pointer_register() {
 379 #ifdef _LP64
 380     return new_register(T_LONG);
 381 #else
 382     return new_register(T_INT);
 383 #endif
 384   }
 385 
 386   static LIR_Condition lir_cond(If::Condition cond) {
 387     LIR_Condition l;
 388     switch (cond) {
 389     case If::eql: l = lir_cond_equal;        break;
 390     case If::neq: l = lir_cond_notEqual;     break;
 391     case If::lss: l = lir_cond_less;         break;
 392     case If::leq: l = lir_cond_lessEqual;    break;
 393     case If::geq: l = lir_cond_greaterEqual; break;
 394     case If::gtr: l = lir_cond_greater;      break;
 395     };
 396     return l;
 397   }
 398 
 399   void init();
 400 
 401   SwitchRangeArray* create_lookup_ranges(TableSwitch* x);
 402   SwitchRangeArray* create_lookup_ranges(LookupSwitch* x);
 403   void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux);
 404 
 405  public:
 406   Compilation*  compilation() const              { return _compilation; }
 407   FrameMap*     frame_map() const                { return _compilation->frame_map(); }
 408   ciMethod*     method() const                   { return _method; }
 409   BlockBegin*   block() const                    { return _block; }
 410   IRScope*      scope() const                    { return block()->scope(); }
 411 
 412   int max_virtual_register_number() const        { return _virtual_register_number; }
 413 
 414   void block_do(BlockBegin* block);
 415 
 416   // Flags that can be set on vregs
 417   enum VregFlag {
 418       must_start_in_memory = 0  // needs to be assigned a memory location at beginning, but may then be loaded in a register
 419     , callee_saved     = 1    // must be in a callee saved register
 420     , byte_reg         = 2    // must be in a byte register
 421     , num_vreg_flags
 422 
 423   };
 424 
 425   LIRGenerator(Compilation* compilation, ciMethod* method)
 426     : _compilation(compilation)
 427     , _method(method)
 428     , _virtual_register_number(LIR_OprDesc::vreg_base)
 429     , _vreg_flags(NULL, 0, num_vreg_flags) {
 430     init();
 431   }
 432 
 433   // for virtual registers, maps them back to Phi's or Local's
 434   Instruction* instruction_for_opr(LIR_Opr opr);
 435   Instruction* instruction_for_vreg(int reg_num);
 436 
 437   void set_vreg_flag   (int vreg_num, VregFlag f);
 438   bool is_vreg_flag_set(int vreg_num, VregFlag f);
 439   void set_vreg_flag   (LIR_Opr opr,  VregFlag f) { set_vreg_flag(opr->vreg_number(), f); }
 440   bool is_vreg_flag_set(LIR_Opr opr,  VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); }
 441 
 442   // statics
 443   static LIR_Opr exceptionOopOpr();
 444   static LIR_Opr exceptionPcOpr();
 445   static LIR_Opr divInOpr();
 446   static LIR_Opr divOutOpr();
 447   static LIR_Opr remOutOpr();
 448   static LIR_Opr shiftCountOpr();
 449   LIR_Opr syncTempOpr();
 450 
 451   // returns a register suitable for saving the thread in a
 452   // call_runtime_leaf if one is needed.
 453   LIR_Opr getThreadTemp();
 454 
 455   // visitor functionality
 456   virtual void do_Phi            (Phi*             x);
 457   virtual void do_Local          (Local*           x);
 458   virtual void do_Constant       (Constant*        x);
 459   virtual void do_LoadField      (LoadField*       x);
 460   virtual void do_StoreField     (StoreField*      x);
 461   virtual void do_ArrayLength    (ArrayLength*     x);
 462   virtual void do_LoadIndexed    (LoadIndexed*     x);
 463   virtual void do_StoreIndexed   (StoreIndexed*    x);
 464   virtual void do_NegateOp       (NegateOp*        x);
 465   virtual void do_ArithmeticOp   (ArithmeticOp*    x);
 466   virtual void do_ShiftOp        (ShiftOp*         x);
 467   virtual void do_LogicOp        (LogicOp*         x);
 468   virtual void do_CompareOp      (CompareOp*       x);
 469   virtual void do_IfOp           (IfOp*            x);
 470   virtual void do_Convert        (Convert*         x);
 471   virtual void do_NullCheck      (NullCheck*       x);
 472   virtual void do_Invoke         (Invoke*          x);
 473   virtual void do_NewInstance    (NewInstance*     x);
 474   virtual void do_NewTypeArray   (NewTypeArray*    x);
 475   virtual void do_NewObjectArray (NewObjectArray*  x);
 476   virtual void do_NewMultiArray  (NewMultiArray*   x);
 477   virtual void do_CheckCast      (CheckCast*       x);
 478   virtual void do_InstanceOf     (InstanceOf*      x);
 479   virtual void do_MonitorEnter   (MonitorEnter*    x);
 480   virtual void do_MonitorExit    (MonitorExit*     x);
 481   virtual void do_Intrinsic      (Intrinsic*       x);
 482   virtual void do_BlockBegin     (BlockBegin*      x);
 483   virtual void do_Goto           (Goto*            x);
 484   virtual void do_If             (If*              x);
 485   virtual void do_IfInstanceOf   (IfInstanceOf*    x);
 486   virtual void do_TableSwitch    (TableSwitch*     x);
 487   virtual void do_LookupSwitch   (LookupSwitch*    x);
 488   virtual void do_Return         (Return*          x);
 489   virtual void do_Throw          (Throw*           x);
 490   virtual void do_Base           (Base*            x);
 491   virtual void do_OsrEntry       (OsrEntry*        x);
 492   virtual void do_ExceptionObject(ExceptionObject* x);
 493   virtual void do_RoundFP        (RoundFP*         x);
 494   virtual void do_UnsafeGetRaw   (UnsafeGetRaw*    x);
 495   virtual void do_UnsafePutRaw   (UnsafePutRaw*    x);
 496   virtual void do_UnsafeGetObject(UnsafeGetObject* x);
 497   virtual void do_UnsafePutObject(UnsafePutObject* x);
 498   virtual void do_UnsafePrefetchRead (UnsafePrefetchRead*  x);
 499   virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x);
 500   virtual void do_ProfileCall    (ProfileCall*     x);
 501   virtual void do_ProfileCounter (ProfileCounter*  x);
 502 };
 503 
 504 
 505 class LIRItem: public CompilationResourceObj {
 506  private:
 507   Value         _value;
 508   LIRGenerator* _gen;
 509   LIR_Opr       _result;
 510   bool          _destroys_register;
 511   LIR_Opr       _new_result;
 512 
 513   LIRGenerator* gen() const { return _gen; }
 514 
 515  public:
 516   LIRItem(Value value, LIRGenerator* gen) {
 517     _destroys_register = false;
 518     _gen = gen;
 519     set_instruction(value);
 520   }
 521 
 522   LIRItem(LIRGenerator* gen) {
 523     _destroys_register = false;
 524     _gen = gen;
 525     _result = LIR_OprFact::illegalOpr;
 526     set_instruction(NULL);
 527   }
 528 
 529   void set_instruction(Value value) {
 530     _value = value;
 531     _result = LIR_OprFact::illegalOpr;
 532     if (_value != NULL) {
 533       _gen->walk(_value);
 534       _result = _value->operand();
 535     }
 536     _new_result = LIR_OprFact::illegalOpr;
 537   }
 538 
 539   Value value() const          { return _value;          }
 540   ValueType* type() const      { return value()->type(); }
 541   LIR_Opr result()             {
 542     assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()),
 543            "shouldn't use set_destroys_register with physical regsiters");
 544     if (_destroys_register && _result->is_register()) {
 545       if (_new_result->is_illegal()) {
 546         _new_result = _gen->new_register(type());
 547         gen()->lir()->move(_result, _new_result);
 548       }
 549       return _new_result;
 550     } else {
 551       return _result;
 552     }
 553     return _result;
 554   }
 555 
 556   void set_result(LIR_Opr opr);
 557 
 558   void load_item();
 559   void load_byte_item();
 560   void load_nonconstant();
 561   // load any values which can't be expressed as part of a single store instruction
 562   void load_for_store(BasicType store_type);
 563   void load_item_force(LIR_Opr reg);
 564 
 565   void dont_load_item() {
 566     // do nothing
 567   }
 568 
 569   void set_destroys_register() {
 570     _destroys_register = true;
 571   }
 572 
 573   bool is_constant() const { return value()->as_Constant() != NULL; }
 574   bool is_stack()          { return result()->is_stack(); }
 575   bool is_register()       { return result()->is_register(); }
 576 
 577   ciObject* get_jobject_constant() const;
 578   jint      get_jint_constant() const;
 579   jlong     get_jlong_constant() const;
 580   jfloat    get_jfloat_constant() const;
 581   jdouble   get_jdouble_constant() const;
 582   jint      get_address_constant() const;
 583 };