src/share/vm/c1/c1_LIRGenerator.hpp

changeset 435
a61af66fc99e
child 777
37f87013dfd8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/c1/c1_LIRGenerator.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,577 @@
     1.4 +/*
     1.5 + * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// The classes responsible for code emission and register allocation
    1.29 +
    1.30 +
    1.31 +class LIRGenerator;
    1.32 +class LIREmitter;
    1.33 +class Invoke;
    1.34 +class SwitchRange;
    1.35 +class LIRItem;
    1.36 +
    1.37 +define_array(LIRItemArray, LIRItem*)
    1.38 +define_stack(LIRItemList, LIRItemArray)
    1.39 +
    1.40 +class SwitchRange: public CompilationResourceObj {
    1.41 + private:
    1.42 +  int _low_key;
    1.43 +  int _high_key;
    1.44 +  BlockBegin* _sux;
    1.45 + public:
    1.46 +  SwitchRange(int start_key, BlockBegin* sux): _low_key(start_key), _high_key(start_key), _sux(sux) {}
    1.47 +  void set_high_key(int key) { _high_key = key; }
    1.48 +
    1.49 +  int high_key() const { return _high_key; }
    1.50 +  int low_key() const { return _low_key; }
    1.51 +  BlockBegin* sux() const { return _sux; }
    1.52 +};
    1.53 +
    1.54 +define_array(SwitchRangeArray, SwitchRange*)
    1.55 +define_stack(SwitchRangeList, SwitchRangeArray)
    1.56 +
    1.57 +
    1.58 +class ResolveNode;
    1.59 +
    1.60 +define_array(NodeArray, ResolveNode*);
    1.61 +define_stack(NodeList, NodeArray);
    1.62 +
    1.63 +
    1.64 +// Node objects form a directed graph of LIR_Opr
    1.65 +// Edges between Nodes represent moves from one Node to its destinations
    1.66 +class ResolveNode: public CompilationResourceObj {
    1.67 + private:
    1.68 +  LIR_Opr    _operand;       // the source or destinaton
    1.69 +  NodeList   _destinations;  // for the operand
    1.70 +  bool       _assigned;      // Value assigned to this Node?
    1.71 +  bool       _visited;       // Node already visited?
    1.72 +  bool       _start_node;    // Start node already visited?
    1.73 +
    1.74 + public:
    1.75 +  ResolveNode(LIR_Opr operand)
    1.76 +    : _operand(operand)
    1.77 +    , _assigned(false)
    1.78 +    , _visited(false)
    1.79 +    , _start_node(false) {};
    1.80 +
    1.81 +  // accessors
    1.82 +  LIR_Opr operand() const           { return _operand; }
    1.83 +  int no_of_destinations() const    { return _destinations.length(); }
    1.84 +  ResolveNode* destination_at(int i)     { return _destinations[i]; }
    1.85 +  bool assigned() const             { return _assigned; }
    1.86 +  bool visited() const              { return _visited; }
    1.87 +  bool start_node() const           { return _start_node; }
    1.88 +
    1.89 +  // modifiers
    1.90 +  void append(ResolveNode* dest)         { _destinations.append(dest); }
    1.91 +  void set_assigned()               { _assigned = true; }
    1.92 +  void set_visited()                { _visited = true; }
    1.93 +  void set_start_node()             { _start_node = true; }
    1.94 +};
    1.95 +
    1.96 +
    1.97 +// This is shared state to be used by the PhiResolver so the operand
    1.98 +// arrays don't have to be reallocated for reach resolution.
    1.99 +class PhiResolverState: public CompilationResourceObj {
   1.100 +  friend class PhiResolver;
   1.101 +
   1.102 + private:
   1.103 +  NodeList _virtual_operands; // Nodes where the operand is a virtual register
   1.104 +  NodeList _other_operands;   // Nodes where the operand is not a virtual register
   1.105 +  NodeList _vreg_table;       // Mapping from virtual register to Node
   1.106 +
   1.107 + public:
   1.108 +  PhiResolverState() {}
   1.109 +
   1.110 +  void reset(int max_vregs);
   1.111 +};
   1.112 +
   1.113 +
   1.114 +// class used to move value of phi operand to phi function
   1.115 +class PhiResolver: public CompilationResourceObj {
   1.116 + private:
   1.117 +  LIRGenerator*     _gen;
   1.118 +  PhiResolverState& _state; // temporary state cached by LIRGenerator
   1.119 +
   1.120 +  ResolveNode*   _loop;
   1.121 +  LIR_Opr _temp;
   1.122 +
   1.123 +  // access to shared state arrays
   1.124 +  NodeList& virtual_operands() { return _state._virtual_operands; }
   1.125 +  NodeList& other_operands()   { return _state._other_operands;   }
   1.126 +  NodeList& vreg_table()       { return _state._vreg_table;       }
   1.127 +
   1.128 +  ResolveNode* create_node(LIR_Opr opr, bool source);
   1.129 +  ResolveNode* source_node(LIR_Opr opr)      { return create_node(opr, true); }
   1.130 +  ResolveNode* destination_node(LIR_Opr opr) { return create_node(opr, false); }
   1.131 +
   1.132 +  void emit_move(LIR_Opr src, LIR_Opr dest);
   1.133 +  void move_to_temp(LIR_Opr src);
   1.134 +  void move_temp_to(LIR_Opr dest);
   1.135 +  void move(ResolveNode* src, ResolveNode* dest);
   1.136 +
   1.137 +  LIRGenerator* gen() {
   1.138 +    return _gen;
   1.139 +  }
   1.140 +
   1.141 + public:
   1.142 +  PhiResolver(LIRGenerator* _lir_gen, int max_vregs);
   1.143 +  ~PhiResolver();
   1.144 +
   1.145 +  void move(LIR_Opr src, LIR_Opr dest);
   1.146 +};
   1.147 +
   1.148 +
   1.149 +// only the classes below belong in the same file
   1.150 +class LIRGenerator: public InstructionVisitor, public BlockClosure {
   1.151 + private:
   1.152 +  Compilation*  _compilation;
   1.153 +  ciMethod*     _method;    // method that we are compiling
   1.154 +  PhiResolverState  _resolver_state;
   1.155 +  BlockBegin*   _block;
   1.156 +  int           _virtual_register_number;
   1.157 +  Values        _instruction_for_operand;
   1.158 +  BitMap2D      _vreg_flags; // flags which can be set on a per-vreg basis
   1.159 +  LIR_List*     _lir;
   1.160 +
   1.161 +  LIRGenerator* gen() {
   1.162 +    return this;
   1.163 +  }
   1.164 +
   1.165 +#ifdef ASSERT
   1.166 +  LIR_List* lir(const char * file, int line) const {
   1.167 +    _lir->set_file_and_line(file, line);
   1.168 +    return _lir;
   1.169 +  }
   1.170 +#endif
   1.171 +  LIR_List* lir() const {
   1.172 +    return _lir;
   1.173 +  }
   1.174 +
   1.175 +  // a simple cache of constants used within a block
   1.176 +  GrowableArray<LIR_Const*>       _constants;
   1.177 +  LIR_OprList                     _reg_for_constants;
   1.178 +  Values                          _unpinned_constants;
   1.179 +
   1.180 +  LIR_Const*                      _card_table_base;
   1.181 +
   1.182 +  friend class PhiResolver;
   1.183 +
   1.184 +  // unified bailout support
   1.185 +  void bailout(const char* msg) const            { compilation()->bailout(msg); }
   1.186 +  bool bailed_out() const                        { return compilation()->bailed_out(); }
   1.187 +
   1.188 +  void block_do_prolog(BlockBegin* block);
   1.189 +  void block_do_epilog(BlockBegin* block);
   1.190 +
   1.191 +  // register allocation
   1.192 +  LIR_Opr rlock(Value instr);                      // lock a free register
   1.193 +  LIR_Opr rlock_result(Value instr);
   1.194 +  LIR_Opr rlock_result(Value instr, BasicType type);
   1.195 +  LIR_Opr rlock_byte(BasicType type);
   1.196 +  LIR_Opr rlock_callee_saved(BasicType type);
   1.197 +
   1.198 +  // get a constant into a register and get track of what register was used
   1.199 +  LIR_Opr load_constant(Constant* x);
   1.200 +  LIR_Opr load_constant(LIR_Const* constant);
   1.201 +
   1.202 +  LIR_Const* card_table_base() const { return _card_table_base; }
   1.203 +
   1.204 +  void  set_result(Value x, LIR_Opr opr)           {
   1.205 +    assert(opr->is_valid(), "must set to valid value");
   1.206 +    assert(x->operand()->is_illegal(), "operand should never change");
   1.207 +    assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register");
   1.208 +    x->set_operand(opr);
   1.209 +    assert(opr == x->operand(), "must be");
   1.210 +    if (opr->is_virtual()) {
   1.211 +      _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL);
   1.212 +    }
   1.213 +  }
   1.214 +  void  set_no_result(Value x)                     { assert(!x->has_uses(), "can't have use"); x->clear_operand(); }
   1.215 +
   1.216 +  friend class LIRItem;
   1.217 +
   1.218 +  LIR_Opr round_item(LIR_Opr opr);
   1.219 +  LIR_Opr force_to_spill(LIR_Opr value, BasicType t);
   1.220 +
   1.221 +  void  profile_branch(If* if_instr, If::Condition cond);
   1.222 +
   1.223 +  PhiResolverState& resolver_state() { return _resolver_state; }
   1.224 +
   1.225 +  void  move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val);
   1.226 +  void  move_to_phi(ValueStack* cur_state);
   1.227 +
   1.228 +  // code emission
   1.229 +  void do_ArithmeticOp_Long   (ArithmeticOp*    x);
   1.230 +  void do_ArithmeticOp_Int    (ArithmeticOp*    x);
   1.231 +  void do_ArithmeticOp_FPU    (ArithmeticOp*    x);
   1.232 +
   1.233 +  // platform dependent
   1.234 +  LIR_Opr getThreadPointer();
   1.235 +
   1.236 +  void do_RegisterFinalizer(Intrinsic* x);
   1.237 +  void do_getClass(Intrinsic* x);
   1.238 +  void do_currentThread(Intrinsic* x);
   1.239 +  void do_MathIntrinsic(Intrinsic* x);
   1.240 +  void do_ArrayCopy(Intrinsic* x);
   1.241 +  void do_CompareAndSwap(Intrinsic* x, ValueType* type);
   1.242 +  void do_AttemptUpdate(Intrinsic* x);
   1.243 +  void do_NIOCheckIndex(Intrinsic* x);
   1.244 +  void do_FPIntrinsics(Intrinsic* x);
   1.245 +
   1.246 +  void do_UnsafePrefetch(UnsafePrefetch* x, bool is_store);
   1.247 +
   1.248 +  LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
   1.249 +  LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info);
   1.250 +
   1.251 +  // convenience functions
   1.252 +  LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info);
   1.253 +  LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info);
   1.254 +
   1.255 +  // GC Barriers
   1.256 +
   1.257 +  // generic interface
   1.258 +
   1.259 +  void post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
   1.260 +
   1.261 +  // specific implementations
   1.262 +
   1.263 +  // post barriers
   1.264 +
   1.265 +  void CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val);
   1.266 +
   1.267 +
   1.268 +  static LIR_Opr result_register_for(ValueType* type, bool callee = false);
   1.269 +
   1.270 +  ciObject* get_jobject_constant(Value value);
   1.271 +
   1.272 +  LIRItemList* invoke_visit_arguments(Invoke* x);
   1.273 +  void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list);
   1.274 +
   1.275 +  void trace_block_entry(BlockBegin* block);
   1.276 +
   1.277 +  // volatile field operations are never patchable because a klass
   1.278 +  // must be loaded to know it's volatile which means that the offset
   1.279 +  // it always known as well.
   1.280 +  void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info);
   1.281 +  void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info);
   1.282 +
   1.283 +  void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile);
   1.284 +  void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile);
   1.285 +
   1.286 +  void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args);
   1.287 +
   1.288 +  void increment_counter(address counter, int step = 1);
   1.289 +  void increment_counter(LIR_Address* addr, int step = 1);
   1.290 +
   1.291 +  // increment a counter returning the incremented value
   1.292 +  LIR_Opr increment_and_return_counter(LIR_Opr base, int offset, int increment);
   1.293 +
   1.294 +  // is_strictfp is only needed for mul and div (and only generates different code on i486)
   1.295 +  void arithmetic_op(Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, bool is_strictfp, LIR_Opr tmp, CodeEmitInfo* info = NULL);
   1.296 +  // machine dependent.  returns true if it emitted code for the multiply
   1.297 +  bool strength_reduce_multiply(LIR_Opr left, int constant, LIR_Opr result, LIR_Opr tmp);
   1.298 +
   1.299 +  void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes);
   1.300 +
   1.301 +  void jobject2reg_with_patching(LIR_Opr r, ciObject* obj, CodeEmitInfo* info);
   1.302 +
   1.303 +  // this loads the length and compares against the index
   1.304 +  void array_range_check          (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info);
   1.305 +  // For java.nio.Buffer.checkIndex
   1.306 +  void nio_range_check            (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info);
   1.307 +
   1.308 +  void arithmetic_op_int  (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp);
   1.309 +  void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL);
   1.310 +  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);
   1.311 +
   1.312 +  void shift_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp);
   1.313 +
   1.314 +  void logic_op   (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right);
   1.315 +
   1.316 +  void monitor_enter (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no, CodeEmitInfo* info_for_exception, CodeEmitInfo* info);
   1.317 +  void monitor_exit  (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, int monitor_no);
   1.318 +
   1.319 +  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);
   1.320 +
   1.321 +  // machine dependent
   1.322 +  void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info);
   1.323 +  void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info);
   1.324 +  void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info);
   1.325 +
   1.326 +  void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type);
   1.327 +
   1.328 +  // returns a LIR_Address to address an array location.  May also
   1.329 +  // emit some code as part of address calculation.  If
   1.330 +  // needs_card_mark is true then compute the full address for use by
   1.331 +  // both the store and the card mark.
   1.332 +  LIR_Address* generate_address(LIR_Opr base,
   1.333 +                                LIR_Opr index, int shift,
   1.334 +                                int disp,
   1.335 +                                BasicType type);
   1.336 +  LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) {
   1.337 +    return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type);
   1.338 +  }
   1.339 +  LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type, bool needs_card_mark);
   1.340 +
   1.341 +  // machine preferences and characteristics
   1.342 +  bool can_inline_as_constant(Value i) const;
   1.343 +  bool can_inline_as_constant(LIR_Const* c) const;
   1.344 +  bool can_store_as_constant(Value i, BasicType type) const;
   1.345 +
   1.346 +  LIR_Opr safepoint_poll_register();
   1.347 +  void increment_invocation_counter(CodeEmitInfo* info, bool backedge = false);
   1.348 +  void increment_backedge_counter(CodeEmitInfo* info) {
   1.349 +    increment_invocation_counter(info, true);
   1.350 +  }
   1.351 +
   1.352 +  CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false);
   1.353 +  CodeEmitInfo* state_for(Instruction* x);
   1.354 +
   1.355 +  // allocates a virtual register for this instruction if
   1.356 +  // one isn't already allocated.  Only for Phi and Local.
   1.357 +  LIR_Opr operand_for_instruction(Instruction *x);
   1.358 +
   1.359 +  void set_block(BlockBegin* block)              { _block = block; }
   1.360 +
   1.361 +  void block_prolog(BlockBegin* block);
   1.362 +  void block_epilog(BlockBegin* block);
   1.363 +
   1.364 +  void do_root (Instruction* instr);
   1.365 +  void walk    (Instruction* instr);
   1.366 +
   1.367 +  void bind_block_entry(BlockBegin* block);
   1.368 +  void start_block(BlockBegin* block);
   1.369 +
   1.370 +  LIR_Opr new_register(BasicType type);
   1.371 +  LIR_Opr new_register(Value value)              { return new_register(as_BasicType(value->type())); }
   1.372 +  LIR_Opr new_register(ValueType* type)          { return new_register(as_BasicType(type)); }
   1.373 +
   1.374 +  // returns a register suitable for doing pointer math
   1.375 +  LIR_Opr new_pointer_register() {
   1.376 +#ifdef _LP64
   1.377 +    return new_register(T_LONG);
   1.378 +#else
   1.379 +    return new_register(T_INT);
   1.380 +#endif
   1.381 +  }
   1.382 +
   1.383 +  static LIR_Condition lir_cond(If::Condition cond) {
   1.384 +    LIR_Condition l;
   1.385 +    switch (cond) {
   1.386 +    case If::eql: l = lir_cond_equal;        break;
   1.387 +    case If::neq: l = lir_cond_notEqual;     break;
   1.388 +    case If::lss: l = lir_cond_less;         break;
   1.389 +    case If::leq: l = lir_cond_lessEqual;    break;
   1.390 +    case If::geq: l = lir_cond_greaterEqual; break;
   1.391 +    case If::gtr: l = lir_cond_greater;      break;
   1.392 +    };
   1.393 +    return l;
   1.394 +  }
   1.395 +
   1.396 +  void init();
   1.397 +
   1.398 +  SwitchRangeArray* create_lookup_ranges(TableSwitch* x);
   1.399 +  SwitchRangeArray* create_lookup_ranges(LookupSwitch* x);
   1.400 +  void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux);
   1.401 +
   1.402 + public:
   1.403 +  Compilation*  compilation() const              { return _compilation; }
   1.404 +  FrameMap*     frame_map() const                { return _compilation->frame_map(); }
   1.405 +  ciMethod*     method() const                   { return _method; }
   1.406 +  BlockBegin*   block() const                    { return _block; }
   1.407 +  IRScope*      scope() const                    { return block()->scope(); }
   1.408 +
   1.409 +  int max_virtual_register_number() const        { return _virtual_register_number; }
   1.410 +
   1.411 +  void block_do(BlockBegin* block);
   1.412 +
   1.413 +  // Flags that can be set on vregs
   1.414 +  enum VregFlag {
   1.415 +      must_start_in_memory = 0  // needs to be assigned a memory location at beginning, but may then be loaded in a register
   1.416 +    , callee_saved     = 1    // must be in a callee saved register
   1.417 +    , byte_reg         = 2    // must be in a byte register
   1.418 +    , num_vreg_flags
   1.419 +
   1.420 +  };
   1.421 +
   1.422 +  LIRGenerator(Compilation* compilation, ciMethod* method)
   1.423 +    : _compilation(compilation)
   1.424 +    , _method(method)
   1.425 +    , _virtual_register_number(LIR_OprDesc::vreg_base)
   1.426 +    , _vreg_flags(NULL, 0, num_vreg_flags) {
   1.427 +    init();
   1.428 +  }
   1.429 +
   1.430 +  // for virtual registers, maps them back to Phi's or Local's
   1.431 +  Instruction* instruction_for_opr(LIR_Opr opr);
   1.432 +  Instruction* instruction_for_vreg(int reg_num);
   1.433 +
   1.434 +  void set_vreg_flag   (int vreg_num, VregFlag f);
   1.435 +  bool is_vreg_flag_set(int vreg_num, VregFlag f);
   1.436 +  void set_vreg_flag   (LIR_Opr opr,  VregFlag f) { set_vreg_flag(opr->vreg_number(), f); }
   1.437 +  bool is_vreg_flag_set(LIR_Opr opr,  VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); }
   1.438 +
   1.439 +  // statics
   1.440 +  static LIR_Opr exceptionOopOpr();
   1.441 +  static LIR_Opr exceptionPcOpr();
   1.442 +  static LIR_Opr divInOpr();
   1.443 +  static LIR_Opr divOutOpr();
   1.444 +  static LIR_Opr remOutOpr();
   1.445 +  static LIR_Opr shiftCountOpr();
   1.446 +  LIR_Opr syncTempOpr();
   1.447 +
   1.448 +  // returns a register suitable for saving the thread in a
   1.449 +  // call_runtime_leaf if one is needed.
   1.450 +  LIR_Opr getThreadTemp();
   1.451 +
   1.452 +  // visitor functionality
   1.453 +  virtual void do_Phi            (Phi*             x);
   1.454 +  virtual void do_Local          (Local*           x);
   1.455 +  virtual void do_Constant       (Constant*        x);
   1.456 +  virtual void do_LoadField      (LoadField*       x);
   1.457 +  virtual void do_StoreField     (StoreField*      x);
   1.458 +  virtual void do_ArrayLength    (ArrayLength*     x);
   1.459 +  virtual void do_LoadIndexed    (LoadIndexed*     x);
   1.460 +  virtual void do_StoreIndexed   (StoreIndexed*    x);
   1.461 +  virtual void do_NegateOp       (NegateOp*        x);
   1.462 +  virtual void do_ArithmeticOp   (ArithmeticOp*    x);
   1.463 +  virtual void do_ShiftOp        (ShiftOp*         x);
   1.464 +  virtual void do_LogicOp        (LogicOp*         x);
   1.465 +  virtual void do_CompareOp      (CompareOp*       x);
   1.466 +  virtual void do_IfOp           (IfOp*            x);
   1.467 +  virtual void do_Convert        (Convert*         x);
   1.468 +  virtual void do_NullCheck      (NullCheck*       x);
   1.469 +  virtual void do_Invoke         (Invoke*          x);
   1.470 +  virtual void do_NewInstance    (NewInstance*     x);
   1.471 +  virtual void do_NewTypeArray   (NewTypeArray*    x);
   1.472 +  virtual void do_NewObjectArray (NewObjectArray*  x);
   1.473 +  virtual void do_NewMultiArray  (NewMultiArray*   x);
   1.474 +  virtual void do_CheckCast      (CheckCast*       x);
   1.475 +  virtual void do_InstanceOf     (InstanceOf*      x);
   1.476 +  virtual void do_MonitorEnter   (MonitorEnter*    x);
   1.477 +  virtual void do_MonitorExit    (MonitorExit*     x);
   1.478 +  virtual void do_Intrinsic      (Intrinsic*       x);
   1.479 +  virtual void do_BlockBegin     (BlockBegin*      x);
   1.480 +  virtual void do_Goto           (Goto*            x);
   1.481 +  virtual void do_If             (If*              x);
   1.482 +  virtual void do_IfInstanceOf   (IfInstanceOf*    x);
   1.483 +  virtual void do_TableSwitch    (TableSwitch*     x);
   1.484 +  virtual void do_LookupSwitch   (LookupSwitch*    x);
   1.485 +  virtual void do_Return         (Return*          x);
   1.486 +  virtual void do_Throw          (Throw*           x);
   1.487 +  virtual void do_Base           (Base*            x);
   1.488 +  virtual void do_OsrEntry       (OsrEntry*        x);
   1.489 +  virtual void do_ExceptionObject(ExceptionObject* x);
   1.490 +  virtual void do_RoundFP        (RoundFP*         x);
   1.491 +  virtual void do_UnsafeGetRaw   (UnsafeGetRaw*    x);
   1.492 +  virtual void do_UnsafePutRaw   (UnsafePutRaw*    x);
   1.493 +  virtual void do_UnsafeGetObject(UnsafeGetObject* x);
   1.494 +  virtual void do_UnsafePutObject(UnsafePutObject* x);
   1.495 +  virtual void do_UnsafePrefetchRead (UnsafePrefetchRead*  x);
   1.496 +  virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x);
   1.497 +  virtual void do_ProfileCall    (ProfileCall*     x);
   1.498 +  virtual void do_ProfileCounter (ProfileCounter*  x);
   1.499 +};
   1.500 +
   1.501 +
   1.502 +class LIRItem: public CompilationResourceObj {
   1.503 + private:
   1.504 +  Value         _value;
   1.505 +  LIRGenerator* _gen;
   1.506 +  LIR_Opr       _result;
   1.507 +  bool          _destroys_register;
   1.508 +  LIR_Opr       _new_result;
   1.509 +
   1.510 +  LIRGenerator* gen() const { return _gen; }
   1.511 +
   1.512 + public:
   1.513 +  LIRItem(Value value, LIRGenerator* gen) {
   1.514 +    _destroys_register = false;
   1.515 +    _gen = gen;
   1.516 +    set_instruction(value);
   1.517 +  }
   1.518 +
   1.519 +  LIRItem(LIRGenerator* gen) {
   1.520 +    _destroys_register = false;
   1.521 +    _gen = gen;
   1.522 +    _result = LIR_OprFact::illegalOpr;
   1.523 +    set_instruction(NULL);
   1.524 +  }
   1.525 +
   1.526 +  void set_instruction(Value value) {
   1.527 +    _value = value;
   1.528 +    _result = LIR_OprFact::illegalOpr;
   1.529 +    if (_value != NULL) {
   1.530 +      _gen->walk(_value);
   1.531 +      _result = _value->operand();
   1.532 +    }
   1.533 +    _new_result = LIR_OprFact::illegalOpr;
   1.534 +  }
   1.535 +
   1.536 +  Value value() const          { return _value;          }
   1.537 +  ValueType* type() const      { return value()->type(); }
   1.538 +  LIR_Opr result()             {
   1.539 +    assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()),
   1.540 +           "shouldn't use set_destroys_register with physical regsiters");
   1.541 +    if (_destroys_register && _result->is_register()) {
   1.542 +      if (_new_result->is_illegal()) {
   1.543 +        _new_result = _gen->new_register(type());
   1.544 +        gen()->lir()->move(_result, _new_result);
   1.545 +      }
   1.546 +      return _new_result;
   1.547 +    } else {
   1.548 +      return _result;
   1.549 +    }
   1.550 +    return _result;
   1.551 +  }
   1.552 +
   1.553 +  void set_result(LIR_Opr opr);
   1.554 +
   1.555 +  void load_item();
   1.556 +  void load_byte_item();
   1.557 +  void load_nonconstant();
   1.558 +  // load any values which can't be expressed as part of a single store instruction
   1.559 +  void load_for_store(BasicType store_type);
   1.560 +  void load_item_force(LIR_Opr reg);
   1.561 +
   1.562 +  void dont_load_item() {
   1.563 +    // do nothing
   1.564 +  }
   1.565 +
   1.566 +  void set_destroys_register() {
   1.567 +    _destroys_register = true;
   1.568 +  }
   1.569 +
   1.570 +  bool is_constant() const { return value()->as_Constant() != NULL; }
   1.571 +  bool is_stack()          { return result()->is_stack(); }
   1.572 +  bool is_register()       { return result()->is_register(); }
   1.573 +
   1.574 +  ciObject* get_jobject_constant() const;
   1.575 +  jint      get_jint_constant() const;
   1.576 +  jlong     get_jlong_constant() const;
   1.577 +  jfloat    get_jfloat_constant() const;
   1.578 +  jdouble   get_jdouble_constant() const;
   1.579 +  jint      get_address_constant() const;
   1.580 +};

mercurial