src/share/vm/c1/c1_LIRGenerator.hpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 8604
04d83ba48607
child 8859
f39c2b3891e2
permissions
-rw-r--r--

Merge

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

mercurial