src/share/vm/c1/c1_LIRGenerator.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial