buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 17 | /* This file contains register alloction support. */ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 18 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame] | 19 | #include "compiler/dex/compiler_ir.h" |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 20 | #include "compiler/dex/compiler_internals.h" |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 21 | #include "mir_to_lir-inl.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 22 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 23 | namespace art { |
| 24 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 25 | /* |
| 26 | * Free all allocated temps in the temp pools. Note that this does |
| 27 | * not affect the "liveness" of a temp register, which will stay |
| 28 | * live until it is either explicitly killed or reallocated. |
| 29 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 30 | void Mir2Lir::ResetRegPool() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 31 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 32 | int i; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 33 | for (i=0; i < reg_pool_->num_core_regs; i++) { |
| 34 | if (reg_pool_->core_regs[i].is_temp) |
| 35 | reg_pool_->core_regs[i].in_use = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 36 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 37 | for (i=0; i < reg_pool_->num_fp_regs; i++) { |
| 38 | if (reg_pool_->FPRegs[i].is_temp) |
| 39 | reg_pool_->FPRegs[i].in_use = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 40 | } |
buzbee | a5abf70 | 2013-04-12 14:39:29 -0700 | [diff] [blame] | 41 | // Reset temp tracking sanity check. |
| 42 | if (kIsDebugBuild) { |
| 43 | live_sreg_ = INVALID_SREG; |
| 44 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 45 | } |
| 46 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 47 | /* |
| 48 | * Set up temp & preserved register pools specialized by target. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 49 | * Note: num_regs may be zero. |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 50 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 51 | void Mir2Lir::CompilerInitPool(RegisterInfo* regs, int* reg_nums, int num) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 52 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 53 | int i; |
| 54 | for (i=0; i < num; i++) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 55 | regs[i].reg = reg_nums[i]; |
| 56 | regs[i].in_use = false; |
| 57 | regs[i].is_temp = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 58 | regs[i].pair = false; |
| 59 | regs[i].live = false; |
| 60 | regs[i].dirty = false; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 61 | regs[i].s_reg = INVALID_SREG; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 62 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 63 | } |
| 64 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 65 | void Mir2Lir::DumpRegPool(RegisterInfo* p, int num_regs) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 66 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 67 | LOG(INFO) << "================================================"; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 68 | for (int i = 0; i < num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 69 | LOG(INFO) << StringPrintf( |
| 70 | "R[%d]: T:%d, U:%d, P:%d, p:%d, LV:%d, D:%d, SR:%d, ST:%x, EN:%x", |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 71 | p[i].reg, p[i].is_temp, p[i].in_use, p[i].pair, p[i].partner, |
| 72 | p[i].live, p[i].dirty, p[i].s_reg, reinterpret_cast<uintptr_t>(p[i].def_start), |
| 73 | reinterpret_cast<uintptr_t>(p[i].def_end)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 74 | } |
| 75 | LOG(INFO) << "================================================"; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 76 | } |
| 77 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 78 | void Mir2Lir::DumpCoreRegPool() |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 79 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 80 | DumpRegPool(reg_pool_->core_regs, reg_pool_->num_core_regs); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 81 | } |
| 82 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 83 | void Mir2Lir::DumpFpRegPool() |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 84 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 85 | DumpRegPool(reg_pool_->FPRegs, reg_pool_->num_fp_regs); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 86 | } |
| 87 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 88 | void Mir2Lir::ClobberSRegBody(RegisterInfo* p, int num_regs, int s_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 89 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 90 | int i; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 91 | for (i=0; i< num_regs; i++) { |
| 92 | if (p[i].s_reg == s_reg) { |
| 93 | if (p[i].is_temp) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 94 | p[i].live = false; |
| 95 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 96 | p[i].def_start = NULL; |
| 97 | p[i].def_end = NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 98 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 99 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 100 | } |
| 101 | |
buzbee | 078fa45 | 2012-12-03 15:51:33 -0800 | [diff] [blame] | 102 | /* |
| 103 | * Break the association between a Dalvik vreg and a physical temp register of either register |
| 104 | * class. |
| 105 | * TODO: Ideally, the public version of this code should not exist. Besides its local usage |
| 106 | * in the register utilities, is is also used by code gen routines to work around a deficiency in |
| 107 | * local register allocation, which fails to distinguish between the "in" and "out" identities |
| 108 | * of Dalvik vregs. This can result in useless register copies when the same Dalvik vreg |
| 109 | * is used both as the source and destination register of an operation in which the type |
| 110 | * changes (for example: INT_TO_FLOAT v1, v1). Revisit when improved register allocation is |
| 111 | * addressed. |
| 112 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 113 | void Mir2Lir::ClobberSReg(int s_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 114 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 115 | /* Reset live temp tracking sanity checker */ |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 116 | if (kIsDebugBuild) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 117 | if (s_reg == live_sreg_) { |
| 118 | live_sreg_ = INVALID_SREG; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 119 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 120 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 121 | ClobberSRegBody(reg_pool_->core_regs, reg_pool_->num_core_regs, s_reg); |
| 122 | ClobberSRegBody(reg_pool_->FPRegs, reg_pool_->num_fp_regs, s_reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 123 | } |
| 124 | |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 125 | /* |
| 126 | * SSA names associated with the initial definitions of Dalvik |
| 127 | * registers are the same as the Dalvik register number (and |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 128 | * thus take the same position in the promotion_map. However, |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 129 | * the special Method* and compiler temp resisters use negative |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 130 | * v_reg numbers to distinguish them and can have an arbitrary |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 131 | * ssa name (above the last original Dalvik register). This function |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 132 | * maps SSA names to positions in the promotion_map array. |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 133 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 134 | int Mir2Lir::SRegToPMap(int s_reg) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 135 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 136 | DCHECK_LT(s_reg, mir_graph_->GetNumSSARegs()); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 137 | DCHECK_GE(s_reg, 0); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 138 | int v_reg = mir_graph_->SRegToVReg(s_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 139 | if (v_reg >= 0) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 140 | DCHECK_LT(v_reg, cu_->num_dalvik_registers); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 141 | return v_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 142 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 143 | int pos = std::abs(v_reg) - std::abs(SSA_METHOD_BASEREG); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 144 | DCHECK_LE(pos, cu_->num_compiler_temps); |
| 145 | return cu_->num_dalvik_registers + pos; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 146 | } |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 147 | } |
| 148 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 149 | void Mir2Lir::RecordCorePromotion(int reg, int s_reg) |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 150 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 151 | int p_map_idx = SRegToPMap(s_reg); |
| 152 | int v_reg = mir_graph_->SRegToVReg(s_reg); |
| 153 | GetRegInfo(reg)->in_use = true; |
| 154 | core_spill_mask_ |= (1 << reg); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 155 | // Include reg for later sort |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 156 | core_vmap_table_.push_back(reg << VREG_NUM_WIDTH | (v_reg & ((1 << VREG_NUM_WIDTH) - 1))); |
| 157 | num_core_spills_++; |
| 158 | promotion_map_[p_map_idx].core_location = kLocPhysReg; |
| 159 | promotion_map_[p_map_idx].core_reg = reg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 160 | } |
| 161 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 162 | /* Reserve a callee-save register. Return -1 if none available */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 163 | int Mir2Lir::AllocPreservedCoreReg(int s_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 164 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 165 | int res = -1; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 166 | RegisterInfo* core_regs = reg_pool_->core_regs; |
| 167 | for (int i = 0; i < reg_pool_->num_core_regs; i++) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 168 | if (!core_regs[i].is_temp && !core_regs[i].in_use) { |
| 169 | res = core_regs[i].reg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 170 | RecordCorePromotion(res, s_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 171 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 172 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 173 | } |
| 174 | return res; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 175 | } |
| 176 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 177 | void Mir2Lir::RecordFpPromotion(int reg, int s_reg) |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 178 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 179 | int p_map_idx = SRegToPMap(s_reg); |
| 180 | int v_reg = mir_graph_->SRegToVReg(s_reg); |
| 181 | GetRegInfo(reg)->in_use = true; |
| 182 | MarkPreservedSingle(v_reg, reg); |
| 183 | promotion_map_[p_map_idx].fp_location = kLocPhysReg; |
| 184 | promotion_map_[p_map_idx].FpReg = reg; |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 185 | } |
| 186 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 187 | /* |
| 188 | * Reserve a callee-save fp single register. Try to fullfill request for |
| 189 | * even/odd allocation, but go ahead and allocate anything if not |
| 190 | * available. If nothing's available, return -1. |
| 191 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 192 | int Mir2Lir::AllocPreservedSingle(int s_reg, bool even) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 193 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 194 | int res = -1; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 195 | RegisterInfo* FPRegs = reg_pool_->FPRegs; |
| 196 | for (int i = 0; i < reg_pool_->num_fp_regs; i++) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 197 | if (!FPRegs[i].is_temp && !FPRegs[i].in_use && |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 198 | ((FPRegs[i].reg & 0x1) == 0) == even) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 199 | res = FPRegs[i].reg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 200 | RecordFpPromotion(res, s_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 201 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 202 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 203 | } |
| 204 | return res; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Somewhat messy code here. We want to allocate a pair of contiguous |
| 209 | * physical single-precision floating point registers starting with |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 210 | * an even numbered reg. It is possible that the paired s_reg (s_reg+1) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 211 | * has already been allocated - try to fit if possible. Fail to |
| 212 | * allocate if we can't meet the requirements for the pair of |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 213 | * s_reg<=sX[even] & (s_reg+1)<= sX+1. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 214 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 215 | int Mir2Lir::AllocPreservedDouble(int s_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 216 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 217 | int res = -1; // Assume failure |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 218 | int v_reg = mir_graph_->SRegToVReg(s_reg); |
| 219 | int p_map_idx = SRegToPMap(s_reg); |
| 220 | if (promotion_map_[p_map_idx+1].fp_location == kLocPhysReg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 221 | // Upper reg is already allocated. Can we fit? |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 222 | int high_reg = promotion_map_[p_map_idx+1].FpReg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 223 | if ((high_reg & 1) == 0) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 224 | // High reg is even - fail. |
| 225 | return res; |
| 226 | } |
| 227 | // Is the low reg of the pair free? |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 228 | RegisterInfo* p = GetRegInfo(high_reg-1); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 229 | if (p->in_use || p->is_temp) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 230 | // Already allocated or not preserved - fail. |
| 231 | return res; |
| 232 | } |
| 233 | // OK - good to go. |
| 234 | res = p->reg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 235 | p->in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 236 | DCHECK_EQ((res & 1), 0); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 237 | MarkPreservedSingle(v_reg, res); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 238 | } else { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 239 | RegisterInfo* FPRegs = reg_pool_->FPRegs; |
| 240 | for (int i = 0; i < reg_pool_->num_fp_regs; i++) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 241 | if (!FPRegs[i].is_temp && !FPRegs[i].in_use && |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 242 | ((FPRegs[i].reg & 0x1) == 0x0) && |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 243 | !FPRegs[i+1].is_temp && !FPRegs[i+1].in_use && |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 244 | ((FPRegs[i+1].reg & 0x1) == 0x1) && |
| 245 | (FPRegs[i].reg + 1) == FPRegs[i+1].reg) { |
| 246 | res = FPRegs[i].reg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 247 | FPRegs[i].in_use = true; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 248 | MarkPreservedSingle(v_reg, res); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 249 | FPRegs[i+1].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 250 | DCHECK_EQ(res + 1, FPRegs[i+1].reg); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 251 | MarkPreservedSingle(v_reg+1, res+1); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 252 | break; |
| 253 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 254 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 255 | } |
| 256 | if (res != -1) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 257 | promotion_map_[p_map_idx].fp_location = kLocPhysReg; |
| 258 | promotion_map_[p_map_idx].FpReg = res; |
| 259 | promotion_map_[p_map_idx+1].fp_location = kLocPhysReg; |
| 260 | promotion_map_[p_map_idx+1].FpReg = res + 1; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 261 | } |
| 262 | return res; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | |
| 266 | /* |
| 267 | * Reserve a callee-save fp register. If this register can be used |
| 268 | * as the first of a double, attempt to allocate an even pair of fp |
| 269 | * single regs (but if can't still attempt to allocate a single, preferring |
| 270 | * first to allocate an odd register. |
| 271 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 272 | int Mir2Lir::AllocPreservedFPReg(int s_reg, bool double_start) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 273 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 274 | int res = -1; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 275 | if (double_start) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 276 | res = AllocPreservedDouble(s_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 277 | } |
| 278 | if (res == -1) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 279 | res = AllocPreservedSingle(s_reg, false /* try odd # */); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 280 | } |
| 281 | if (res == -1) |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 282 | res = AllocPreservedSingle(s_reg, true /* try even # */); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 283 | return res; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 284 | } |
| 285 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 286 | int Mir2Lir::AllocTempBody(RegisterInfo* p, int num_regs, int* next_temp, |
| 287 | bool required) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 288 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 289 | int i; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 290 | int next = *next_temp; |
| 291 | for (i=0; i< num_regs; i++) { |
| 292 | if (next >= num_regs) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 293 | next = 0; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 294 | if (p[next].is_temp && !p[next].in_use && !p[next].live) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 295 | Clobber(p[next].reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 296 | p[next].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 297 | p[next].pair = false; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 298 | *next_temp = next + 1; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 299 | return p[next].reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 300 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 301 | next++; |
| 302 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 303 | next = *next_temp; |
| 304 | for (i=0; i< num_regs; i++) { |
| 305 | if (next >= num_regs) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 306 | next = 0; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 307 | if (p[next].is_temp && !p[next].in_use) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 308 | Clobber(p[next].reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 309 | p[next].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 310 | p[next].pair = false; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 311 | *next_temp = next + 1; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 312 | return p[next].reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 313 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 314 | next++; |
| 315 | } |
| 316 | if (required) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 317 | CodegenDump(); |
| 318 | DumpRegPool(reg_pool_->core_regs, |
| 319 | reg_pool_->num_core_regs); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 320 | LOG(FATAL) << "No free temp registers"; |
| 321 | } |
| 322 | return -1; // No register available |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | //REDO: too many assumptions. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 326 | int Mir2Lir::AllocTempDouble() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 327 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 328 | RegisterInfo* p = reg_pool_->FPRegs; |
| 329 | int num_regs = reg_pool_->num_fp_regs; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 330 | /* Start looking at an even reg */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 331 | int next = reg_pool_->next_fp_reg & ~0x1; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 332 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 333 | // First try to avoid allocating live registers |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 334 | for (int i=0; i < num_regs; i+=2) { |
| 335 | if (next >= num_regs) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 336 | next = 0; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 337 | if ((p[next].is_temp && !p[next].in_use && !p[next].live) && |
| 338 | (p[next+1].is_temp && !p[next+1].in_use && !p[next+1].live)) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 339 | Clobber(p[next].reg); |
| 340 | Clobber(p[next+1].reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 341 | p[next].in_use = true; |
| 342 | p[next+1].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 343 | DCHECK_EQ((p[next].reg+1), p[next+1].reg); |
| 344 | DCHECK_EQ((p[next].reg & 0x1), 0); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 345 | reg_pool_->next_fp_reg = next + 2; |
| 346 | if (reg_pool_->next_fp_reg >= num_regs) { |
| 347 | reg_pool_->next_fp_reg = 0; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 348 | } |
| 349 | return p[next].reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 350 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 351 | next += 2; |
| 352 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 353 | next = reg_pool_->next_fp_reg & ~0x1; |
buzbee | a50638b | 2011-11-02 15:15:06 -0700 | [diff] [blame] | 354 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 355 | // No choice - find a pair and kill it. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 356 | for (int i=0; i < num_regs; i+=2) { |
| 357 | if (next >= num_regs) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 358 | next = 0; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 359 | if (p[next].is_temp && !p[next].in_use && p[next+1].is_temp && |
| 360 | !p[next+1].in_use) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 361 | Clobber(p[next].reg); |
| 362 | Clobber(p[next+1].reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 363 | p[next].in_use = true; |
| 364 | p[next+1].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 365 | DCHECK_EQ((p[next].reg+1), p[next+1].reg); |
| 366 | DCHECK_EQ((p[next].reg & 0x1), 0); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 367 | reg_pool_->next_fp_reg = next + 2; |
| 368 | if (reg_pool_->next_fp_reg >= num_regs) { |
| 369 | reg_pool_->next_fp_reg = 0; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 370 | } |
| 371 | return p[next].reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 372 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 373 | next += 2; |
| 374 | } |
| 375 | LOG(FATAL) << "No free temp registers (pair)"; |
| 376 | return -1; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /* Return a temp if one is available, -1 otherwise */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 380 | int Mir2Lir::AllocFreeTemp() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 381 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 382 | return AllocTempBody(reg_pool_->core_regs, |
| 383 | reg_pool_->num_core_regs, |
| 384 | ®_pool_->next_core_reg, true); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 385 | } |
| 386 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 387 | int Mir2Lir::AllocTemp() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 388 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 389 | return AllocTempBody(reg_pool_->core_regs, |
| 390 | reg_pool_->num_core_regs, |
| 391 | ®_pool_->next_core_reg, true); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 392 | } |
| 393 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 394 | int Mir2Lir::AllocTempFloat() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 395 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 396 | return AllocTempBody(reg_pool_->FPRegs, |
| 397 | reg_pool_->num_fp_regs, |
| 398 | ®_pool_->next_fp_reg, true); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 399 | } |
| 400 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 401 | Mir2Lir::RegisterInfo* Mir2Lir::AllocLiveBody(RegisterInfo* p, int num_regs, int s_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 402 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 403 | int i; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 404 | if (s_reg == -1) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 405 | return NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 406 | for (i=0; i < num_regs; i++) { |
| 407 | if (p[i].live && (p[i].s_reg == s_reg)) { |
| 408 | if (p[i].is_temp) |
| 409 | p[i].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 410 | return &p[i]; |
| 411 | } |
| 412 | } |
| 413 | return NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 414 | } |
| 415 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 416 | Mir2Lir::RegisterInfo* Mir2Lir::AllocLive(int s_reg, int reg_class) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 417 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 418 | RegisterInfo* res = NULL; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 419 | switch (reg_class) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 420 | case kAnyReg: |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 421 | res = AllocLiveBody(reg_pool_->FPRegs, |
| 422 | reg_pool_->num_fp_regs, s_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 423 | if (res) |
| 424 | break; |
| 425 | /* Intentional fallthrough */ |
| 426 | case kCoreReg: |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 427 | res = AllocLiveBody(reg_pool_->core_regs, |
| 428 | reg_pool_->num_core_regs, s_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 429 | break; |
| 430 | case kFPReg: |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 431 | res = AllocLiveBody(reg_pool_->FPRegs, |
| 432 | reg_pool_->num_fp_regs, s_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 433 | break; |
| 434 | default: |
| 435 | LOG(FATAL) << "Invalid register type"; |
| 436 | } |
| 437 | return res; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 438 | } |
| 439 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 440 | void Mir2Lir::FreeTemp(int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 441 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 442 | RegisterInfo* p = reg_pool_->core_regs; |
| 443 | int num_regs = reg_pool_->num_core_regs; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 444 | int i; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 445 | for (i=0; i< num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 446 | if (p[i].reg == reg) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 447 | if (p[i].is_temp) { |
| 448 | p[i].in_use = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 449 | } |
| 450 | p[i].pair = false; |
| 451 | return; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 452 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 453 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 454 | p = reg_pool_->FPRegs; |
| 455 | num_regs = reg_pool_->num_fp_regs; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 456 | for (i=0; i< num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 457 | if (p[i].reg == reg) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 458 | if (p[i].is_temp) { |
| 459 | p[i].in_use = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 460 | } |
| 461 | p[i].pair = false; |
| 462 | return; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 463 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 464 | } |
| 465 | LOG(FATAL) << "Tried to free a non-existant temp: r" << reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 466 | } |
| 467 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 468 | Mir2Lir::RegisterInfo* Mir2Lir::IsLive(int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 469 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 470 | RegisterInfo* p = reg_pool_->core_regs; |
| 471 | int num_regs = reg_pool_->num_core_regs; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 472 | int i; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 473 | for (i=0; i< num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 474 | if (p[i].reg == reg) { |
| 475 | return p[i].live ? &p[i] : NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 476 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 477 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 478 | p = reg_pool_->FPRegs; |
| 479 | num_regs = reg_pool_->num_fp_regs; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 480 | for (i=0; i< num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 481 | if (p[i].reg == reg) { |
| 482 | return p[i].live ? &p[i] : NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 483 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 484 | } |
| 485 | return NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 486 | } |
| 487 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 488 | Mir2Lir::RegisterInfo* Mir2Lir::IsTemp(int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 489 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 490 | RegisterInfo* p = GetRegInfo(reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 491 | return (p->is_temp) ? p : NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 492 | } |
| 493 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 494 | Mir2Lir::RegisterInfo* Mir2Lir::IsPromoted(int reg) |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 495 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 496 | RegisterInfo* p = GetRegInfo(reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 497 | return (p->is_temp) ? NULL : p; |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 498 | } |
| 499 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 500 | bool Mir2Lir::IsDirty(int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 501 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 502 | RegisterInfo* p = GetRegInfo(reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 503 | return p->dirty; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | /* |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 507 | * Similar to AllocTemp(), but forces the allocation of a specific |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 508 | * register. No check is made to see if the register was previously |
| 509 | * allocated. Use with caution. |
| 510 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 511 | void Mir2Lir::LockTemp(int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 512 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 513 | RegisterInfo* p = reg_pool_->core_regs; |
| 514 | int num_regs = reg_pool_->num_core_regs; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 515 | int i; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 516 | for (i=0; i< num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 517 | if (p[i].reg == reg) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 518 | DCHECK(p[i].is_temp); |
| 519 | p[i].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 520 | p[i].live = false; |
| 521 | return; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 522 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 523 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 524 | p = reg_pool_->FPRegs; |
| 525 | num_regs = reg_pool_->num_fp_regs; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 526 | for (i=0; i< num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 527 | if (p[i].reg == reg) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 528 | DCHECK(p[i].is_temp); |
| 529 | p[i].in_use = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 530 | p[i].live = false; |
| 531 | return; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 532 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 533 | } |
| 534 | LOG(FATAL) << "Tried to lock a non-existant temp: r" << reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 535 | } |
| 536 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 537 | void Mir2Lir::ResetDef(int reg) |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 538 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 539 | ResetDefBody(GetRegInfo(reg)); |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 540 | } |
| 541 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 542 | void Mir2Lir::NullifyRange(LIR *start, LIR *finish, int s_reg1, int s_reg2) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 543 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 544 | if (start && finish) { |
| 545 | LIR *p; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 546 | DCHECK_EQ(s_reg1, s_reg2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 547 | for (p = start; ;p = p->next) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 548 | NopLIR(p); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 549 | if (p == finish) |
| 550 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 551 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 552 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | /* |
| 556 | * Mark the beginning and end LIR of a def sequence. Note that |
| 557 | * on entry start points to the LIR prior to the beginning of the |
| 558 | * sequence. |
| 559 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 560 | void Mir2Lir::MarkDef(RegLocation rl, LIR *start, LIR *finish) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 561 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 562 | DCHECK(!rl.wide); |
| 563 | DCHECK(start && start->next); |
| 564 | DCHECK(finish); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 565 | RegisterInfo* p = GetRegInfo(rl.low_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 566 | p->def_start = start->next; |
| 567 | p->def_end = finish; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Mark the beginning and end LIR of a def sequence. Note that |
| 572 | * on entry start points to the LIR prior to the beginning of the |
| 573 | * sequence. |
| 574 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 575 | void Mir2Lir::MarkDefWide(RegLocation rl, LIR *start, LIR *finish) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 576 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 577 | DCHECK(rl.wide); |
| 578 | DCHECK(start && start->next); |
| 579 | DCHECK(finish); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 580 | RegisterInfo* p = GetRegInfo(rl.low_reg); |
| 581 | ResetDef(rl.high_reg); // Only track low of pair |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 582 | p->def_start = start->next; |
| 583 | p->def_end = finish; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 584 | } |
| 585 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 586 | RegLocation Mir2Lir::WideToNarrow(RegLocation rl) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 587 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 588 | DCHECK(rl.wide); |
| 589 | if (rl.location == kLocPhysReg) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 590 | RegisterInfo* info_lo = GetRegInfo(rl.low_reg); |
| 591 | RegisterInfo* info_hi = GetRegInfo(rl.high_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 592 | if (info_lo->is_temp) { |
| 593 | info_lo->pair = false; |
| 594 | info_lo->def_start = NULL; |
| 595 | info_lo->def_end = NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 596 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 597 | if (info_hi->is_temp) { |
| 598 | info_hi->pair = false; |
| 599 | info_hi->def_start = NULL; |
| 600 | info_hi->def_end = NULL; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | rl.wide = false; |
| 604 | return rl; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 605 | } |
| 606 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 607 | void Mir2Lir::ResetDefLoc(RegLocation rl) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 608 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 609 | DCHECK(!rl.wide); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 610 | RegisterInfo* p = IsTemp(rl.low_reg); |
| 611 | if (p && !(cu_->disable_opt & (1 << kSuppressLoads))) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 612 | DCHECK(!p->pair); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 613 | NullifyRange(p->def_start, p->def_end, p->s_reg, rl.s_reg_low); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 614 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 615 | ResetDef(rl.low_reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 616 | } |
| 617 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 618 | void Mir2Lir::ResetDefLocWide(RegLocation rl) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 619 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 620 | DCHECK(rl.wide); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 621 | RegisterInfo* p_low = IsTemp(rl.low_reg); |
| 622 | RegisterInfo* p_high = IsTemp(rl.high_reg); |
| 623 | if (p_low && !(cu_->disable_opt & (1 << kSuppressLoads))) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 624 | DCHECK(p_low->pair); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 625 | NullifyRange(p_low->def_start, p_low->def_end, p_low->s_reg, rl.s_reg_low); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 626 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 627 | if (p_high && !(cu_->disable_opt & (1 << kSuppressLoads))) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 628 | DCHECK(p_high->pair); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 629 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 630 | ResetDef(rl.low_reg); |
| 631 | ResetDef(rl.high_reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 632 | } |
| 633 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 634 | void Mir2Lir::ResetDefTracking() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 635 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 636 | int i; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 637 | for (i=0; i< reg_pool_->num_core_regs; i++) { |
| 638 | ResetDefBody(®_pool_->core_regs[i]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 639 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 640 | for (i=0; i< reg_pool_->num_fp_regs; i++) { |
| 641 | ResetDefBody(®_pool_->FPRegs[i]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 642 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 643 | } |
| 644 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 645 | void Mir2Lir::ClobberAllRegs() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 646 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 647 | int i; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 648 | for (i=0; i< reg_pool_->num_core_regs; i++) { |
| 649 | ClobberBody(®_pool_->core_regs[i]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 650 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 651 | for (i=0; i< reg_pool_->num_fp_regs; i++) { |
| 652 | ClobberBody(®_pool_->FPRegs[i]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 653 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 654 | } |
| 655 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 656 | // Make sure nothing is live and dirty |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 657 | void Mir2Lir::FlushAllRegsBody(RegisterInfo* info, int num_regs) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 658 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 659 | int i; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 660 | for (i=0; i < num_regs; i++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 661 | if (info[i].live && info[i].dirty) { |
| 662 | if (info[i].pair) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 663 | FlushRegWide(info[i].reg, info[i].partner); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 664 | } else { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 665 | FlushReg(info[i].reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 666 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 667 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 668 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 669 | } |
| 670 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 671 | void Mir2Lir::FlushAllRegs() |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 672 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 673 | FlushAllRegsBody(reg_pool_->core_regs, |
| 674 | reg_pool_->num_core_regs); |
| 675 | FlushAllRegsBody(reg_pool_->FPRegs, |
| 676 | reg_pool_->num_fp_regs); |
| 677 | ClobberAllRegs(); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
| 681 | //TUNING: rewrite all of this reg stuff. Probably use an attribute table |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 682 | bool Mir2Lir::RegClassMatches(int reg_class, int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 683 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 684 | if (reg_class == kAnyReg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 685 | return true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 686 | } else if (reg_class == kCoreReg) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 687 | return !IsFpReg(reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 688 | } else { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 689 | return IsFpReg(reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 690 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 691 | } |
| 692 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 693 | void Mir2Lir::MarkLive(int reg, int s_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 694 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 695 | RegisterInfo* info = GetRegInfo(reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 696 | if ((info->reg == reg) && (info->s_reg == s_reg) && info->live) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 697 | return; /* already live */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 698 | } else if (s_reg != INVALID_SREG) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 699 | ClobberSReg(s_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 700 | if (info->is_temp) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 701 | info->live = true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 702 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 703 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 704 | /* Can't be live if no associated s_reg */ |
| 705 | DCHECK(info->is_temp); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 706 | info->live = false; |
| 707 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 708 | info->s_reg = s_reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 709 | } |
| 710 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 711 | void Mir2Lir::MarkTemp(int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 712 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 713 | RegisterInfo* info = GetRegInfo(reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 714 | info->is_temp = true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 715 | } |
| 716 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 717 | void Mir2Lir::UnmarkTemp(int reg) |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 718 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 719 | RegisterInfo* info = GetRegInfo(reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 720 | info->is_temp = false; |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 721 | } |
| 722 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 723 | void Mir2Lir::MarkPair(int low_reg, int high_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 724 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 725 | RegisterInfo* info_lo = GetRegInfo(low_reg); |
| 726 | RegisterInfo* info_hi = GetRegInfo(high_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 727 | info_lo->pair = info_hi->pair = true; |
| 728 | info_lo->partner = high_reg; |
| 729 | info_hi->partner = low_reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 730 | } |
| 731 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 732 | void Mir2Lir::MarkClean(RegLocation loc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 733 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 734 | RegisterInfo* info = GetRegInfo(loc.low_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 735 | info->dirty = false; |
| 736 | if (loc.wide) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 737 | info = GetRegInfo(loc.high_reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 738 | info->dirty = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 739 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 740 | } |
| 741 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 742 | void Mir2Lir::MarkDirty(RegLocation loc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 743 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 744 | if (loc.home) { |
| 745 | // If already home, can't be dirty |
| 746 | return; |
| 747 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 748 | RegisterInfo* info = GetRegInfo(loc.low_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 749 | info->dirty = true; |
| 750 | if (loc.wide) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 751 | info = GetRegInfo(loc.high_reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 752 | info->dirty = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 753 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 754 | } |
| 755 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 756 | void Mir2Lir::MarkInUse(int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 757 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 758 | RegisterInfo* info = GetRegInfo(reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 759 | info->in_use = true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 760 | } |
| 761 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 762 | void Mir2Lir::CopyRegInfo(int new_reg, int old_reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 763 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 764 | RegisterInfo* new_info = GetRegInfo(new_reg); |
| 765 | RegisterInfo* old_info = GetRegInfo(old_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 766 | // Target temp status must not change |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 767 | bool is_temp = new_info->is_temp; |
| 768 | *new_info = *old_info; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 769 | // Restore target's temp status |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 770 | new_info->is_temp = is_temp; |
| 771 | new_info->reg = new_reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 772 | } |
| 773 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 774 | bool Mir2Lir::CheckCorePoolSanity() |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 775 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 776 | for (static int i = 0; i < reg_pool_->num_core_regs; i++) { |
| 777 | if (reg_pool_->core_regs[i].pair) { |
| 778 | static int my_reg = reg_pool_->core_regs[i].reg; |
| 779 | static int my_sreg = reg_pool_->core_regs[i].s_reg; |
| 780 | static int partner_reg = reg_pool_->core_regs[i].partner; |
| 781 | static RegisterInfo* partner = GetRegInfo(partner_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 782 | DCHECK(partner != NULL); |
| 783 | DCHECK(partner->pair); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 784 | DCHECK_EQ(my_reg, partner->partner); |
| 785 | static int partner_sreg = partner->s_reg; |
| 786 | if (my_sreg == INVALID_SREG) { |
| 787 | DCHECK_EQ(partner_sreg, INVALID_SREG); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 788 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 789 | int diff = my_sreg - partner_sreg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 790 | DCHECK((diff == -1) || (diff == 1)); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 791 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 792 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 793 | if (!reg_pool_->core_regs[i].live) { |
| 794 | DCHECK(reg_pool_->core_regs[i].def_start == NULL); |
| 795 | DCHECK(reg_pool_->core_regs[i].def_end == NULL); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 796 | } |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 797 | } |
| 798 | return true; |
| 799 | } |
| 800 | |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 801 | /* |
| 802 | * Return an updated location record with current in-register status. |
| 803 | * If the value lives in live temps, reflect that fact. No code |
| 804 | * is generated. If the live value is part of an older pair, |
| 805 | * clobber both low and high. |
| 806 | * TUNING: clobbering both is a bit heavy-handed, but the alternative |
| 807 | * is a bit complex when dealing with FP regs. Examine code to see |
| 808 | * if it's worthwhile trying to be more clever here. |
| 809 | */ |
| 810 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 811 | RegLocation Mir2Lir::UpdateLoc(RegLocation loc) |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 812 | { |
| 813 | DCHECK(!loc.wide); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 814 | DCHECK(CheckCorePoolSanity()); |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 815 | if (loc.location != kLocPhysReg) { |
| 816 | DCHECK((loc.location == kLocDalvikFrame) || |
| 817 | (loc.location == kLocCompilerTemp)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 818 | RegisterInfo* info_lo = AllocLive(loc.s_reg_low, kAnyReg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 819 | if (info_lo) { |
| 820 | if (info_lo->pair) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 821 | Clobber(info_lo->reg); |
| 822 | Clobber(info_lo->partner); |
| 823 | FreeTemp(info_lo->reg); |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 824 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 825 | loc.low_reg = info_lo->reg; |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 826 | loc.location = kLocPhysReg; |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | return loc; |
| 832 | } |
| 833 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 834 | /* see comments for update_loc */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 835 | RegLocation Mir2Lir::UpdateLocWide(RegLocation loc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 836 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 837 | DCHECK(loc.wide); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 838 | DCHECK(CheckCorePoolSanity()); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 839 | if (loc.location != kLocPhysReg) { |
| 840 | DCHECK((loc.location == kLocDalvikFrame) || |
| 841 | (loc.location == kLocCompilerTemp)); |
| 842 | // Are the dalvik regs already live in physical registers? |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 843 | RegisterInfo* info_lo = AllocLive(loc.s_reg_low, kAnyReg); |
| 844 | RegisterInfo* info_hi = AllocLive(GetSRegHi(loc.s_reg_low), kAnyReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 845 | bool match = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 846 | match = match && (info_lo != NULL); |
| 847 | match = match && (info_hi != NULL); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 848 | // Are they both core or both FP? |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 849 | match = match && (IsFpReg(info_lo->reg) == IsFpReg(info_hi->reg)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 850 | // If a pair of floating point singles, are they properly aligned? |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 851 | if (match && IsFpReg(info_lo->reg)) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 852 | match &= ((info_lo->reg & 0x1) == 0); |
| 853 | match &= ((info_hi->reg - info_lo->reg) == 1); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 854 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 855 | // If previously used as a pair, it is the same pair? |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 856 | if (match && (info_lo->pair || info_hi->pair)) { |
| 857 | match = (info_lo->pair == info_hi->pair); |
| 858 | match &= ((info_lo->reg == info_hi->partner) && |
| 859 | (info_hi->reg == info_lo->partner)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 860 | } |
| 861 | if (match) { |
| 862 | // Can reuse - update the register usage info |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 863 | loc.low_reg = info_lo->reg; |
| 864 | loc.high_reg = info_hi->reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 865 | loc.location = kLocPhysReg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 866 | MarkPair(loc.low_reg, loc.high_reg); |
| 867 | DCHECK(!IsFpReg(loc.low_reg) || ((loc.low_reg & 0x1) == 0)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 868 | return loc; |
| 869 | } |
| 870 | // Can't easily reuse - clobber and free any overlaps |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 871 | if (info_lo) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 872 | Clobber(info_lo->reg); |
| 873 | FreeTemp(info_lo->reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 874 | if (info_lo->pair) |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 875 | Clobber(info_lo->partner); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 876 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 877 | if (info_hi) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 878 | Clobber(info_hi->reg); |
| 879 | FreeTemp(info_hi->reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 880 | if (info_hi->pair) |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 881 | Clobber(info_hi->partner); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | return loc; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 885 | } |
| 886 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 887 | |
| 888 | /* For use in cases we don't know (or care) width */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 889 | RegLocation Mir2Lir::UpdateRawLoc(RegLocation loc) |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 890 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 891 | if (loc.wide) |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 892 | return UpdateLocWide(loc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 893 | else |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 894 | return UpdateLoc(loc); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 895 | } |
| 896 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 897 | RegLocation Mir2Lir::EvalLocWide(RegLocation loc, int reg_class, bool update) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 898 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 899 | DCHECK(loc.wide); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 900 | int new_regs; |
| 901 | int low_reg; |
| 902 | int high_reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 903 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 904 | loc = UpdateLocWide(loc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 905 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 906 | /* If already in registers, we can assume proper form. Right reg class? */ |
| 907 | if (loc.location == kLocPhysReg) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 908 | DCHECK_EQ(IsFpReg(loc.low_reg), IsFpReg(loc.high_reg)); |
| 909 | DCHECK(!IsFpReg(loc.low_reg) || ((loc.low_reg & 0x1) == 0)); |
| 910 | if (!RegClassMatches(reg_class, loc.low_reg)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 911 | /* Wrong register class. Reallocate and copy */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 912 | new_regs = AllocTypedTempPair(loc.fp, reg_class); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 913 | low_reg = new_regs & 0xff; |
| 914 | high_reg = (new_regs >> 8) & 0xff; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 915 | OpRegCopyWide(low_reg, high_reg, loc.low_reg, loc.high_reg); |
| 916 | CopyRegInfo(low_reg, loc.low_reg); |
| 917 | CopyRegInfo(high_reg, loc.high_reg); |
| 918 | Clobber(loc.low_reg); |
| 919 | Clobber(loc.high_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 920 | loc.low_reg = low_reg; |
| 921 | loc.high_reg = high_reg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 922 | MarkPair(loc.low_reg, loc.high_reg); |
| 923 | DCHECK(!IsFpReg(loc.low_reg) || ((loc.low_reg & 0x1) == 0)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 924 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 925 | return loc; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 926 | } |
| 927 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 928 | DCHECK_NE(loc.s_reg_low, INVALID_SREG); |
| 929 | DCHECK_NE(GetSRegHi(loc.s_reg_low), INVALID_SREG); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 930 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 931 | new_regs = AllocTypedTempPair(loc.fp, reg_class); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 932 | loc.low_reg = new_regs & 0xff; |
| 933 | loc.high_reg = (new_regs >> 8) & 0xff; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 934 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 935 | MarkPair(loc.low_reg, loc.high_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 936 | if (update) { |
| 937 | loc.location = kLocPhysReg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 938 | MarkLive(loc.low_reg, loc.s_reg_low); |
| 939 | MarkLive(loc.high_reg, GetSRegHi(loc.s_reg_low)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 940 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 941 | DCHECK(!IsFpReg(loc.low_reg) || ((loc.low_reg & 0x1) == 0)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 942 | return loc; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 943 | } |
| 944 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 945 | RegLocation Mir2Lir::EvalLoc(RegLocation loc, int reg_class, bool update) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 946 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 947 | int new_reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 948 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 949 | if (loc.wide) |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 950 | return EvalLocWide(loc, reg_class, update); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 951 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 952 | loc = UpdateLoc(loc); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 953 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 954 | if (loc.location == kLocPhysReg) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 955 | if (!RegClassMatches(reg_class, loc.low_reg)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 956 | /* Wrong register class. Realloc, copy and transfer ownership */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 957 | new_reg = AllocTypedTemp(loc.fp, reg_class); |
| 958 | OpRegCopy(new_reg, loc.low_reg); |
| 959 | CopyRegInfo(new_reg, loc.low_reg); |
| 960 | Clobber(loc.low_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 961 | loc.low_reg = new_reg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 962 | } |
| 963 | return loc; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 964 | } |
| 965 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 966 | DCHECK_NE(loc.s_reg_low, INVALID_SREG); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 967 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 968 | new_reg = AllocTypedTemp(loc.fp, reg_class); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 969 | loc.low_reg = new_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 970 | |
| 971 | if (update) { |
| 972 | loc.location = kLocPhysReg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 973 | MarkLive(loc.low_reg, loc.s_reg_low); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 974 | } |
| 975 | return loc; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 976 | } |
| 977 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 978 | /* USE SSA names to count references of base Dalvik v_regs. */ |
buzbee | b0245ae | 2013-04-02 15:33:54 -0700 | [diff] [blame] | 979 | void Mir2Lir::CountRefs(RefCounts* core_counts, RefCounts* fp_counts) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 980 | for (int i = 0; i < mir_graph_->GetNumSSARegs(); i++) { |
| 981 | RegLocation loc = mir_graph_->reg_location_[i]; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 982 | RefCounts* counts = loc.fp ? fp_counts : core_counts; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 983 | int p_map_idx = SRegToPMap(loc.s_reg_low); |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 984 | //Don't count easily regenerated immediates |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 985 | if (loc.fp || !IsInexpensiveConstant(loc)) { |
| 986 | counts[p_map_idx].count += mir_graph_->GetUseCount(i); |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 987 | } |
buzbee | c7d1f91 | 2013-02-07 15:22:39 -0800 | [diff] [blame] | 988 | if (loc.wide && loc.fp && !loc.high_word) { |
| 989 | counts[p_map_idx].double_start = true; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 990 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 991 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | /* qsort callback function, sort descending */ |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 995 | static int SortCounts(const void *val1, const void *val2) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 996 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 997 | const Mir2Lir::RefCounts* op1 = reinterpret_cast<const Mir2Lir::RefCounts*>(val1); |
| 998 | const Mir2Lir::RefCounts* op2 = reinterpret_cast<const Mir2Lir::RefCounts*>(val2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 999 | return (op1->count == op2->count) ? 0 : (op1->count < op2->count ? 1 : -1); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1002 | void Mir2Lir::DumpCounts(const RefCounts* arr, int size, const char* msg) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1003 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1004 | LOG(INFO) << msg; |
| 1005 | for (int i = 0; i < size; i++) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1006 | LOG(INFO) << "s_reg[" << arr[i].s_reg << "]: " << arr[i].count; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1007 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | /* |
| 1011 | * Note: some portions of this code required even if the kPromoteRegs |
| 1012 | * optimization is disabled. |
| 1013 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1014 | void Mir2Lir::DoPromotion() |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1015 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1016 | int reg_bias = cu_->num_compiler_temps + 1; |
| 1017 | int dalvik_regs = cu_->num_dalvik_registers; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1018 | int num_regs = dalvik_regs + reg_bias; |
buzbee | b0245ae | 2013-04-02 15:33:54 -0700 | [diff] [blame] | 1019 | const int promotion_threshold = 1; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1020 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1021 | // Allow target code to add any special registers |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1022 | AdjustSpillMask(); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1023 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1024 | /* |
| 1025 | * Simple register promotion. Just do a static count of the uses |
| 1026 | * of Dalvik registers. Note that we examine the SSA names, but |
| 1027 | * count based on original Dalvik register name. Count refs |
| 1028 | * separately based on type in order to give allocation |
| 1029 | * preference to fp doubles - which must be allocated sequential |
| 1030 | * physical single fp registers started with an even-numbered |
| 1031 | * reg. |
| 1032 | * TUNING: replace with linear scan once we have the ability |
| 1033 | * to describe register live ranges for GC. |
| 1034 | */ |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 1035 | RefCounts *core_regs = |
| 1036 | static_cast<RefCounts*>(arena_->NewMem(sizeof(RefCounts) * num_regs, true, |
| 1037 | ArenaAllocator::kAllocRegAlloc)); |
| 1038 | RefCounts *FpRegs = |
| 1039 | static_cast<RefCounts *>(arena_->NewMem(sizeof(RefCounts) * num_regs, true, |
| 1040 | ArenaAllocator::kAllocRegAlloc)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1041 | // Set ssa names for original Dalvik registers |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1042 | for (int i = 0; i < dalvik_regs; i++) { |
| 1043 | core_regs[i].s_reg = FpRegs[i].s_reg = i; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1044 | } |
| 1045 | // Set ssa name for Method* |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1046 | core_regs[dalvik_regs].s_reg = mir_graph_->GetMethodSReg(); |
| 1047 | FpRegs[dalvik_regs].s_reg = mir_graph_->GetMethodSReg(); // For consistecy |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1048 | // Set ssa names for compiler_temps |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1049 | for (int i = 1; i <= cu_->num_compiler_temps; i++) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 1050 | CompilerTemp* ct = mir_graph_->compiler_temps_.Get(i); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1051 | core_regs[dalvik_regs + i].s_reg = ct->s_reg; |
| 1052 | FpRegs[dalvik_regs + i].s_reg = ct->s_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
buzbee | b0245ae | 2013-04-02 15:33:54 -0700 | [diff] [blame] | 1055 | // Sum use counts of SSA regs by original Dalvik vreg. |
| 1056 | CountRefs(core_regs, FpRegs); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1057 | |
| 1058 | /* |
| 1059 | * Ideally, we'd allocate doubles starting with an even-numbered |
| 1060 | * register. Bias the counts to try to allocate any vreg that's |
| 1061 | * used as the start of a pair first. |
| 1062 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1063 | for (int i = 0; i < num_regs; i++) { |
| 1064 | if (FpRegs[i].double_start) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 1065 | FpRegs[i].count *= 2; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1066 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | // Sort the count arrays |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1070 | qsort(core_regs, num_regs, sizeof(RefCounts), SortCounts); |
| 1071 | qsort(FpRegs, num_regs, sizeof(RefCounts), SortCounts); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1072 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1073 | if (cu_->verbose) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1074 | DumpCounts(core_regs, num_regs, "Core regs after sort"); |
| 1075 | DumpCounts(FpRegs, num_regs, "Fp regs after sort"); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1078 | if (!(cu_->disable_opt & (1 << kPromoteRegs))) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 1079 | // Promote FpRegs |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1080 | for (int i = 0; (i < num_regs) && |
| 1081 | (FpRegs[i].count >= promotion_threshold ); i++) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1082 | int p_map_idx = SRegToPMap(FpRegs[i].s_reg); |
| 1083 | if (promotion_map_[p_map_idx].fp_location != kLocPhysReg) { |
| 1084 | int reg = AllocPreservedFPReg(FpRegs[i].s_reg, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1085 | FpRegs[i].double_start); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1086 | if (reg < 0) { |
| 1087 | break; // No more left |
| 1088 | } |
| 1089 | } |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 1090 | } |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 1091 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1092 | // Promote core regs |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1093 | for (int i = 0; (i < num_regs) && |
buzbee | b0245ae | 2013-04-02 15:33:54 -0700 | [diff] [blame] | 1094 | (core_regs[i].count >= promotion_threshold); i++) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1095 | int p_map_idx = SRegToPMap(core_regs[i].s_reg); |
| 1096 | if (promotion_map_[p_map_idx].core_location != |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1097 | kLocPhysReg) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1098 | int reg = AllocPreservedCoreReg(core_regs[i].s_reg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1099 | if (reg < 0) { |
| 1100 | break; // No more left |
| 1101 | } |
| 1102 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1103 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1104 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1105 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1106 | // Now, update SSA names to new home locations |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1107 | for (int i = 0; i < mir_graph_->GetNumSSARegs(); i++) { |
| 1108 | RegLocation *curr = &mir_graph_->reg_location_[i]; |
| 1109 | int p_map_idx = SRegToPMap(curr->s_reg_low); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1110 | if (!curr->wide) { |
| 1111 | if (curr->fp) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1112 | if (promotion_map_[p_map_idx].fp_location == kLocPhysReg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1113 | curr->location = kLocPhysReg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1114 | curr->low_reg = promotion_map_[p_map_idx].FpReg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1115 | curr->home = true; |
| 1116 | } |
| 1117 | } else { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1118 | if (promotion_map_[p_map_idx].core_location == kLocPhysReg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1119 | curr->location = kLocPhysReg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1120 | curr->low_reg = promotion_map_[p_map_idx].core_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1121 | curr->home = true; |
| 1122 | } |
| 1123 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1124 | curr->high_reg = INVALID_REG; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1125 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1126 | if (curr->high_word) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1127 | continue; |
| 1128 | } |
| 1129 | if (curr->fp) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1130 | if ((promotion_map_[p_map_idx].fp_location == kLocPhysReg) && |
| 1131 | (promotion_map_[p_map_idx+1].fp_location == |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1132 | kLocPhysReg)) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1133 | int low_reg = promotion_map_[p_map_idx].FpReg; |
| 1134 | int high_reg = promotion_map_[p_map_idx+1].FpReg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1135 | // Doubles require pair of singles starting at even reg |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1136 | if (((low_reg & 0x1) == 0) && ((low_reg + 1) == high_reg)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1137 | curr->location = kLocPhysReg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 1138 | curr->low_reg = low_reg; |
| 1139 | curr->high_reg = high_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1140 | curr->home = true; |
| 1141 | } |
| 1142 | } |
| 1143 | } else { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1144 | if ((promotion_map_[p_map_idx].core_location == kLocPhysReg) |
| 1145 | && (promotion_map_[p_map_idx+1].core_location == |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1146 | kLocPhysReg)) { |
| 1147 | curr->location = kLocPhysReg; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1148 | curr->low_reg = promotion_map_[p_map_idx].core_reg; |
| 1149 | curr->high_reg = promotion_map_[p_map_idx+1].core_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1150 | curr->home = true; |
| 1151 | } |
| 1152 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1153 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1154 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1155 | if (cu_->verbose) { |
| 1156 | DumpPromotionMap(); |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 1157 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /* Returns sp-relative offset in bytes for a VReg */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1161 | int Mir2Lir::VRegOffset(int v_reg) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1162 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1163 | return StackVisitor::GetVRegOffset(cu_->code_item, core_spill_mask_, |
| 1164 | fp_spill_mask_, frame_size_, v_reg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | /* Returns sp-relative offset in bytes for a SReg */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1168 | int Mir2Lir::SRegOffset(int s_reg) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1169 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1170 | return VRegOffset(mir_graph_->SRegToVReg(s_reg)); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /* Mark register usage state and return long retloc */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1174 | RegLocation Mir2Lir::GetReturnWide(bool is_double) |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1175 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1176 | RegLocation gpr_res = LocCReturnWide(); |
| 1177 | RegLocation fpr_res = LocCReturnDouble(); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1178 | RegLocation res = is_double ? fpr_res : gpr_res; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1179 | Clobber(res.low_reg); |
| 1180 | Clobber(res.high_reg); |
| 1181 | LockTemp(res.low_reg); |
| 1182 | LockTemp(res.high_reg); |
| 1183 | MarkPair(res.low_reg, res.high_reg); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1184 | return res; |
| 1185 | } |
| 1186 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1187 | RegLocation Mir2Lir::GetReturn(bool is_float) |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1188 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1189 | RegLocation gpr_res = LocCReturn(); |
| 1190 | RegLocation fpr_res = LocCReturnFloat(); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1191 | RegLocation res = is_float ? fpr_res : gpr_res; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1192 | Clobber(res.low_reg); |
| 1193 | if (cu_->instruction_set == kMips) { |
| 1194 | MarkInUse(res.low_reg); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1195 | } else { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1196 | LockTemp(res.low_reg); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 1197 | } |
| 1198 | return res; |
| 1199 | } |
| 1200 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1201 | void Mir2Lir::SimpleRegAlloc() |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1202 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1203 | DoPromotion(); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1204 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1205 | if (cu_->verbose && !(cu_->disable_opt & (1 << kPromoteRegs))) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1206 | LOG(INFO) << "After Promotion"; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1207 | mir_graph_->DumpRegLocTable(mir_graph_->reg_location_, mir_graph_->GetNumSSARegs()); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | /* Set the frame size */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1211 | frame_size_ = ComputeFrameSize(); |
| 1212 | } |
| 1213 | |
| 1214 | /* |
| 1215 | * Get the "real" sreg number associated with an s_reg slot. In general, |
| 1216 | * s_reg values passed through codegen are the SSA names created by |
| 1217 | * dataflow analysis and refer to slot numbers in the mir_graph_->reg_location |
| 1218 | * array. However, renaming is accomplished by simply replacing RegLocation |
| 1219 | * entries in the reglocation[] array. Therefore, when location |
| 1220 | * records for operands are first created, we need to ask the locRecord |
| 1221 | * identified by the dataflow pass what it's new name is. |
| 1222 | */ |
| 1223 | int Mir2Lir::GetSRegHi(int lowSreg) { |
| 1224 | return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1; |
| 1225 | } |
| 1226 | |
| 1227 | bool Mir2Lir::oat_live_out(int s_reg) { |
| 1228 | //For now. |
| 1229 | return true; |
| 1230 | } |
| 1231 | |
| 1232 | int Mir2Lir::oatSSASrc(MIR* mir, int num) { |
| 1233 | DCHECK_GT(mir->ssa_rep->num_uses, num); |
| 1234 | return mir->ssa_rep->uses[num]; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 1237 | } // namespace art |