aoqi@0: /* kevinw@8368: * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@1: /* aoqi@1: * This file has been modified by Loongson Technology in 2015. These aoqi@1: * modifications are Copyright (c) 2015 Loongson Technology, and are made aoqi@1: * available on the same license terms set forth above. aoqi@1: */ aoqi@1: aoqi@0: #ifndef SHARE_VM_C1_C1_LIRGENERATOR_HPP aoqi@0: #define SHARE_VM_C1_C1_LIRGENERATOR_HPP aoqi@0: aoqi@0: #include "c1/c1_Instruction.hpp" aoqi@0: #include "c1/c1_LIR.hpp" aoqi@0: #include "ci/ciMethodData.hpp" aoqi@0: #include "utilities/sizes.hpp" aoqi@0: aoqi@0: // The classes responsible for code emission and register allocation aoqi@0: aoqi@0: aoqi@0: class LIRGenerator; aoqi@0: class LIREmitter; aoqi@0: class Invoke; aoqi@0: class SwitchRange; aoqi@0: class LIRItem; aoqi@0: aoqi@0: define_array(LIRItemArray, LIRItem*) aoqi@0: define_stack(LIRItemList, LIRItemArray) aoqi@0: aoqi@0: class SwitchRange: public CompilationResourceObj { aoqi@0: private: aoqi@0: int _low_key; aoqi@0: int _high_key; aoqi@0: BlockBegin* _sux; aoqi@0: public: aoqi@0: SwitchRange(int start_key, BlockBegin* sux): _low_key(start_key), _high_key(start_key), _sux(sux) {} aoqi@0: void set_high_key(int key) { _high_key = key; } aoqi@0: aoqi@0: int high_key() const { return _high_key; } aoqi@0: int low_key() const { return _low_key; } aoqi@0: BlockBegin* sux() const { return _sux; } aoqi@0: }; aoqi@0: aoqi@0: define_array(SwitchRangeArray, SwitchRange*) aoqi@0: define_stack(SwitchRangeList, SwitchRangeArray) aoqi@0: aoqi@0: aoqi@0: class ResolveNode; aoqi@0: aoqi@0: define_array(NodeArray, ResolveNode*); aoqi@0: define_stack(NodeList, NodeArray); aoqi@0: aoqi@0: aoqi@0: // Node objects form a directed graph of LIR_Opr aoqi@0: // Edges between Nodes represent moves from one Node to its destinations aoqi@0: class ResolveNode: public CompilationResourceObj { aoqi@0: private: aoqi@0: LIR_Opr _operand; // the source or destinaton aoqi@0: NodeList _destinations; // for the operand aoqi@0: bool _assigned; // Value assigned to this Node? aoqi@0: bool _visited; // Node already visited? aoqi@0: bool _start_node; // Start node already visited? aoqi@0: aoqi@0: public: aoqi@0: ResolveNode(LIR_Opr operand) aoqi@0: : _operand(operand) aoqi@0: , _assigned(false) aoqi@0: , _visited(false) aoqi@0: , _start_node(false) {}; aoqi@0: aoqi@0: // accessors aoqi@0: LIR_Opr operand() const { return _operand; } aoqi@0: int no_of_destinations() const { return _destinations.length(); } aoqi@0: ResolveNode* destination_at(int i) { return _destinations[i]; } aoqi@0: bool assigned() const { return _assigned; } aoqi@0: bool visited() const { return _visited; } aoqi@0: bool start_node() const { return _start_node; } aoqi@0: aoqi@0: // modifiers aoqi@0: void append(ResolveNode* dest) { _destinations.append(dest); } aoqi@0: void set_assigned() { _assigned = true; } aoqi@0: void set_visited() { _visited = true; } aoqi@0: void set_start_node() { _start_node = true; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // This is shared state to be used by the PhiResolver so the operand aoqi@0: // arrays don't have to be reallocated for reach resolution. aoqi@0: class PhiResolverState: public CompilationResourceObj { aoqi@0: friend class PhiResolver; aoqi@0: aoqi@0: private: aoqi@0: NodeList _virtual_operands; // Nodes where the operand is a virtual register aoqi@0: NodeList _other_operands; // Nodes where the operand is not a virtual register aoqi@0: NodeList _vreg_table; // Mapping from virtual register to Node aoqi@0: aoqi@0: public: aoqi@0: PhiResolverState() {} aoqi@0: aoqi@0: void reset(int max_vregs); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // class used to move value of phi operand to phi function aoqi@0: class PhiResolver: public CompilationResourceObj { aoqi@0: private: aoqi@0: LIRGenerator* _gen; aoqi@0: PhiResolverState& _state; // temporary state cached by LIRGenerator aoqi@0: aoqi@0: ResolveNode* _loop; aoqi@0: LIR_Opr _temp; aoqi@0: aoqi@0: // access to shared state arrays aoqi@0: NodeList& virtual_operands() { return _state._virtual_operands; } aoqi@0: NodeList& other_operands() { return _state._other_operands; } aoqi@0: NodeList& vreg_table() { return _state._vreg_table; } aoqi@0: aoqi@0: ResolveNode* create_node(LIR_Opr opr, bool source); aoqi@0: ResolveNode* source_node(LIR_Opr opr) { return create_node(opr, true); } aoqi@0: ResolveNode* destination_node(LIR_Opr opr) { return create_node(opr, false); } aoqi@0: aoqi@0: void emit_move(LIR_Opr src, LIR_Opr dest); aoqi@0: void move_to_temp(LIR_Opr src); aoqi@0: void move_temp_to(LIR_Opr dest); aoqi@0: void move(ResolveNode* src, ResolveNode* dest); aoqi@0: aoqi@0: LIRGenerator* gen() { aoqi@0: return _gen; aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: PhiResolver(LIRGenerator* _lir_gen, int max_vregs); aoqi@0: ~PhiResolver(); aoqi@0: aoqi@0: void move(LIR_Opr src, LIR_Opr dest); aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // only the classes below belong in the same file aoqi@0: class LIRGenerator: public InstructionVisitor, public BlockClosure { aoqi@0: aoqi@0: private: aoqi@0: Compilation* _compilation; aoqi@0: ciMethod* _method; // method that we are compiling aoqi@0: PhiResolverState _resolver_state; aoqi@0: BlockBegin* _block; aoqi@0: int _virtual_register_number; aoqi@0: Values _instruction_for_operand; aoqi@0: BitMap2D _vreg_flags; // flags which can be set on a per-vreg basis aoqi@0: LIR_List* _lir; aoqi@0: BarrierSet* _bs; aoqi@0: aoqi@0: LIRGenerator* gen() { aoqi@0: return this; aoqi@0: } aoqi@0: rbackman@7058: void print_if_not_loaded(const NewInstance* new_instance) PRODUCT_RETURN; rbackman@7058: aoqi@0: #ifdef ASSERT aoqi@0: LIR_List* lir(const char * file, int line) const { aoqi@0: _lir->set_file_and_line(file, line); aoqi@0: return _lir; aoqi@0: } aoqi@0: #endif aoqi@0: LIR_List* lir() const { aoqi@0: return _lir; aoqi@0: } aoqi@0: aoqi@0: // a simple cache of constants used within a block aoqi@0: GrowableArray _constants; aoqi@0: LIR_OprList _reg_for_constants; aoqi@0: Values _unpinned_constants; aoqi@0: aoqi@1: #ifdef MIPS64 aoqi@1: LIR_Const* _card_table_base; aoqi@1: #endif aoqi@0: friend class PhiResolver; aoqi@0: aoqi@0: // unified bailout support aoqi@0: void bailout(const char* msg) const { compilation()->bailout(msg); } aoqi@0: bool bailed_out() const { return compilation()->bailed_out(); } aoqi@0: aoqi@0: void block_do_prolog(BlockBegin* block); aoqi@0: void block_do_epilog(BlockBegin* block); aoqi@0: aoqi@0: // register allocation aoqi@0: LIR_Opr rlock(Value instr); // lock a free register aoqi@0: LIR_Opr rlock_result(Value instr); aoqi@0: LIR_Opr rlock_result(Value instr, BasicType type); aoqi@0: LIR_Opr rlock_byte(BasicType type); aoqi@0: LIR_Opr rlock_callee_saved(BasicType type); aoqi@0: aoqi@0: // get a constant into a register and get track of what register was used aoqi@0: LIR_Opr load_constant(Constant* x); aoqi@0: LIR_Opr load_constant(LIR_Const* constant); aoqi@0: aoqi@1: #ifdef MIPS64 aoqi@1: LIR_Const* card_table_base() const { aoqi@1: return _card_table_base; aoqi@1: } aoqi@1: #endif aoqi@0: // Given an immediate value, return an operand usable in logical ops. aoqi@0: LIR_Opr load_immediate(int x, BasicType type); aoqi@0: aoqi@0: void set_result(Value x, LIR_Opr opr) { aoqi@0: assert(opr->is_valid(), "must set to valid value"); aoqi@0: assert(x->operand()->is_illegal(), "operand should never change"); aoqi@0: assert(!opr->is_register() || opr->is_virtual(), "should never set result to a physical register"); aoqi@0: x->set_operand(opr); aoqi@0: assert(opr == x->operand(), "must be"); aoqi@0: if (opr->is_virtual()) { aoqi@0: _instruction_for_operand.at_put_grow(opr->vreg_number(), x, NULL); aoqi@0: } aoqi@0: } aoqi@0: void set_no_result(Value x) { assert(!x->has_uses(), "can't have use"); x->clear_operand(); } aoqi@0: aoqi@0: friend class LIRItem; aoqi@0: aoqi@0: LIR_Opr round_item(LIR_Opr opr); aoqi@0: LIR_Opr force_to_spill(LIR_Opr value, BasicType t); aoqi@0: aoqi@1: #ifdef MIPS64 aoqi@1: void profile_branch(If* if_instr, If::Condition cond, LIR_Opr left, LIR_Opr right); aoqi@1: #endif aoqi@0: PhiResolverState& resolver_state() { return _resolver_state; } aoqi@0: aoqi@0: void move_to_phi(PhiResolver* resolver, Value cur_val, Value sux_val); aoqi@0: void move_to_phi(ValueStack* cur_state); aoqi@0: aoqi@0: // code emission aoqi@0: void do_ArithmeticOp_Long (ArithmeticOp* x); aoqi@0: void do_ArithmeticOp_Int (ArithmeticOp* x); aoqi@0: void do_ArithmeticOp_FPU (ArithmeticOp* x); aoqi@0: aoqi@0: // platform dependent aoqi@0: LIR_Opr getThreadPointer(); aoqi@0: aoqi@0: void do_RegisterFinalizer(Intrinsic* x); aoqi@0: void do_isInstance(Intrinsic* x); aoqi@0: void do_getClass(Intrinsic* x); aoqi@0: void do_currentThread(Intrinsic* x); aoqi@0: void do_MathIntrinsic(Intrinsic* x); aoqi@0: void do_ArrayCopy(Intrinsic* x); aoqi@0: void do_CompareAndSwap(Intrinsic* x, ValueType* type); aoqi@0: void do_NIOCheckIndex(Intrinsic* x); aoqi@0: void do_FPIntrinsics(Intrinsic* x); aoqi@0: void do_Reference_get(Intrinsic* x); aoqi@0: void do_update_CRC32(Intrinsic* x); aoqi@0: aoqi@0: void do_UnsafePrefetch(UnsafePrefetch* x, bool is_store); aoqi@0: aoqi@0: LIR_Opr call_runtime(BasicTypeArray* signature, LIRItemList* args, address entry, ValueType* result_type, CodeEmitInfo* info); aoqi@0: LIR_Opr call_runtime(BasicTypeArray* signature, LIR_OprList* args, address entry, ValueType* result_type, CodeEmitInfo* info); aoqi@0: aoqi@0: // convenience functions aoqi@0: LIR_Opr call_runtime(Value arg1, address entry, ValueType* result_type, CodeEmitInfo* info); aoqi@0: LIR_Opr call_runtime(Value arg1, Value arg2, address entry, ValueType* result_type, CodeEmitInfo* info); aoqi@0: aoqi@0: // GC Barriers aoqi@0: aoqi@0: // generic interface aoqi@0: aoqi@0: void pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val, bool do_load, bool patch, CodeEmitInfo* info); aoqi@0: void post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val); aoqi@0: aoqi@0: // specific implementations aoqi@0: // pre barriers aoqi@0: aoqi@0: void G1SATBCardTableModRef_pre_barrier(LIR_Opr addr_opr, LIR_Opr pre_val, aoqi@0: bool do_load, bool patch, CodeEmitInfo* info); aoqi@0: aoqi@0: // post barriers aoqi@0: aoqi@0: void G1SATBCardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val); aoqi@0: void CardTableModRef_post_barrier(LIR_OprDesc* addr, LIR_OprDesc* new_val); dlong@7598: #ifdef CARDTABLEMODREF_POST_BARRIER_HELPER dlong@7598: void CardTableModRef_post_barrier_helper(LIR_OprDesc* addr, LIR_Const* card_table_base); dlong@7598: #endif aoqi@0: aoqi@0: aoqi@0: static LIR_Opr result_register_for(ValueType* type, bool callee = false); aoqi@0: aoqi@0: ciObject* get_jobject_constant(Value value); aoqi@0: aoqi@0: LIRItemList* invoke_visit_arguments(Invoke* x); aoqi@0: void invoke_load_arguments(Invoke* x, LIRItemList* args, const LIR_OprList* arg_list); aoqi@0: aoqi@0: void trace_block_entry(BlockBegin* block); aoqi@0: aoqi@0: // volatile field operations are never patchable because a klass aoqi@0: // must be loaded to know it's volatile which means that the offset aoqi@0: // it always known as well. aoqi@0: void volatile_field_store(LIR_Opr value, LIR_Address* address, CodeEmitInfo* info); aoqi@0: void volatile_field_load(LIR_Address* address, LIR_Opr result, CodeEmitInfo* info); aoqi@0: aoqi@0: void put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data, BasicType type, bool is_volatile); aoqi@0: void get_Object_unsafe(LIR_Opr dest, LIR_Opr src, LIR_Opr offset, BasicType type, bool is_volatile); aoqi@0: aoqi@0: void arithmetic_call_op (Bytecodes::Code code, LIR_Opr result, LIR_OprList* args); aoqi@0: aoqi@0: void increment_counter(address counter, BasicType type, int step = 1); aoqi@0: void increment_counter(LIR_Address* addr, int step = 1); aoqi@0: aoqi@0: // is_strictfp is only needed for mul and div (and only generates different code on i486) aoqi@0: 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: // machine dependent. returns true if it emitted code for the multiply aoqi@0: bool strength_reduce_multiply(LIR_Opr left, int constant, LIR_Opr result, LIR_Opr tmp); aoqi@0: aoqi@0: void store_stack_parameter (LIR_Opr opr, ByteSize offset_from_sp_in_bytes); aoqi@0: rbackman@7058: void klass2reg_with_patching(LIR_Opr r, ciMetadata* obj, CodeEmitInfo* info, bool need_resolve = false); aoqi@0: aoqi@0: // this loads the length and compares against the index aoqi@0: void array_range_check (LIR_Opr array, LIR_Opr index, CodeEmitInfo* null_check_info, CodeEmitInfo* range_check_info); aoqi@0: // For java.nio.Buffer.checkIndex aoqi@0: void nio_range_check (LIR_Opr buffer, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info); aoqi@0: aoqi@0: void arithmetic_op_int (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, LIR_Opr tmp); aoqi@0: void arithmetic_op_long (Bytecodes::Code code, LIR_Opr result, LIR_Opr left, LIR_Opr right, CodeEmitInfo* info = NULL); aoqi@0: 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: aoqi@0: void shift_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr value, LIR_Opr count, LIR_Opr tmp); aoqi@0: aoqi@0: void logic_op (Bytecodes::Code code, LIR_Opr dst_reg, LIR_Opr left, LIR_Opr right); aoqi@0: aoqi@0: 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: void monitor_exit (LIR_Opr object, LIR_Opr lock, LIR_Opr hdr, LIR_Opr scratch, int monitor_no); roland@6103: aoqi@1: #ifndef MIPS64 rbackman@7058: 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: #else aoqi@1: 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: #endif roland@6103: aoqi@0: // machine dependent aoqi@0: void cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info); aoqi@0: void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info); aoqi@0: void cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, LIR_Opr disp, BasicType type, CodeEmitInfo* info); aoqi@0: aoqi@0: void arraycopy_helper(Intrinsic* x, int* flags, ciArrayKlass** expected_type); aoqi@0: aoqi@0: // returns a LIR_Address to address an array location. May also aoqi@0: // emit some code as part of address calculation. If aoqi@0: // needs_card_mark is true then compute the full address for use by aoqi@0: // both the store and the card mark. aoqi@0: LIR_Address* generate_address(LIR_Opr base, aoqi@0: LIR_Opr index, int shift, aoqi@0: int disp, aoqi@0: BasicType type); aoqi@0: LIR_Address* generate_address(LIR_Opr base, int disp, BasicType type) { aoqi@0: return generate_address(base, LIR_OprFact::illegalOpr, 0, disp, type); aoqi@0: } aoqi@0: LIR_Address* emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type, bool needs_card_mark); aoqi@0: aoqi@1: #ifdef MIPS64 aoqi@1: void write_barrier(LIR_Opr addr); aoqi@1: #endif aoqi@0: // the helper for generate_address aoqi@0: void add_large_constant(LIR_Opr src, int c, LIR_Opr dest); aoqi@0: aoqi@0: // machine preferences and characteristics aoqi@0: bool can_inline_as_constant(Value i) const; aoqi@0: bool can_inline_as_constant(LIR_Const* c) const; aoqi@0: bool can_store_as_constant(Value i, BasicType type) const; aoqi@0: aoqi@0: LIR_Opr safepoint_poll_register(); aoqi@0: aoqi@0: void profile_branch(If* if_instr, If::Condition cond); aoqi@0: void increment_event_counter_impl(CodeEmitInfo* info, aoqi@0: ciMethod *method, int frequency, aoqi@0: int bci, bool backedge, bool notify); aoqi@0: void increment_event_counter(CodeEmitInfo* info, int bci, bool backedge); aoqi@0: void increment_invocation_counter(CodeEmitInfo *info) { aoqi@0: if (compilation()->count_invocations()) { aoqi@0: increment_event_counter(info, InvocationEntryBci, false); aoqi@0: } aoqi@0: } aoqi@0: void increment_backedge_counter(CodeEmitInfo* info, int bci) { aoqi@0: if (compilation()->count_backedges()) { aoqi@0: increment_event_counter(info, bci, true); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: CodeEmitInfo* state_for(Instruction* x, ValueStack* state, bool ignore_xhandler = false); aoqi@0: CodeEmitInfo* state_for(Instruction* x); aoqi@0: aoqi@0: // allocates a virtual register for this instruction if aoqi@0: // one isn't already allocated. Only for Phi and Local. aoqi@0: LIR_Opr operand_for_instruction(Instruction *x); aoqi@0: aoqi@0: void set_block(BlockBegin* block) { _block = block; } aoqi@0: aoqi@0: void block_prolog(BlockBegin* block); aoqi@0: void block_epilog(BlockBegin* block); aoqi@0: aoqi@0: void do_root (Instruction* instr); aoqi@0: void walk (Instruction* instr); aoqi@0: aoqi@0: void bind_block_entry(BlockBegin* block); aoqi@0: void start_block(BlockBegin* block); aoqi@0: aoqi@0: LIR_Opr new_register(BasicType type); aoqi@0: LIR_Opr new_register(Value value) { return new_register(as_BasicType(value->type())); } aoqi@0: LIR_Opr new_register(ValueType* type) { return new_register(as_BasicType(type)); } aoqi@0: aoqi@0: // returns a register suitable for doing pointer math aoqi@0: LIR_Opr new_pointer_register() { aoqi@0: #ifdef _LP64 aoqi@0: return new_register(T_LONG); aoqi@0: #else aoqi@0: return new_register(T_INT); aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: static LIR_Condition lir_cond(If::Condition cond) { csahu@8316: LIR_Condition l = lir_cond_unknown; aoqi@0: switch (cond) { aoqi@0: case If::eql: l = lir_cond_equal; break; aoqi@0: case If::neq: l = lir_cond_notEqual; break; aoqi@0: case If::lss: l = lir_cond_less; break; aoqi@0: case If::leq: l = lir_cond_lessEqual; break; aoqi@0: case If::geq: l = lir_cond_greaterEqual; break; aoqi@0: case If::gtr: l = lir_cond_greater; break; aoqi@0: case If::aeq: l = lir_cond_aboveEqual; break; aoqi@0: case If::beq: l = lir_cond_belowEqual; break; csahu@8316: default: fatal("You must pass valid If::Condition"); aoqi@0: }; aoqi@0: return l; aoqi@0: } aoqi@0: aoqi@0: #ifdef __SOFTFP__ aoqi@0: void do_soft_float_compare(If *x); aoqi@0: #endif // __SOFTFP__ aoqi@0: aoqi@0: void init(); aoqi@0: aoqi@0: SwitchRangeArray* create_lookup_ranges(TableSwitch* x); aoqi@0: SwitchRangeArray* create_lookup_ranges(LookupSwitch* x); aoqi@0: void do_SwitchRanges(SwitchRangeArray* x, LIR_Opr value, BlockBegin* default_sux); aoqi@0: aoqi@0: void do_RuntimeCall(address routine, int expected_arguments, Intrinsic* x); aoqi@0: #ifdef TRACE_HAVE_INTRINSICS aoqi@0: void do_ThreadIDIntrinsic(Intrinsic* x); aoqi@0: void do_ClassIDIntrinsic(Intrinsic* x); aoqi@0: #endif aoqi@0: ciKlass* profile_type(ciMethodData* md, int md_first_offset, int md_offset, intptr_t profiled_k, aoqi@0: Value arg, LIR_Opr& mdp, bool not_null, ciKlass* signature_at_call_k, aoqi@0: ciKlass* callee_signature_k); aoqi@0: void profile_arguments(ProfileCall* x); aoqi@0: void profile_parameters(Base* x); aoqi@0: void profile_parameters_at_call(ProfileCall* x); kevinw@8368: LIR_Opr maybe_mask_boolean(StoreIndexed* x, LIR_Opr array, LIR_Opr value, CodeEmitInfo*& null_check_info); aoqi@0: aoqi@0: public: aoqi@0: Compilation* compilation() const { return _compilation; } aoqi@0: FrameMap* frame_map() const { return _compilation->frame_map(); } aoqi@0: ciMethod* method() const { return _method; } aoqi@0: BlockBegin* block() const { return _block; } aoqi@0: IRScope* scope() const { return block()->scope(); } aoqi@0: aoqi@0: int max_virtual_register_number() const { return _virtual_register_number; } aoqi@0: aoqi@0: void block_do(BlockBegin* block); aoqi@0: aoqi@0: // Flags that can be set on vregs aoqi@0: enum VregFlag { aoqi@0: must_start_in_memory = 0 // needs to be assigned a memory location at beginning, but may then be loaded in a register aoqi@0: , callee_saved = 1 // must be in a callee saved register aoqi@0: , byte_reg = 2 // must be in a byte register aoqi@0: , num_vreg_flags aoqi@0: aoqi@0: }; aoqi@0: aoqi@0: LIRGenerator(Compilation* compilation, ciMethod* method) aoqi@0: : _compilation(compilation) aoqi@0: , _method(method) aoqi@0: , _virtual_register_number(LIR_OprDesc::vreg_base) aoqi@0: , _vreg_flags(NULL, 0, num_vreg_flags) { aoqi@0: init(); aoqi@0: } aoqi@0: aoqi@0: // for virtual registers, maps them back to Phi's or Local's aoqi@0: Instruction* instruction_for_opr(LIR_Opr opr); aoqi@0: Instruction* instruction_for_vreg(int reg_num); aoqi@0: aoqi@0: void set_vreg_flag (int vreg_num, VregFlag f); aoqi@0: bool is_vreg_flag_set(int vreg_num, VregFlag f); aoqi@0: void set_vreg_flag (LIR_Opr opr, VregFlag f) { set_vreg_flag(opr->vreg_number(), f); } aoqi@0: bool is_vreg_flag_set(LIR_Opr opr, VregFlag f) { return is_vreg_flag_set(opr->vreg_number(), f); } aoqi@0: aoqi@0: // statics aoqi@0: static LIR_Opr exceptionOopOpr(); aoqi@0: static LIR_Opr exceptionPcOpr(); aoqi@0: static LIR_Opr divInOpr(); aoqi@0: static LIR_Opr divOutOpr(); aoqi@0: static LIR_Opr remOutOpr(); aoqi@0: static LIR_Opr shiftCountOpr(); aoqi@0: LIR_Opr syncTempOpr(); aoqi@0: LIR_Opr atomicLockOpr(); aoqi@0: aoqi@0: // returns a register suitable for saving the thread in a aoqi@0: // call_runtime_leaf if one is needed. aoqi@0: LIR_Opr getThreadTemp(); aoqi@0: aoqi@0: // visitor functionality aoqi@0: virtual void do_Phi (Phi* x); aoqi@0: virtual void do_Local (Local* x); aoqi@0: virtual void do_Constant (Constant* x); aoqi@0: virtual void do_LoadField (LoadField* x); aoqi@0: virtual void do_StoreField (StoreField* x); aoqi@0: virtual void do_ArrayLength (ArrayLength* x); aoqi@0: virtual void do_LoadIndexed (LoadIndexed* x); aoqi@0: virtual void do_StoreIndexed (StoreIndexed* x); aoqi@0: virtual void do_NegateOp (NegateOp* x); aoqi@0: virtual void do_ArithmeticOp (ArithmeticOp* x); aoqi@0: virtual void do_ShiftOp (ShiftOp* x); aoqi@0: virtual void do_LogicOp (LogicOp* x); aoqi@0: virtual void do_CompareOp (CompareOp* x); aoqi@0: virtual void do_IfOp (IfOp* x); aoqi@0: virtual void do_Convert (Convert* x); aoqi@0: virtual void do_NullCheck (NullCheck* x); aoqi@0: virtual void do_TypeCast (TypeCast* x); aoqi@0: virtual void do_Invoke (Invoke* x); aoqi@0: virtual void do_NewInstance (NewInstance* x); aoqi@0: virtual void do_NewTypeArray (NewTypeArray* x); aoqi@0: virtual void do_NewObjectArray (NewObjectArray* x); aoqi@0: virtual void do_NewMultiArray (NewMultiArray* x); aoqi@0: virtual void do_CheckCast (CheckCast* x); aoqi@0: virtual void do_InstanceOf (InstanceOf* x); aoqi@0: virtual void do_MonitorEnter (MonitorEnter* x); aoqi@0: virtual void do_MonitorExit (MonitorExit* x); aoqi@0: virtual void do_Intrinsic (Intrinsic* x); aoqi@0: virtual void do_BlockBegin (BlockBegin* x); aoqi@0: virtual void do_Goto (Goto* x); aoqi@0: virtual void do_If (If* x); aoqi@0: virtual void do_IfInstanceOf (IfInstanceOf* x); aoqi@0: virtual void do_TableSwitch (TableSwitch* x); aoqi@0: virtual void do_LookupSwitch (LookupSwitch* x); aoqi@0: virtual void do_Return (Return* x); aoqi@0: virtual void do_Throw (Throw* x); aoqi@0: virtual void do_Base (Base* x); aoqi@0: virtual void do_OsrEntry (OsrEntry* x); aoqi@0: virtual void do_ExceptionObject(ExceptionObject* x); aoqi@0: virtual void do_RoundFP (RoundFP* x); aoqi@0: virtual void do_UnsafeGetRaw (UnsafeGetRaw* x); aoqi@0: virtual void do_UnsafePutRaw (UnsafePutRaw* x); aoqi@0: virtual void do_UnsafeGetObject(UnsafeGetObject* x); aoqi@0: virtual void do_UnsafePutObject(UnsafePutObject* x); aoqi@0: virtual void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x); aoqi@0: virtual void do_UnsafePrefetchRead (UnsafePrefetchRead* x); aoqi@0: virtual void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x); aoqi@0: virtual void do_ProfileCall (ProfileCall* x); aoqi@0: virtual void do_ProfileReturnType (ProfileReturnType* x); aoqi@0: virtual void do_ProfileInvoke (ProfileInvoke* x); aoqi@0: virtual void do_RuntimeCall (RuntimeCall* x); aoqi@0: virtual void do_MemBar (MemBar* x); aoqi@0: virtual void do_RangeCheckPredicate(RangeCheckPredicate* x); aoqi@0: #ifdef ASSERT aoqi@0: virtual void do_Assert (Assert* x); aoqi@0: #endif dlong@7598: dlong@7598: #ifdef C1_LIRGENERATOR_MD_HPP dlong@7598: #include C1_LIRGENERATOR_MD_HPP dlong@7598: #endif aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: class LIRItem: public CompilationResourceObj { aoqi@0: private: aoqi@0: Value _value; aoqi@0: LIRGenerator* _gen; aoqi@0: LIR_Opr _result; aoqi@0: bool _destroys_register; aoqi@0: LIR_Opr _new_result; aoqi@0: aoqi@0: LIRGenerator* gen() const { return _gen; } aoqi@0: aoqi@0: public: aoqi@0: LIRItem(Value value, LIRGenerator* gen) { aoqi@0: _destroys_register = false; aoqi@0: _gen = gen; aoqi@0: set_instruction(value); aoqi@0: } aoqi@0: aoqi@0: LIRItem(LIRGenerator* gen) { aoqi@0: _destroys_register = false; aoqi@0: _gen = gen; aoqi@0: _result = LIR_OprFact::illegalOpr; aoqi@0: set_instruction(NULL); aoqi@0: } aoqi@0: aoqi@0: void set_instruction(Value value) { aoqi@0: _value = value; aoqi@0: _result = LIR_OprFact::illegalOpr; aoqi@0: if (_value != NULL) { aoqi@0: _gen->walk(_value); aoqi@0: _result = _value->operand(); aoqi@0: } aoqi@0: _new_result = LIR_OprFact::illegalOpr; aoqi@0: } aoqi@0: aoqi@0: Value value() const { return _value; } aoqi@0: ValueType* type() const { return value()->type(); } aoqi@0: LIR_Opr result() { aoqi@0: assert(!_destroys_register || (!_result->is_register() || _result->is_virtual()), aoqi@0: "shouldn't use set_destroys_register with physical regsiters"); aoqi@0: if (_destroys_register && _result->is_register()) { aoqi@0: if (_new_result->is_illegal()) { aoqi@0: _new_result = _gen->new_register(type()); aoqi@0: gen()->lir()->move(_result, _new_result); aoqi@0: } aoqi@0: return _new_result; aoqi@0: } else { aoqi@0: return _result; aoqi@0: } aoqi@0: return _result; aoqi@0: } aoqi@0: aoqi@0: void set_result(LIR_Opr opr); aoqi@0: aoqi@0: void load_item(); aoqi@0: void load_byte_item(); aoqi@0: void load_nonconstant(); aoqi@0: // load any values which can't be expressed as part of a single store instruction aoqi@0: void load_for_store(BasicType store_type); aoqi@0: void load_item_force(LIR_Opr reg); aoqi@0: aoqi@0: void dont_load_item() { aoqi@0: // do nothing aoqi@0: } aoqi@0: aoqi@0: void set_destroys_register() { aoqi@0: _destroys_register = true; aoqi@0: } aoqi@0: aoqi@0: bool is_constant() const { return value()->as_Constant() != NULL; } aoqi@0: bool is_stack() { return result()->is_stack(); } aoqi@0: bool is_register() { return result()->is_register(); } aoqi@0: aoqi@0: ciObject* get_jobject_constant() const; aoqi@0: jint get_jint_constant() const; aoqi@0: jlong get_jlong_constant() const; aoqi@0: jfloat get_jfloat_constant() const; aoqi@0: jdouble get_jdouble_constant() const; aoqi@0: jint get_address_constant() const; aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_C1_C1_LIRGENERATOR_HPP