blob: 64555724705ca30e8e93c9bc7e075bc51435da79 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
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
17/* This file contains register alloction support. */
18
19#include "dex/compiler_ir.h"
20#include "dex/compiler_internals.h"
21#include "mir_to_lir-inl.h"
22
23namespace art {
24
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 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070030void Mir2Lir::ResetRegPool() {
buzbeebd663de2013-09-10 15:41:31 -070031 GrowableArray<RegisterInfo*>::Iterator iter(&tempreg_info_);
32 for (RegisterInfo* info = iter.Next(); info != NULL; info = iter.Next()) {
33 info->in_use = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -070034 }
35 // Reset temp tracking sanity check.
36 if (kIsDebugBuild) {
37 live_sreg_ = INVALID_SREG;
38 }
39}
40
41 /*
42 * Set up temp & preserved register pools specialized by target.
43 * Note: num_regs may be zero.
44 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070045void Mir2Lir::CompilerInitPool(RegisterInfo* regs, int* reg_nums, int num) {
Brian Carlstrom38f85e42013-07-18 14:45:22 -070046 for (int i = 0; i < num; i++) {
buzbeebd663de2013-09-10 15:41:31 -070047 uint32_t reg_number = reg_nums[i];
48 regs[i].reg = reg_number;
Brian Carlstrom7940e442013-07-12 13:46:57 -070049 regs[i].in_use = false;
50 regs[i].is_temp = false;
51 regs[i].pair = false;
52 regs[i].live = false;
53 regs[i].dirty = false;
54 regs[i].s_reg = INVALID_SREG;
buzbeebd663de2013-09-10 15:41:31 -070055 size_t map_size = reginfo_map_.Size();
56 if (reg_number >= map_size) {
57 for (uint32_t i = 0; i < ((reg_number - map_size) + 1); i++) {
58 reginfo_map_.Insert(NULL);
59 }
60 }
61 reginfo_map_.Put(reg_number, &regs[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -070062 }
63}
64
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070065void Mir2Lir::DumpRegPool(RegisterInfo* p, int num_regs) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070066 LOG(INFO) << "================================================";
67 for (int i = 0; i < num_regs; i++) {
68 LOG(INFO) << StringPrintf(
buzbee0d829482013-10-11 15:24:55 -070069 "R[%d]: T:%d, U:%d, P:%d, p:%d, LV:%d, D:%d, SR:%d",
Brian Carlstrom7940e442013-07-12 13:46:57 -070070 p[i].reg, p[i].is_temp, p[i].in_use, p[i].pair, p[i].partner,
buzbee0d829482013-10-11 15:24:55 -070071 p[i].live, p[i].dirty, p[i].s_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070072 }
73 LOG(INFO) << "================================================";
74}
75
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070076void Mir2Lir::DumpCoreRegPool() {
Brian Carlstrom7940e442013-07-12 13:46:57 -070077 DumpRegPool(reg_pool_->core_regs, reg_pool_->num_core_regs);
78}
79
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070080void Mir2Lir::DumpFpRegPool() {
Brian Carlstrom7940e442013-07-12 13:46:57 -070081 DumpRegPool(reg_pool_->FPRegs, reg_pool_->num_fp_regs);
82}
83
buzbee2700f7e2014-03-07 09:46:20 -080084void Mir2Lir::Clobber(RegStorage reg) {
85 if (reg.IsPair()) {
86 ClobberBody(GetRegInfo(reg.GetLowReg()));
87 ClobberBody(GetRegInfo(reg.GetHighReg()));
88 } else {
89 ClobberBody(GetRegInfo(reg.GetReg()));
90 }
91}
92
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070093void Mir2Lir::ClobberSRegBody(RegisterInfo* p, int num_regs, int s_reg) {
Brian Carlstrom38f85e42013-07-18 14:45:22 -070094 for (int i = 0; i< num_regs; i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070095 if (p[i].s_reg == s_reg) {
96 if (p[i].is_temp) {
97 p[i].live = false;
98 }
99 p[i].def_start = NULL;
100 p[i].def_end = NULL;
101 }
102 }
103}
104
105/*
106 * Break the association between a Dalvik vreg and a physical temp register of either register
107 * class.
108 * TODO: Ideally, the public version of this code should not exist. Besides its local usage
109 * in the register utilities, is is also used by code gen routines to work around a deficiency in
110 * local register allocation, which fails to distinguish between the "in" and "out" identities
111 * of Dalvik vregs. This can result in useless register copies when the same Dalvik vreg
112 * is used both as the source and destination register of an operation in which the type
113 * changes (for example: INT_TO_FLOAT v1, v1). Revisit when improved register allocation is
114 * addressed.
115 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700116void Mir2Lir::ClobberSReg(int s_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117 /* Reset live temp tracking sanity checker */
118 if (kIsDebugBuild) {
119 if (s_reg == live_sreg_) {
120 live_sreg_ = INVALID_SREG;
121 }
122 }
123 ClobberSRegBody(reg_pool_->core_regs, reg_pool_->num_core_regs, s_reg);
124 ClobberSRegBody(reg_pool_->FPRegs, reg_pool_->num_fp_regs, s_reg);
125}
126
127/*
128 * SSA names associated with the initial definitions of Dalvik
129 * registers are the same as the Dalvik register number (and
130 * thus take the same position in the promotion_map. However,
131 * the special Method* and compiler temp resisters use negative
132 * v_reg numbers to distinguish them and can have an arbitrary
133 * ssa name (above the last original Dalvik register). This function
134 * maps SSA names to positions in the promotion_map array.
135 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700136int Mir2Lir::SRegToPMap(int s_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700137 DCHECK_LT(s_reg, mir_graph_->GetNumSSARegs());
138 DCHECK_GE(s_reg, 0);
139 int v_reg = mir_graph_->SRegToVReg(s_reg);
140 if (v_reg >= 0) {
141 DCHECK_LT(v_reg, cu_->num_dalvik_registers);
142 return v_reg;
143 } else {
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800144 /*
145 * It must be the case that the v_reg for temporary is less than or equal to the
146 * base reg for temps. For that reason, "position" must be zero or positive.
147 */
148 unsigned int position = std::abs(v_reg) - std::abs(static_cast<int>(kVRegTempBaseReg));
149
150 // The temporaries are placed after dalvik registers in the promotion map
151 DCHECK_LT(position, mir_graph_->GetNumUsedCompilerTemps());
152 return cu_->num_dalvik_registers + position;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700153 }
154}
155
buzbee2700f7e2014-03-07 09:46:20 -0800156void Mir2Lir::RecordCorePromotion(RegStorage reg, int s_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700157 int p_map_idx = SRegToPMap(s_reg);
158 int v_reg = mir_graph_->SRegToVReg(s_reg);
buzbee2700f7e2014-03-07 09:46:20 -0800159 int reg_num = reg.GetReg();
160 GetRegInfo(reg_num)->in_use = true;
161 core_spill_mask_ |= (1 << reg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 // Include reg for later sort
buzbee2700f7e2014-03-07 09:46:20 -0800163 core_vmap_table_.push_back(reg_num << VREG_NUM_WIDTH | (v_reg & ((1 << VREG_NUM_WIDTH) - 1)));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700164 num_core_spills_++;
165 promotion_map_[p_map_idx].core_location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800166 promotion_map_[p_map_idx].core_reg = reg_num;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700167}
168
169/* Reserve a callee-save register. Return -1 if none available */
buzbee2700f7e2014-03-07 09:46:20 -0800170RegStorage Mir2Lir::AllocPreservedCoreReg(int s_reg) {
171 RegStorage res;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700172 RegisterInfo* core_regs = reg_pool_->core_regs;
173 for (int i = 0; i < reg_pool_->num_core_regs; i++) {
174 if (!core_regs[i].is_temp && !core_regs[i].in_use) {
buzbee2700f7e2014-03-07 09:46:20 -0800175 res = RegStorage::Solo32(core_regs[i].reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700176 RecordCorePromotion(res, s_reg);
177 break;
178 }
179 }
180 return res;
181}
182
buzbee2700f7e2014-03-07 09:46:20 -0800183void Mir2Lir::RecordFpPromotion(RegStorage reg, int s_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700184 int p_map_idx = SRegToPMap(s_reg);
185 int v_reg = mir_graph_->SRegToVReg(s_reg);
buzbee2700f7e2014-03-07 09:46:20 -0800186 int reg_num = reg.GetReg();
187 GetRegInfo(reg_num)->in_use = true;
188 MarkPreservedSingle(v_reg, reg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700189 promotion_map_[p_map_idx].fp_location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800190 promotion_map_[p_map_idx].FpReg = reg_num;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700191}
192
buzbeec729a6b2013-09-14 16:04:31 -0700193// Reserve a callee-save fp single register.
buzbee2700f7e2014-03-07 09:46:20 -0800194RegStorage Mir2Lir::AllocPreservedSingle(int s_reg) {
195 RegStorage res;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700196 RegisterInfo* FPRegs = reg_pool_->FPRegs;
197 for (int i = 0; i < reg_pool_->num_fp_regs; i++) {
buzbeec729a6b2013-09-14 16:04:31 -0700198 if (!FPRegs[i].is_temp && !FPRegs[i].in_use) {
buzbee2700f7e2014-03-07 09:46:20 -0800199 res = RegStorage::Solo32(FPRegs[i].reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700200 RecordFpPromotion(res, s_reg);
201 break;
202 }
203 }
204 return res;
205}
206
207/*
208 * Somewhat messy code here. We want to allocate a pair of contiguous
209 * physical single-precision floating point registers starting with
210 * an even numbered reg. It is possible that the paired s_reg (s_reg+1)
211 * has already been allocated - try to fit if possible. Fail to
212 * allocate if we can't meet the requirements for the pair of
213 * s_reg<=sX[even] & (s_reg+1)<= sX+1.
214 */
buzbee2700f7e2014-03-07 09:46:20 -0800215// TODO: needs rewrite to support non-backed 64-bit float regs.
216RegStorage Mir2Lir::AllocPreservedDouble(int s_reg) {
217 RegStorage res;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700218 int v_reg = mir_graph_->SRegToVReg(s_reg);
219 int p_map_idx = SRegToPMap(s_reg);
220 if (promotion_map_[p_map_idx+1].fp_location == kLocPhysReg) {
221 // Upper reg is already allocated. Can we fit?
222 int high_reg = promotion_map_[p_map_idx+1].FpReg;
223 if ((high_reg & 1) == 0) {
224 // High reg is even - fail.
buzbee2700f7e2014-03-07 09:46:20 -0800225 return res; // Invalid.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700226 }
227 // Is the low reg of the pair free?
228 RegisterInfo* p = GetRegInfo(high_reg-1);
229 if (p->in_use || p->is_temp) {
230 // Already allocated or not preserved - fail.
buzbee2700f7e2014-03-07 09:46:20 -0800231 return res; // Invalid.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700232 }
233 // OK - good to go.
buzbee2700f7e2014-03-07 09:46:20 -0800234 res = RegStorage(RegStorage::k64BitPair, p->reg, p->reg + 1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700235 p->in_use = true;
buzbee2700f7e2014-03-07 09:46:20 -0800236 DCHECK_EQ((res.GetReg() & 1), 0);
237 MarkPreservedSingle(v_reg, res.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700238 } else {
239 RegisterInfo* FPRegs = reg_pool_->FPRegs;
240 for (int i = 0; i < reg_pool_->num_fp_regs; i++) {
241 if (!FPRegs[i].is_temp && !FPRegs[i].in_use &&
242 ((FPRegs[i].reg & 0x1) == 0x0) &&
243 !FPRegs[i+1].is_temp && !FPRegs[i+1].in_use &&
244 ((FPRegs[i+1].reg & 0x1) == 0x1) &&
245 (FPRegs[i].reg + 1) == FPRegs[i+1].reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800246 res = RegStorage(RegStorage::k64BitPair, FPRegs[i].reg, FPRegs[i].reg+1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700247 FPRegs[i].in_use = true;
buzbee2700f7e2014-03-07 09:46:20 -0800248 MarkPreservedSingle(v_reg, res.GetLowReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700249 FPRegs[i+1].in_use = true;
buzbee2700f7e2014-03-07 09:46:20 -0800250 DCHECK_EQ(res.GetLowReg() + 1, FPRegs[i+1].reg);
251 MarkPreservedSingle(v_reg+1, res.GetLowReg() + 1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700252 break;
253 }
254 }
255 }
buzbee2700f7e2014-03-07 09:46:20 -0800256 if (res.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700257 promotion_map_[p_map_idx].fp_location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800258 promotion_map_[p_map_idx].FpReg = res.GetLowReg();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700259 promotion_map_[p_map_idx+1].fp_location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800260 promotion_map_[p_map_idx+1].FpReg = res.GetLowReg() + 1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700261 }
262 return res;
263}
264
buzbee2700f7e2014-03-07 09:46:20 -0800265RegStorage Mir2Lir::AllocTempBody(RegisterInfo* p, int num_regs, int* next_temp,
266 bool required) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700267 int next = *next_temp;
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700268 for (int i = 0; i< num_regs; i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700269 if (next >= num_regs)
270 next = 0;
271 if (p[next].is_temp && !p[next].in_use && !p[next].live) {
272 Clobber(p[next].reg);
273 p[next].in_use = true;
274 p[next].pair = false;
275 *next_temp = next + 1;
buzbee2700f7e2014-03-07 09:46:20 -0800276 return RegStorage::Solo32(p[next].reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700277 }
278 next++;
279 }
280 next = *next_temp;
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700281 for (int i = 0; i< num_regs; i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700282 if (next >= num_regs)
283 next = 0;
284 if (p[next].is_temp && !p[next].in_use) {
285 Clobber(p[next].reg);
286 p[next].in_use = true;
287 p[next].pair = false;
288 *next_temp = next + 1;
buzbee2700f7e2014-03-07 09:46:20 -0800289 return RegStorage::Solo32(p[next].reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700290 }
291 next++;
292 }
293 if (required) {
294 CodegenDump();
295 DumpRegPool(reg_pool_->core_regs,
296 reg_pool_->num_core_regs);
297 LOG(FATAL) << "No free temp registers";
298 }
buzbee2700f7e2014-03-07 09:46:20 -0800299 return RegStorage::InvalidReg(); // No register available
Brian Carlstrom7940e442013-07-12 13:46:57 -0700300}
301
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700302// REDO: too many assumptions.
buzbee2700f7e2014-03-07 09:46:20 -0800303// Virtualize - this is target dependent.
304RegStorage Mir2Lir::AllocTempDouble() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700305 RegisterInfo* p = reg_pool_->FPRegs;
306 int num_regs = reg_pool_->num_fp_regs;
307 /* Start looking at an even reg */
308 int next = reg_pool_->next_fp_reg & ~0x1;
309
310 // First try to avoid allocating live registers
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700311 for (int i = 0; i < num_regs; i+=2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700312 if (next >= num_regs)
313 next = 0;
314 if ((p[next].is_temp && !p[next].in_use && !p[next].live) &&
315 (p[next+1].is_temp && !p[next+1].in_use && !p[next+1].live)) {
316 Clobber(p[next].reg);
317 Clobber(p[next+1].reg);
318 p[next].in_use = true;
319 p[next+1].in_use = true;
320 DCHECK_EQ((p[next].reg+1), p[next+1].reg);
321 DCHECK_EQ((p[next].reg & 0x1), 0);
322 reg_pool_->next_fp_reg = next + 2;
323 if (reg_pool_->next_fp_reg >= num_regs) {
324 reg_pool_->next_fp_reg = 0;
325 }
buzbee2700f7e2014-03-07 09:46:20 -0800326 // FIXME: should return k64BitSolo.
327 return RegStorage(RegStorage::k64BitPair, p[next].reg, p[next+1].reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700328 }
329 next += 2;
330 }
331 next = reg_pool_->next_fp_reg & ~0x1;
332
333 // No choice - find a pair and kill it.
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700334 for (int i = 0; i < num_regs; i+=2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700335 if (next >= num_regs)
336 next = 0;
337 if (p[next].is_temp && !p[next].in_use && p[next+1].is_temp &&
338 !p[next+1].in_use) {
339 Clobber(p[next].reg);
340 Clobber(p[next+1].reg);
341 p[next].in_use = true;
342 p[next+1].in_use = true;
343 DCHECK_EQ((p[next].reg+1), p[next+1].reg);
344 DCHECK_EQ((p[next].reg & 0x1), 0);
345 reg_pool_->next_fp_reg = next + 2;
346 if (reg_pool_->next_fp_reg >= num_regs) {
347 reg_pool_->next_fp_reg = 0;
348 }
buzbee2700f7e2014-03-07 09:46:20 -0800349 return RegStorage(RegStorage::k64BitPair, p[next].reg, p[next+1].reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700350 }
351 next += 2;
352 }
353 LOG(FATAL) << "No free temp registers (pair)";
buzbee2700f7e2014-03-07 09:46:20 -0800354 return RegStorage::InvalidReg();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700355}
356
357/* Return a temp if one is available, -1 otherwise */
buzbee2700f7e2014-03-07 09:46:20 -0800358RegStorage Mir2Lir::AllocFreeTemp() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700359 return AllocTempBody(reg_pool_->core_regs,
360 reg_pool_->num_core_regs,
Vladimir Marko73e08b32013-11-21 10:58:36 +0000361 &reg_pool_->next_core_reg, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700362}
363
buzbee2700f7e2014-03-07 09:46:20 -0800364RegStorage Mir2Lir::AllocTemp() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700365 return AllocTempBody(reg_pool_->core_regs,
366 reg_pool_->num_core_regs,
367 &reg_pool_->next_core_reg, true);
368}
369
buzbee2700f7e2014-03-07 09:46:20 -0800370RegStorage Mir2Lir::AllocTempFloat() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700371 return AllocTempBody(reg_pool_->FPRegs,
372 reg_pool_->num_fp_regs,
373 &reg_pool_->next_fp_reg, true);
374}
375
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700376Mir2Lir::RegisterInfo* Mir2Lir::AllocLiveBody(RegisterInfo* p, int num_regs, int s_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700377 if (s_reg == -1)
378 return NULL;
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700379 for (int i = 0; i < num_regs; i++) {
buzbee56c71782013-09-05 17:13:19 -0700380 if ((p[i].s_reg == s_reg) && p[i].live) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700381 if (p[i].is_temp)
382 p[i].in_use = true;
383 return &p[i];
384 }
385 }
386 return NULL;
387}
388
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700389Mir2Lir::RegisterInfo* Mir2Lir::AllocLive(int s_reg, int reg_class) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700390 RegisterInfo* res = NULL;
391 switch (reg_class) {
392 case kAnyReg:
393 res = AllocLiveBody(reg_pool_->FPRegs,
394 reg_pool_->num_fp_regs, s_reg);
395 if (res)
396 break;
397 /* Intentional fallthrough */
398 case kCoreReg:
399 res = AllocLiveBody(reg_pool_->core_regs,
400 reg_pool_->num_core_regs, s_reg);
401 break;
402 case kFPReg:
403 res = AllocLiveBody(reg_pool_->FPRegs,
404 reg_pool_->num_fp_regs, s_reg);
405 break;
406 default:
407 LOG(FATAL) << "Invalid register type";
408 }
409 return res;
410}
411
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700412void Mir2Lir::FreeTemp(int reg) {
buzbee56c71782013-09-05 17:13:19 -0700413 RegisterInfo* p = GetRegInfo(reg);
414 if (p->is_temp) {
415 p->in_use = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700416 }
buzbee56c71782013-09-05 17:13:19 -0700417 p->pair = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700418}
419
buzbee2700f7e2014-03-07 09:46:20 -0800420void Mir2Lir::FreeTemp(RegStorage reg) {
421 if (reg.IsPair()) {
422 FreeTemp(reg.GetLowReg());
423 FreeTemp(reg.GetHighReg());
424 } else {
425 FreeTemp(reg.GetReg());
426 }
427}
428
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700429Mir2Lir::RegisterInfo* Mir2Lir::IsLive(int reg) {
buzbee56c71782013-09-05 17:13:19 -0700430 RegisterInfo* p = GetRegInfo(reg);
431 return p->live ? p : NULL;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700432}
433
buzbee262b2992014-03-27 11:22:43 -0700434bool Mir2Lir::IsLive(RegStorage reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800435 if (reg.IsPair()) {
buzbee262b2992014-03-27 11:22:43 -0700436 return IsLive(reg.GetLowReg()) || IsLive(reg.GetHighReg());
buzbee2700f7e2014-03-07 09:46:20 -0800437 } else {
438 return IsLive(reg.GetReg());
439 }
440}
441
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700442Mir2Lir::RegisterInfo* Mir2Lir::IsTemp(int reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700443 RegisterInfo* p = GetRegInfo(reg);
444 return (p->is_temp) ? p : NULL;
445}
446
buzbee262b2992014-03-27 11:22:43 -0700447bool Mir2Lir::IsTemp(RegStorage reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800448 if (reg.IsPair()) {
buzbee262b2992014-03-27 11:22:43 -0700449 return IsTemp(reg.GetLowReg()) || IsTemp(reg.GetHighReg());
buzbee2700f7e2014-03-07 09:46:20 -0800450 } else {
451 return IsTemp(reg.GetReg());
452 }
453}
454
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700455Mir2Lir::RegisterInfo* Mir2Lir::IsPromoted(int reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700456 RegisterInfo* p = GetRegInfo(reg);
457 return (p->is_temp) ? NULL : p;
458}
459
buzbee262b2992014-03-27 11:22:43 -0700460bool Mir2Lir::IsPromoted(RegStorage reg) {
buzbee2700f7e2014-03-07 09:46:20 -0800461 if (reg.IsPair()) {
buzbee262b2992014-03-27 11:22:43 -0700462 return IsPromoted(reg.GetLowReg()) || IsPromoted(reg.GetHighReg());
buzbee2700f7e2014-03-07 09:46:20 -0800463 } else {
464 return IsPromoted(reg.GetReg());
465 }
466}
467
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700468bool Mir2Lir::IsDirty(int reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700469 RegisterInfo* p = GetRegInfo(reg);
470 return p->dirty;
471}
472
buzbee2700f7e2014-03-07 09:46:20 -0800473bool Mir2Lir::IsDirty(RegStorage reg) {
474 if (reg.IsPair()) {
buzbee262b2992014-03-27 11:22:43 -0700475 return IsDirty(reg.GetLowReg()) || IsDirty(reg.GetHighReg());
buzbee2700f7e2014-03-07 09:46:20 -0800476 } else {
477 return IsDirty(reg.GetReg());
478 }
479}
480
Brian Carlstrom7940e442013-07-12 13:46:57 -0700481/*
482 * Similar to AllocTemp(), but forces the allocation of a specific
483 * register. No check is made to see if the register was previously
484 * allocated. Use with caution.
485 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700486void Mir2Lir::LockTemp(int reg) {
buzbee56c71782013-09-05 17:13:19 -0700487 RegisterInfo* p = GetRegInfo(reg);
488 DCHECK(p->is_temp);
489 p->in_use = true;
490 p->live = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700491}
492
buzbee2700f7e2014-03-07 09:46:20 -0800493void Mir2Lir::LockTemp(RegStorage reg) {
494 DCHECK(!reg.IsPair());
495 LockTemp(reg.GetReg());
496}
497
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700498void Mir2Lir::ResetDef(int reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700499 ResetDefBody(GetRegInfo(reg));
500}
501
buzbee2700f7e2014-03-07 09:46:20 -0800502void Mir2Lir::ResetDef(RegStorage reg) {
503 DCHECK(!reg.IsPair()); // Is this done? If so, do on both low and high.
504 ResetDef(reg.GetReg());
505}
506
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700507void Mir2Lir::NullifyRange(LIR *start, LIR *finish, int s_reg1, int s_reg2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700508 if (start && finish) {
509 LIR *p;
510 DCHECK_EQ(s_reg1, s_reg2);
Brian Carlstrom02c8cc62013-07-18 15:54:44 -0700511 for (p = start; ; p = p->next) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700512 NopLIR(p);
513 if (p == finish)
514 break;
515 }
516 }
517}
518
519/*
520 * Mark the beginning and end LIR of a def sequence. Note that
521 * on entry start points to the LIR prior to the beginning of the
522 * sequence.
523 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700524void Mir2Lir::MarkDef(RegLocation rl, LIR *start, LIR *finish) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700525 DCHECK(!rl.wide);
526 DCHECK(start && start->next);
527 DCHECK(finish);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000528 RegisterInfo* p = GetRegInfo(rl.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700529 p->def_start = start->next;
530 p->def_end = finish;
531}
532
533/*
534 * Mark the beginning and end LIR of a def sequence. Note that
535 * on entry start points to the LIR prior to the beginning of the
536 * sequence.
537 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700538void Mir2Lir::MarkDefWide(RegLocation rl, LIR *start, LIR *finish) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700539 DCHECK(rl.wide);
540 DCHECK(start && start->next);
541 DCHECK(finish);
buzbee2700f7e2014-03-07 09:46:20 -0800542 RegisterInfo* p = GetRegInfo(rl.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000543 ResetDef(rl.reg.GetHighReg()); // Only track low of pair
Brian Carlstrom7940e442013-07-12 13:46:57 -0700544 p->def_start = start->next;
545 p->def_end = finish;
546}
547
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700548RegLocation Mir2Lir::WideToNarrow(RegLocation rl) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700549 DCHECK(rl.wide);
550 if (rl.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800551 RegisterInfo* info_lo = GetRegInfo(rl.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000552 RegisterInfo* info_hi = GetRegInfo(rl.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700553 if (info_lo->is_temp) {
554 info_lo->pair = false;
555 info_lo->def_start = NULL;
556 info_lo->def_end = NULL;
557 }
558 if (info_hi->is_temp) {
559 info_hi->pair = false;
560 info_hi->def_start = NULL;
561 info_hi->def_end = NULL;
562 }
buzbee2700f7e2014-03-07 09:46:20 -0800563 rl.reg = RegStorage::Solo32(rl.reg.GetLowReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700564 }
565 rl.wide = false;
566 return rl;
567}
568
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700569void Mir2Lir::ResetDefLoc(RegLocation rl) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700570 DCHECK(!rl.wide);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000571 RegisterInfo* p = IsTemp(rl.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700572 if (p && !(cu_->disable_opt & (1 << kSuppressLoads))) {
573 DCHECK(!p->pair);
574 NullifyRange(p->def_start, p->def_end, p->s_reg, rl.s_reg_low);
575 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000576 ResetDef(rl.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700577}
578
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700579void Mir2Lir::ResetDefLocWide(RegLocation rl) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700580 DCHECK(rl.wide);
buzbee2700f7e2014-03-07 09:46:20 -0800581 RegisterInfo* p_low = IsTemp(rl.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000582 RegisterInfo* p_high = IsTemp(rl.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700583 if (p_low && !(cu_->disable_opt & (1 << kSuppressLoads))) {
584 DCHECK(p_low->pair);
585 NullifyRange(p_low->def_start, p_low->def_end, p_low->s_reg, rl.s_reg_low);
586 }
587 if (p_high && !(cu_->disable_opt & (1 << kSuppressLoads))) {
588 DCHECK(p_high->pair);
589 }
buzbee2700f7e2014-03-07 09:46:20 -0800590 ResetDef(rl.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000591 ResetDef(rl.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700592}
593
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700594void Mir2Lir::ResetDefTracking() {
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700595 for (int i = 0; i< reg_pool_->num_core_regs; i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700596 ResetDefBody(&reg_pool_->core_regs[i]);
597 }
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700598 for (int i = 0; i< reg_pool_->num_fp_regs; i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700599 ResetDefBody(&reg_pool_->FPRegs[i]);
600 }
601}
602
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700603void Mir2Lir::ClobberAllRegs() {
buzbeebd663de2013-09-10 15:41:31 -0700604 GrowableArray<RegisterInfo*>::Iterator iter(&tempreg_info_);
605 for (RegisterInfo* info = iter.Next(); info != NULL; info = iter.Next()) {
606 info->live = false;
607 info->s_reg = INVALID_SREG;
608 info->def_start = NULL;
609 info->def_end = NULL;
610 info->pair = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700611 }
612}
613
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800614void Mir2Lir::FlushSpecificReg(RegisterInfo* info) {
615 if (info->pair) {
buzbee2700f7e2014-03-07 09:46:20 -0800616 FlushRegWide(RegStorage(RegStorage::k64BitPair, info->reg, info->partner));
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800617 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800618 FlushReg(RegStorage::Solo32(info->reg));
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800619 }
620}
621
Brian Carlstrom7940e442013-07-12 13:46:57 -0700622// Make sure nothing is live and dirty
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700623void Mir2Lir::FlushAllRegsBody(RegisterInfo* info, int num_regs) {
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700624 for (int i = 0; i < num_regs; i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700625 if (info[i].live && info[i].dirty) {
Razvan A Lupusoru614c2b42014-01-28 17:05:21 -0800626 FlushSpecificReg(&info[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700627 }
628 }
629}
630
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700631void Mir2Lir::FlushAllRegs() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700632 FlushAllRegsBody(reg_pool_->core_regs,
633 reg_pool_->num_core_regs);
634 FlushAllRegsBody(reg_pool_->FPRegs,
635 reg_pool_->num_fp_regs);
636 ClobberAllRegs();
637}
638
639
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700640// TUNING: rewrite all of this reg stuff. Probably use an attribute table
buzbee2700f7e2014-03-07 09:46:20 -0800641bool Mir2Lir::RegClassMatches(int reg_class, RegStorage reg) {
642 int reg_num = reg.IsPair() ? reg.GetLowReg() : reg.GetReg();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700643 if (reg_class == kAnyReg) {
644 return true;
645 } else if (reg_class == kCoreReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800646 return !IsFpReg(reg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700647 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800648 return IsFpReg(reg_num);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700649 }
650}
651
buzbee2700f7e2014-03-07 09:46:20 -0800652void Mir2Lir::MarkLive(RegStorage reg, int s_reg) {
653 DCHECK(!reg.IsPair()); // Could be done - but would that be meaningful?
654 RegisterInfo* info = GetRegInfo(reg.GetReg());
655 if ((info->s_reg == s_reg) && info->live) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700656 return; /* already live */
657 } else if (s_reg != INVALID_SREG) {
658 ClobberSReg(s_reg);
659 if (info->is_temp) {
660 info->live = true;
661 }
662 } else {
663 /* Can't be live if no associated s_reg */
664 DCHECK(info->is_temp);
665 info->live = false;
666 }
667 info->s_reg = s_reg;
668}
669
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700670void Mir2Lir::MarkTemp(int reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700671 RegisterInfo* info = GetRegInfo(reg);
buzbeebd663de2013-09-10 15:41:31 -0700672 tempreg_info_.Insert(info);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700673 info->is_temp = true;
674}
675
buzbee2700f7e2014-03-07 09:46:20 -0800676void Mir2Lir::MarkTemp(RegStorage reg) {
677 DCHECK(!reg.IsPair());
678 MarkTemp(reg.GetReg());
679}
680
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700681void Mir2Lir::UnmarkTemp(int reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700682 RegisterInfo* info = GetRegInfo(reg);
buzbeebd663de2013-09-10 15:41:31 -0700683 tempreg_info_.Delete(info);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700684 info->is_temp = false;
685}
686
buzbee2700f7e2014-03-07 09:46:20 -0800687void Mir2Lir::UnmarkTemp(RegStorage reg) {
688 DCHECK(!reg.IsPair());
689 UnmarkTemp(reg.GetReg());
690}
691
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700692void Mir2Lir::MarkPair(int low_reg, int high_reg) {
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000693 DCHECK_NE(low_reg, high_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700694 RegisterInfo* info_lo = GetRegInfo(low_reg);
695 RegisterInfo* info_hi = GetRegInfo(high_reg);
696 info_lo->pair = info_hi->pair = true;
697 info_lo->partner = high_reg;
698 info_hi->partner = low_reg;
699}
700
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700701void Mir2Lir::MarkClean(RegLocation loc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700702 if (loc.wide) {
buzbee2700f7e2014-03-07 09:46:20 -0800703 RegisterInfo* info = GetRegInfo(loc.reg.GetLowReg());
704 info->dirty = false;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000705 info = GetRegInfo(loc.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700706 info->dirty = false;
buzbee2700f7e2014-03-07 09:46:20 -0800707 } else {
708 RegisterInfo* info = GetRegInfo(loc.reg.GetReg());
709 info->dirty = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700710 }
711}
712
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700713void Mir2Lir::MarkDirty(RegLocation loc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700714 if (loc.home) {
715 // If already home, can't be dirty
716 return;
717 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700718 if (loc.wide) {
buzbee2700f7e2014-03-07 09:46:20 -0800719 RegisterInfo* info = GetRegInfo(loc.reg.GetLowReg());
720 info->dirty = true;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000721 info = GetRegInfo(loc.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700722 info->dirty = true;
buzbee2700f7e2014-03-07 09:46:20 -0800723 } else {
724 RegisterInfo* info = GetRegInfo(loc.reg.GetReg());
725 info->dirty = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700726 }
727}
728
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700729void Mir2Lir::MarkInUse(int reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700730 RegisterInfo* info = GetRegInfo(reg);
731 info->in_use = true;
732}
733
buzbee2700f7e2014-03-07 09:46:20 -0800734void Mir2Lir::MarkInUse(RegStorage reg) {
735 if (reg.IsPair()) {
736 MarkInUse(reg.GetLowReg());
737 MarkInUse(reg.GetHighReg());
738 } else {
739 MarkInUse(reg.GetReg());
740 }
741}
742
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700743void Mir2Lir::CopyRegInfo(int new_reg, int old_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700744 RegisterInfo* new_info = GetRegInfo(new_reg);
745 RegisterInfo* old_info = GetRegInfo(old_reg);
Chao-ying Fu3d325c62014-03-27 14:17:28 -0700746 // Target temp, live, dirty status must not change
Brian Carlstrom7940e442013-07-12 13:46:57 -0700747 bool is_temp = new_info->is_temp;
Chao-ying Fu3d325c62014-03-27 14:17:28 -0700748 bool live = new_info->live;
749 bool dirty = new_info->dirty;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700750 *new_info = *old_info;
Chao-ying Fu3d325c62014-03-27 14:17:28 -0700751 // Restore target's temp, live, dirty status
Brian Carlstrom7940e442013-07-12 13:46:57 -0700752 new_info->is_temp = is_temp;
Chao-ying Fu3d325c62014-03-27 14:17:28 -0700753 new_info->live = live;
754 new_info->dirty = dirty;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700755 new_info->reg = new_reg;
756}
757
buzbee2700f7e2014-03-07 09:46:20 -0800758void Mir2Lir::CopyRegInfo(RegStorage new_reg, RegStorage old_reg) {
759 DCHECK(!new_reg.IsPair());
760 DCHECK(!old_reg.IsPair());
761 CopyRegInfo(new_reg.GetReg(), old_reg.GetReg());
762}
763
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700764bool Mir2Lir::CheckCorePoolSanity() {
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700765 for (static int i = 0; i < reg_pool_->num_core_regs; i++) {
766 if (reg_pool_->core_regs[i].pair) {
767 static int my_reg = reg_pool_->core_regs[i].reg;
768 static int my_sreg = reg_pool_->core_regs[i].s_reg;
769 static int partner_reg = reg_pool_->core_regs[i].partner;
770 static RegisterInfo* partner = GetRegInfo(partner_reg);
771 DCHECK(partner != NULL);
772 DCHECK(partner->pair);
773 DCHECK_EQ(my_reg, partner->partner);
774 static int partner_sreg = partner->s_reg;
775 if (my_sreg == INVALID_SREG) {
776 DCHECK_EQ(partner_sreg, INVALID_SREG);
777 } else {
778 int diff = my_sreg - partner_sreg;
779 DCHECK((diff == -1) || (diff == 1));
780 }
781 }
782 if (!reg_pool_->core_regs[i].live) {
783 DCHECK(reg_pool_->core_regs[i].def_start == NULL);
784 DCHECK(reg_pool_->core_regs[i].def_end == NULL);
785 }
786 }
787 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700788}
789
790/*
791 * Return an updated location record with current in-register status.
792 * If the value lives in live temps, reflect that fact. No code
793 * is generated. If the live value is part of an older pair,
794 * clobber both low and high.
795 * TUNING: clobbering both is a bit heavy-handed, but the alternative
796 * is a bit complex when dealing with FP regs. Examine code to see
797 * if it's worthwhile trying to be more clever here.
798 */
799
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700800RegLocation Mir2Lir::UpdateLoc(RegLocation loc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700801 DCHECK(!loc.wide);
802 DCHECK(CheckCorePoolSanity());
803 if (loc.location != kLocPhysReg) {
804 DCHECK((loc.location == kLocDalvikFrame) ||
805 (loc.location == kLocCompilerTemp));
806 RegisterInfo* info_lo = AllocLive(loc.s_reg_low, kAnyReg);
807 if (info_lo) {
808 if (info_lo->pair) {
809 Clobber(info_lo->reg);
810 Clobber(info_lo->partner);
811 FreeTemp(info_lo->reg);
812 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800813 loc.reg = RegStorage::Solo32(info_lo->reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700814 loc.location = kLocPhysReg;
815 }
816 }
817 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700818 return loc;
819}
820
821/* see comments for update_loc */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700822RegLocation Mir2Lir::UpdateLocWide(RegLocation loc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700823 DCHECK(loc.wide);
824 DCHECK(CheckCorePoolSanity());
825 if (loc.location != kLocPhysReg) {
826 DCHECK((loc.location == kLocDalvikFrame) ||
827 (loc.location == kLocCompilerTemp));
828 // Are the dalvik regs already live in physical registers?
829 RegisterInfo* info_lo = AllocLive(loc.s_reg_low, kAnyReg);
830 RegisterInfo* info_hi = AllocLive(GetSRegHi(loc.s_reg_low), kAnyReg);
831 bool match = true;
832 match = match && (info_lo != NULL);
833 match = match && (info_hi != NULL);
834 // Are they both core or both FP?
835 match = match && (IsFpReg(info_lo->reg) == IsFpReg(info_hi->reg));
836 // If a pair of floating point singles, are they properly aligned?
837 if (match && IsFpReg(info_lo->reg)) {
838 match &= ((info_lo->reg & 0x1) == 0);
839 match &= ((info_hi->reg - info_lo->reg) == 1);
840 }
841 // If previously used as a pair, it is the same pair?
842 if (match && (info_lo->pair || info_hi->pair)) {
843 match = (info_lo->pair == info_hi->pair);
844 match &= ((info_lo->reg == info_hi->partner) &&
845 (info_hi->reg == info_lo->partner));
846 }
847 if (match) {
848 // Can reuse - update the register usage info
Brian Carlstrom7940e442013-07-12 13:46:57 -0700849 loc.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000850 loc.reg = RegStorage(RegStorage::k64BitPair, info_lo->reg, info_hi->reg);
buzbee2700f7e2014-03-07 09:46:20 -0800851 MarkPair(loc.reg.GetLowReg(), loc.reg.GetHighReg());
852 DCHECK(!IsFpReg(loc.reg.GetLowReg()) || ((loc.reg.GetLowReg() & 0x1) == 0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700853 return loc;
854 }
855 // Can't easily reuse - clobber and free any overlaps
856 if (info_lo) {
857 Clobber(info_lo->reg);
858 FreeTemp(info_lo->reg);
859 if (info_lo->pair)
860 Clobber(info_lo->partner);
861 }
862 if (info_hi) {
863 Clobber(info_hi->reg);
864 FreeTemp(info_hi->reg);
865 if (info_hi->pair)
866 Clobber(info_hi->partner);
867 }
868 }
869 return loc;
870}
871
872
873/* For use in cases we don't know (or care) width */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700874RegLocation Mir2Lir::UpdateRawLoc(RegLocation loc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700875 if (loc.wide)
876 return UpdateLocWide(loc);
877 else
878 return UpdateLoc(loc);
879}
880
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700881RegLocation Mir2Lir::EvalLocWide(RegLocation loc, int reg_class, bool update) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700882 DCHECK(loc.wide);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700883
884 loc = UpdateLocWide(loc);
885
886 /* If already in registers, we can assume proper form. Right reg class? */
887 if (loc.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800888 DCHECK_EQ(IsFpReg(loc.reg.GetLowReg()), IsFpReg(loc.reg.GetHighReg()));
889 DCHECK(!IsFpReg(loc.reg.GetLowReg()) || ((loc.reg.GetLowReg() & 0x1) == 0));
890 if (!RegClassMatches(reg_class, loc.reg)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700891 /* Wrong register class. Reallocate and copy */
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000892 RegStorage new_regs = AllocTypedTempWide(loc.fp, reg_class);
buzbee2700f7e2014-03-07 09:46:20 -0800893 OpRegCopyWide(new_regs, loc.reg);
894 CopyRegInfo(new_regs.GetLowReg(), loc.reg.GetLowReg());
895 CopyRegInfo(new_regs.GetHighReg(), loc.reg.GetHighReg());
896 Clobber(loc.reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000897 loc.reg = new_regs;
buzbee2700f7e2014-03-07 09:46:20 -0800898 MarkPair(loc.reg.GetLowReg(), loc.reg.GetHighReg());
899 DCHECK(!IsFpReg(loc.reg.GetLowReg()) || ((loc.reg.GetLowReg() & 0x1) == 0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700900 }
901 return loc;
902 }
903
904 DCHECK_NE(loc.s_reg_low, INVALID_SREG);
905 DCHECK_NE(GetSRegHi(loc.s_reg_low), INVALID_SREG);
906
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000907 loc.reg = AllocTypedTempWide(loc.fp, reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700908
buzbee2700f7e2014-03-07 09:46:20 -0800909 MarkPair(loc.reg.GetLowReg(), loc.reg.GetHighReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700910 if (update) {
911 loc.location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800912 MarkLive(loc.reg.GetLow(), loc.s_reg_low);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000913 // Does this wide value live in two registers or one vector register?
buzbee2700f7e2014-03-07 09:46:20 -0800914 if (loc.reg.GetLowReg() != loc.reg.GetHighReg()) {
915 MarkLive(loc.reg.GetHigh(), GetSRegHi(loc.s_reg_low));
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000916 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700917 }
buzbee2700f7e2014-03-07 09:46:20 -0800918 DCHECK(!IsFpReg(loc.reg.GetLowReg()) || ((loc.reg.GetLowReg() & 0x1) == 0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700919 return loc;
920}
921
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700922RegLocation Mir2Lir::EvalLoc(RegLocation loc, int reg_class, bool update) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700923 if (loc.wide)
924 return EvalLocWide(loc, reg_class, update);
925
926 loc = UpdateLoc(loc);
927
928 if (loc.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800929 if (!RegClassMatches(reg_class, loc.reg)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700930 /* Wrong register class. Realloc, copy and transfer ownership */
buzbee2700f7e2014-03-07 09:46:20 -0800931 RegStorage new_reg = AllocTypedTemp(loc.fp, reg_class);
932 OpRegCopy(new_reg, loc.reg);
933 CopyRegInfo(new_reg, loc.reg);
934 Clobber(loc.reg);
935 loc.reg = new_reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700936 }
937 return loc;
938 }
939
940 DCHECK_NE(loc.s_reg_low, INVALID_SREG);
941
buzbee2700f7e2014-03-07 09:46:20 -0800942 loc.reg = AllocTypedTemp(loc.fp, reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700943
944 if (update) {
945 loc.location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800946 MarkLive(loc.reg, loc.s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700947 }
948 return loc;
949}
950
951/* USE SSA names to count references of base Dalvik v_regs. */
buzbeec729a6b2013-09-14 16:04:31 -0700952void Mir2Lir::CountRefs(RefCounts* core_counts, RefCounts* fp_counts, size_t num_regs) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700953 for (int i = 0; i < mir_graph_->GetNumSSARegs(); i++) {
954 RegLocation loc = mir_graph_->reg_location_[i];
955 RefCounts* counts = loc.fp ? fp_counts : core_counts;
956 int p_map_idx = SRegToPMap(loc.s_reg_low);
buzbeec729a6b2013-09-14 16:04:31 -0700957 if (loc.fp) {
958 if (loc.wide) {
959 // Treat doubles as a unit, using upper half of fp_counts array.
960 counts[p_map_idx + num_regs].count += mir_graph_->GetUseCount(i);
961 i++;
962 } else {
963 counts[p_map_idx].count += mir_graph_->GetUseCount(i);
964 }
965 } else if (!IsInexpensiveConstant(loc)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700966 counts[p_map_idx].count += mir_graph_->GetUseCount(i);
967 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700968 }
969}
970
971/* qsort callback function, sort descending */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700972static int SortCounts(const void *val1, const void *val2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700973 const Mir2Lir::RefCounts* op1 = reinterpret_cast<const Mir2Lir::RefCounts*>(val1);
974 const Mir2Lir::RefCounts* op2 = reinterpret_cast<const Mir2Lir::RefCounts*>(val2);
Brian Carlstrom4b8c13e2013-08-23 18:10:32 -0700975 // Note that we fall back to sorting on reg so we get stable output
976 // on differing qsort implementations (such as on host and target or
977 // between local host and build servers).
978 return (op1->count == op2->count)
979 ? (op1->s_reg - op2->s_reg)
980 : (op1->count < op2->count ? 1 : -1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700981}
982
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700983void Mir2Lir::DumpCounts(const RefCounts* arr, int size, const char* msg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700984 LOG(INFO) << msg;
985 for (int i = 0; i < size; i++) {
buzbeec729a6b2013-09-14 16:04:31 -0700986 if ((arr[i].s_reg & STARTING_DOUBLE_SREG) != 0) {
987 LOG(INFO) << "s_reg[D" << (arr[i].s_reg & ~STARTING_DOUBLE_SREG) << "]: " << arr[i].count;
988 } else {
989 LOG(INFO) << "s_reg[" << arr[i].s_reg << "]: " << arr[i].count;
990 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700991 }
992}
993
994/*
995 * Note: some portions of this code required even if the kPromoteRegs
996 * optimization is disabled.
997 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700998void Mir2Lir::DoPromotion() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700999 int dalvik_regs = cu_->num_dalvik_registers;
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -08001000 int num_regs = dalvik_regs + mir_graph_->GetNumUsedCompilerTemps();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001001 const int promotion_threshold = 1;
buzbeed69835d2014-02-03 14:40:27 -08001002 // Allocate the promotion map - one entry for each Dalvik vReg or compiler temp
1003 promotion_map_ = static_cast<PromotionMap*>
Vladimir Marko83cc7ae2014-02-12 18:02:05 +00001004 (arena_->Alloc(num_regs * sizeof(promotion_map_[0]), kArenaAllocRegAlloc));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001005
1006 // Allow target code to add any special registers
1007 AdjustSpillMask();
1008
1009 /*
1010 * Simple register promotion. Just do a static count of the uses
1011 * of Dalvik registers. Note that we examine the SSA names, but
1012 * count based on original Dalvik register name. Count refs
1013 * separately based on type in order to give allocation
1014 * preference to fp doubles - which must be allocated sequential
buzbeec729a6b2013-09-14 16:04:31 -07001015 * physical single fp registers starting with an even-numbered
Brian Carlstrom7940e442013-07-12 13:46:57 -07001016 * reg.
1017 * TUNING: replace with linear scan once we have the ability
1018 * to describe register live ranges for GC.
1019 */
1020 RefCounts *core_regs =
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -07001021 static_cast<RefCounts*>(arena_->Alloc(sizeof(RefCounts) * num_regs,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +00001022 kArenaAllocRegAlloc));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001023 RefCounts *FpRegs =
buzbeec729a6b2013-09-14 16:04:31 -07001024 static_cast<RefCounts *>(arena_->Alloc(sizeof(RefCounts) * num_regs * 2,
Vladimir Marko83cc7ae2014-02-12 18:02:05 +00001025 kArenaAllocRegAlloc));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001026 // Set ssa names for original Dalvik registers
1027 for (int i = 0; i < dalvik_regs; i++) {
1028 core_regs[i].s_reg = FpRegs[i].s_reg = i;
1029 }
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -08001030
1031 // Set ssa names for compiler temporaries
1032 for (unsigned int ct_idx = 0; ct_idx < mir_graph_->GetNumUsedCompilerTemps(); ct_idx++) {
1033 CompilerTemp* ct = mir_graph_->GetCompilerTemp(ct_idx);
1034 core_regs[dalvik_regs + ct_idx].s_reg = ct->s_reg_low;
1035 FpRegs[dalvik_regs + ct_idx].s_reg = ct->s_reg_low;
1036 FpRegs[num_regs + dalvik_regs + ct_idx].s_reg = ct->s_reg_low;
buzbeec729a6b2013-09-14 16:04:31 -07001037 }
1038
1039 // Duplicate in upper half to represent possible fp double starting sregs.
1040 for (int i = 0; i < num_regs; i++) {
1041 FpRegs[num_regs + i].s_reg = FpRegs[i].s_reg | STARTING_DOUBLE_SREG;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001042 }
1043
1044 // Sum use counts of SSA regs by original Dalvik vreg.
buzbeec729a6b2013-09-14 16:04:31 -07001045 CountRefs(core_regs, FpRegs, num_regs);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001046
Brian Carlstrom7940e442013-07-12 13:46:57 -07001047
1048 // Sort the count arrays
1049 qsort(core_regs, num_regs, sizeof(RefCounts), SortCounts);
buzbeec729a6b2013-09-14 16:04:31 -07001050 qsort(FpRegs, num_regs * 2, sizeof(RefCounts), SortCounts);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001051
1052 if (cu_->verbose) {
1053 DumpCounts(core_regs, num_regs, "Core regs after sort");
buzbeec729a6b2013-09-14 16:04:31 -07001054 DumpCounts(FpRegs, num_regs * 2, "Fp regs after sort");
Brian Carlstrom7940e442013-07-12 13:46:57 -07001055 }
1056
1057 if (!(cu_->disable_opt & (1 << kPromoteRegs))) {
1058 // Promote FpRegs
buzbeec729a6b2013-09-14 16:04:31 -07001059 for (int i = 0; (i < (num_regs * 2)) && (FpRegs[i].count >= promotion_threshold); i++) {
1060 int p_map_idx = SRegToPMap(FpRegs[i].s_reg & ~STARTING_DOUBLE_SREG);
1061 if ((FpRegs[i].s_reg & STARTING_DOUBLE_SREG) != 0) {
1062 if ((promotion_map_[p_map_idx].fp_location != kLocPhysReg) &&
1063 (promotion_map_[p_map_idx + 1].fp_location != kLocPhysReg)) {
1064 int low_sreg = FpRegs[i].s_reg & ~STARTING_DOUBLE_SREG;
1065 // Ignore result - if can't alloc double may still be able to alloc singles.
1066 AllocPreservedDouble(low_sreg);
1067 }
1068 } else if (promotion_map_[p_map_idx].fp_location != kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -08001069 RegStorage reg = AllocPreservedSingle(FpRegs[i].s_reg);
1070 if (!reg.Valid()) {
buzbeec729a6b2013-09-14 16:04:31 -07001071 break; // No more left.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001072 }
1073 }
1074 }
1075
1076 // Promote core regs
1077 for (int i = 0; (i < num_regs) &&
1078 (core_regs[i].count >= promotion_threshold); i++) {
1079 int p_map_idx = SRegToPMap(core_regs[i].s_reg);
1080 if (promotion_map_[p_map_idx].core_location !=
1081 kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -08001082 RegStorage reg = AllocPreservedCoreReg(core_regs[i].s_reg);
1083 if (!reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001084 break; // No more left
1085 }
1086 }
1087 }
1088 }
1089
1090 // Now, update SSA names to new home locations
1091 for (int i = 0; i < mir_graph_->GetNumSSARegs(); i++) {
1092 RegLocation *curr = &mir_graph_->reg_location_[i];
1093 int p_map_idx = SRegToPMap(curr->s_reg_low);
1094 if (!curr->wide) {
1095 if (curr->fp) {
1096 if (promotion_map_[p_map_idx].fp_location == kLocPhysReg) {
1097 curr->location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -08001098 curr->reg = RegStorage::Solo32(promotion_map_[p_map_idx].FpReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001099 curr->home = true;
1100 }
1101 } else {
1102 if (promotion_map_[p_map_idx].core_location == kLocPhysReg) {
1103 curr->location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -08001104 curr->reg = RegStorage::Solo32(promotion_map_[p_map_idx].core_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001105 curr->home = true;
1106 }
1107 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001108 } else {
1109 if (curr->high_word) {
1110 continue;
1111 }
1112 if (curr->fp) {
1113 if ((promotion_map_[p_map_idx].fp_location == kLocPhysReg) &&
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001114 (promotion_map_[p_map_idx+1].fp_location == kLocPhysReg)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001115 int low_reg = promotion_map_[p_map_idx].FpReg;
1116 int high_reg = promotion_map_[p_map_idx+1].FpReg;
1117 // Doubles require pair of singles starting at even reg
1118 if (((low_reg & 0x1) == 0) && ((low_reg + 1) == high_reg)) {
1119 curr->location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001120 curr->reg = RegStorage(RegStorage::k64BitPair, low_reg, high_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001121 curr->home = true;
1122 }
1123 }
1124 } else {
1125 if ((promotion_map_[p_map_idx].core_location == kLocPhysReg)
1126 && (promotion_map_[p_map_idx+1].core_location ==
1127 kLocPhysReg)) {
1128 curr->location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001129 curr->reg = RegStorage(RegStorage::k64BitPair, promotion_map_[p_map_idx].core_reg,
1130 promotion_map_[p_map_idx+1].core_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001131 curr->home = true;
1132 }
1133 }
1134 }
1135 }
1136 if (cu_->verbose) {
1137 DumpPromotionMap();
1138 }
1139}
1140
1141/* Returns sp-relative offset in bytes for a VReg */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001142int Mir2Lir::VRegOffset(int v_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001143 return StackVisitor::GetVRegOffset(cu_->code_item, core_spill_mask_,
Nicolas Geoffray42fcd982014-04-22 11:03:52 +00001144 fp_spill_mask_, frame_size_, v_reg,
1145 cu_->instruction_set);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001146}
1147
1148/* Returns sp-relative offset in bytes for a SReg */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001149int Mir2Lir::SRegOffset(int s_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001150 return VRegOffset(mir_graph_->SRegToVReg(s_reg));
1151}
1152
1153/* Mark register usage state and return long retloc */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001154RegLocation Mir2Lir::GetReturnWide(bool is_double) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001155 RegLocation gpr_res = LocCReturnWide();
1156 RegLocation fpr_res = LocCReturnDouble();
1157 RegLocation res = is_double ? fpr_res : gpr_res;
buzbee2700f7e2014-03-07 09:46:20 -08001158 Clobber(res.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001159 Clobber(res.reg.GetHighReg());
buzbee2700f7e2014-03-07 09:46:20 -08001160 LockTemp(res.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001161 LockTemp(res.reg.GetHighReg());
Bill Buzbeed61ba4b2014-01-13 21:44:01 +00001162 // Does this wide value live in two registers or one vector register?
buzbee2700f7e2014-03-07 09:46:20 -08001163 if (res.reg.GetLowReg() != res.reg.GetHighReg()) {
1164 MarkPair(res.reg.GetLowReg(), res.reg.GetHighReg());
Bill Buzbeed61ba4b2014-01-13 21:44:01 +00001165 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001166 return res;
1167}
1168
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001169RegLocation Mir2Lir::GetReturn(bool is_float) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001170 RegLocation gpr_res = LocCReturn();
1171 RegLocation fpr_res = LocCReturnFloat();
1172 RegLocation res = is_float ? fpr_res : gpr_res;
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001173 Clobber(res.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001174 if (cu_->instruction_set == kMips) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001175 MarkInUse(res.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001176 } else {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001177 LockTemp(res.reg.GetReg());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001178 }
1179 return res;
1180}
1181
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001182void Mir2Lir::SimpleRegAlloc() {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001183 DoPromotion();
1184
1185 if (cu_->verbose && !(cu_->disable_opt & (1 << kPromoteRegs))) {
1186 LOG(INFO) << "After Promotion";
1187 mir_graph_->DumpRegLocTable(mir_graph_->reg_location_, mir_graph_->GetNumSSARegs());
1188 }
1189
1190 /* Set the frame size */
1191 frame_size_ = ComputeFrameSize();
1192}
1193
1194/*
1195 * Get the "real" sreg number associated with an s_reg slot. In general,
1196 * s_reg values passed through codegen are the SSA names created by
1197 * dataflow analysis and refer to slot numbers in the mir_graph_->reg_location
1198 * array. However, renaming is accomplished by simply replacing RegLocation
1199 * entries in the reglocation[] array. Therefore, when location
1200 * records for operands are first created, we need to ask the locRecord
1201 * identified by the dataflow pass what it's new name is.
1202 */
1203int Mir2Lir::GetSRegHi(int lowSreg) {
1204 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
1205}
1206
1207bool Mir2Lir::oat_live_out(int s_reg) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001208 // For now.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001209 return true;
1210}
1211
1212int Mir2Lir::oatSSASrc(MIR* mir, int num) {
1213 DCHECK_GT(mir->ssa_rep->num_uses, num);
1214 return mir->ssa_rep->uses[num];
1215}
1216
1217} // namespace art