annotate src/share/vm/c1/c1_LIRGenerator.hpp @ 0:a61af66fc99e

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