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