src/cpu/x86/vm/c1_LinearScan_x86.hpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2010, 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 CPU_X86_VM_C1_LINEARSCAN_X86_HPP
aoqi@0 26 #define CPU_X86_VM_C1_LINEARSCAN_X86_HPP
aoqi@0 27
aoqi@0 28 inline bool LinearScan::is_processed_reg_num(int reg_num) {
aoqi@0 29 #ifndef _LP64
aoqi@0 30 // rsp and rbp (numbers 6 ancd 7) are ignored
aoqi@0 31 assert(FrameMap::rsp_opr->cpu_regnr() == 6, "wrong assumption below");
aoqi@0 32 assert(FrameMap::rbp_opr->cpu_regnr() == 7, "wrong assumption below");
aoqi@0 33 assert(reg_num >= 0, "invalid reg_num");
aoqi@0 34 #else
aoqi@0 35 // rsp and rbp, r10, r15 (numbers [12,15]) are ignored
aoqi@0 36 // r12 (number 11) is conditional on compressed oops.
aoqi@0 37 assert(FrameMap::r12_opr->cpu_regnr() == 11, "wrong assumption below");
aoqi@0 38 assert(FrameMap::r10_opr->cpu_regnr() == 12, "wrong assumption below");
aoqi@0 39 assert(FrameMap::r15_opr->cpu_regnr() == 13, "wrong assumption below");
aoqi@0 40 assert(FrameMap::rsp_opr->cpu_regnrLo() == 14, "wrong assumption below");
aoqi@0 41 assert(FrameMap::rbp_opr->cpu_regnrLo() == 15, "wrong assumption below");
aoqi@0 42 assert(reg_num >= 0, "invalid reg_num");
aoqi@0 43 #endif // _LP64
aoqi@0 44 return reg_num <= FrameMap::last_cpu_reg() || reg_num >= pd_nof_cpu_regs_frame_map;
aoqi@0 45 }
aoqi@0 46
aoqi@0 47 inline int LinearScan::num_physical_regs(BasicType type) {
aoqi@0 48 // Intel requires two cpu registers for long,
aoqi@0 49 // but requires only one fpu register for double
aoqi@0 50 if (LP64_ONLY(false &&) type == T_LONG) {
aoqi@0 51 return 2;
aoqi@0 52 }
aoqi@0 53 return 1;
aoqi@0 54 }
aoqi@0 55
aoqi@0 56
aoqi@0 57 inline bool LinearScan::requires_adjacent_regs(BasicType type) {
aoqi@0 58 return false;
aoqi@0 59 }
aoqi@0 60
aoqi@0 61 inline bool LinearScan::is_caller_save(int assigned_reg) {
aoqi@0 62 assert(assigned_reg >= 0 && assigned_reg < nof_regs, "should call this only for registers");
aoqi@0 63 return true; // no callee-saved registers on Intel
aoqi@0 64
aoqi@0 65 }
aoqi@0 66
aoqi@0 67
aoqi@0 68 inline void LinearScan::pd_add_temps(LIR_Op* op) {
aoqi@0 69 switch (op->code()) {
aoqi@0 70 case lir_tan:
aoqi@0 71 case lir_sin:
aoqi@0 72 case lir_cos: {
aoqi@0 73 // The slow path for these functions may need to save and
aoqi@0 74 // restore all live registers but we don't want to save and
aoqi@0 75 // restore everything all the time, so mark the xmms as being
aoqi@0 76 // killed. If the slow path were explicit or we could propagate
aoqi@0 77 // live register masks down to the assembly we could do better
aoqi@0 78 // but we don't have any easy way to do that right now. We
aoqi@0 79 // could also consider not killing all xmm registers if we
aoqi@0 80 // assume that slow paths are uncommon but it's not clear that
aoqi@0 81 // would be a good idea.
aoqi@0 82 if (UseSSE > 0) {
aoqi@0 83 #ifndef PRODUCT
aoqi@0 84 if (TraceLinearScanLevel >= 2) {
aoqi@0 85 tty->print_cr("killing XMMs for trig");
aoqi@0 86 }
aoqi@0 87 #endif
aoqi@0 88 int op_id = op->id();
aoqi@0 89 for (int xmm = 0; xmm < FrameMap::nof_caller_save_xmm_regs; xmm++) {
aoqi@0 90 LIR_Opr opr = FrameMap::caller_save_xmm_reg_at(xmm);
aoqi@0 91 add_temp(reg_num(opr), op_id, noUse, T_ILLEGAL);
aoqi@0 92 }
aoqi@0 93 }
aoqi@0 94 break;
aoqi@0 95 }
aoqi@0 96 }
aoqi@0 97 }
aoqi@0 98
aoqi@0 99
aoqi@0 100 // Implementation of LinearScanWalker
aoqi@0 101
aoqi@0 102 inline bool LinearScanWalker::pd_init_regs_for_alloc(Interval* cur) {
aoqi@0 103 if (allocator()->gen()->is_vreg_flag_set(cur->reg_num(), LIRGenerator::byte_reg)) {
aoqi@0 104 assert(cur->type() != T_FLOAT && cur->type() != T_DOUBLE, "cpu regs only");
aoqi@0 105 _first_reg = pd_first_byte_reg;
aoqi@0 106 _last_reg = FrameMap::last_byte_reg();
aoqi@0 107 return true;
aoqi@0 108 } else if ((UseSSE >= 1 && cur->type() == T_FLOAT) || (UseSSE >= 2 && cur->type() == T_DOUBLE)) {
aoqi@0 109 _first_reg = pd_first_xmm_reg;
aoqi@0 110 _last_reg = pd_last_xmm_reg;
aoqi@0 111 return true;
aoqi@0 112 }
aoqi@0 113
aoqi@0 114 return false;
aoqi@0 115 }
aoqi@0 116
aoqi@0 117
aoqi@0 118 class FpuStackAllocator VALUE_OBJ_CLASS_SPEC {
aoqi@0 119 private:
aoqi@0 120 Compilation* _compilation;
aoqi@0 121 LinearScan* _allocator;
aoqi@0 122
aoqi@0 123 LIR_OpVisitState visitor;
aoqi@0 124
aoqi@0 125 LIR_List* _lir;
aoqi@0 126 int _pos;
aoqi@0 127 FpuStackSim _sim;
aoqi@0 128 FpuStackSim _temp_sim;
aoqi@0 129
aoqi@0 130 bool _debug_information_computed;
aoqi@0 131
aoqi@0 132 LinearScan* allocator() { return _allocator; }
aoqi@0 133 Compilation* compilation() const { return _compilation; }
aoqi@0 134
aoqi@0 135 // unified bailout support
aoqi@0 136 void bailout(const char* msg) const { compilation()->bailout(msg); }
aoqi@0 137 bool bailed_out() const { return compilation()->bailed_out(); }
aoqi@0 138
aoqi@0 139 int pos() { return _pos; }
aoqi@0 140 void set_pos(int pos) { _pos = pos; }
aoqi@0 141 LIR_Op* cur_op() { return lir()->instructions_list()->at(pos()); }
aoqi@0 142 LIR_List* lir() { return _lir; }
aoqi@0 143 void set_lir(LIR_List* lir) { _lir = lir; }
aoqi@0 144 FpuStackSim* sim() { return &_sim; }
aoqi@0 145 FpuStackSim* temp_sim() { return &_temp_sim; }
aoqi@0 146
aoqi@0 147 int fpu_num(LIR_Opr opr);
aoqi@0 148 int tos_offset(LIR_Opr opr);
aoqi@0 149 LIR_Opr to_fpu_stack_top(LIR_Opr opr, bool dont_check_offset = false);
aoqi@0 150
aoqi@0 151 // Helper functions for handling operations
aoqi@0 152 void insert_op(LIR_Op* op);
aoqi@0 153 void insert_exchange(int offset);
aoqi@0 154 void insert_exchange(LIR_Opr opr);
aoqi@0 155 void insert_free(int offset);
aoqi@0 156 void insert_free_if_dead(LIR_Opr opr);
aoqi@0 157 void insert_free_if_dead(LIR_Opr opr, LIR_Opr ignore);
aoqi@0 158 void insert_copy(LIR_Opr from, LIR_Opr to);
aoqi@0 159 void do_rename(LIR_Opr from, LIR_Opr to);
aoqi@0 160 void do_push(LIR_Opr opr);
aoqi@0 161 void pop_if_last_use(LIR_Op* op, LIR_Opr opr);
aoqi@0 162 void pop_always(LIR_Op* op, LIR_Opr opr);
aoqi@0 163 void clear_fpu_stack(LIR_Opr preserve);
aoqi@0 164 void handle_op1(LIR_Op1* op1);
aoqi@0 165 void handle_op2(LIR_Op2* op2);
aoqi@0 166 void handle_opCall(LIR_OpCall* opCall);
aoqi@0 167 void compute_debug_information(LIR_Op* op);
aoqi@0 168 void allocate_exception_handler(XHandler* xhandler);
aoqi@0 169 void allocate_block(BlockBegin* block);
aoqi@0 170
aoqi@0 171 #ifndef PRODUCT
aoqi@0 172 void check_invalid_lir_op(LIR_Op* op);
aoqi@0 173 #endif
aoqi@0 174
aoqi@0 175 // Helper functions for merging of fpu stacks
aoqi@0 176 void merge_insert_add(LIR_List* instrs, FpuStackSim* cur_sim, int reg);
aoqi@0 177 void merge_insert_xchg(LIR_List* instrs, FpuStackSim* cur_sim, int slot);
aoqi@0 178 void merge_insert_pop(LIR_List* instrs, FpuStackSim* cur_sim);
aoqi@0 179 bool merge_rename(FpuStackSim* cur_sim, FpuStackSim* sux_sim, int start_slot, int change_slot);
aoqi@0 180 void merge_fpu_stack(LIR_List* instrs, FpuStackSim* cur_sim, FpuStackSim* sux_sim);
aoqi@0 181 void merge_cleanup_fpu_stack(LIR_List* instrs, FpuStackSim* cur_sim, BitMap& live_fpu_regs);
aoqi@0 182 bool merge_fpu_stack_with_successors(BlockBegin* block);
aoqi@0 183
aoqi@0 184 public:
aoqi@0 185 LIR_Opr to_fpu_stack(LIR_Opr opr); // used by LinearScan for creation of debug information
aoqi@0 186
aoqi@0 187 FpuStackAllocator(Compilation* compilation, LinearScan* allocator);
aoqi@0 188 void allocate();
aoqi@0 189 };
aoqi@0 190
aoqi@0 191 #endif // CPU_X86_VM_C1_LINEARSCAN_X86_HPP

mercurial