blob: f5e7e635dea4d31dc7f168a10bc8606b8f666788 [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#include "dex/compiler_ir.h"
18#include "dex/compiler_internals.h"
19#include "dex/quick/mir_to_lir-inl.h"
20#include "invoke_type.h"
21
22namespace art {
23
24/* This file contains target-independent codegen and support. */
25
26/*
27 * Load an immediate value into a fixed or temp register. Target
28 * register is clobbered, and marked in_use.
29 */
buzbee2700f7e2014-03-07 09:46:20 -080030LIR* Mir2Lir::LoadConstant(RegStorage r_dest, int value) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070031 if (IsTemp(r_dest)) {
32 Clobber(r_dest);
33 MarkInUse(r_dest);
34 }
35 return LoadConstantNoClobber(r_dest, value);
36}
37
38/*
39 * Temporary workaround for Issue 7250540. If we're loading a constant zero into a
40 * promoted floating point register, also copy a zero into the int/ref identity of
41 * that sreg.
42 */
buzbee2700f7e2014-03-07 09:46:20 -080043void Mir2Lir::Workaround7250540(RegLocation rl_dest, RegStorage zero_reg) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070044 if (rl_dest.fp) {
45 int pmap_index = SRegToPMap(rl_dest.s_reg_low);
46 if (promotion_map_[pmap_index].fp_location == kLocPhysReg) {
47 // Now, determine if this vreg is ever used as a reference. If not, we're done.
48 bool used_as_reference = false;
49 int base_vreg = mir_graph_->SRegToVReg(rl_dest.s_reg_low);
50 for (int i = 0; !used_as_reference && (i < mir_graph_->GetNumSSARegs()); i++) {
51 if (mir_graph_->SRegToVReg(mir_graph_->reg_location_[i].s_reg_low) == base_vreg) {
52 used_as_reference |= mir_graph_->reg_location_[i].ref;
53 }
54 }
55 if (!used_as_reference) {
56 return;
57 }
buzbee2700f7e2014-03-07 09:46:20 -080058 RegStorage temp_reg = zero_reg;
59 if (!temp_reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070060 temp_reg = AllocTemp();
61 LoadConstant(temp_reg, 0);
62 }
63 if (promotion_map_[pmap_index].core_location == kLocPhysReg) {
64 // Promoted - just copy in a zero
buzbee2700f7e2014-03-07 09:46:20 -080065 OpRegCopy(RegStorage::Solo32(promotion_map_[pmap_index].core_reg), temp_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070066 } else {
67 // Lives in the frame, need to store.
buzbee695d13a2014-04-19 13:32:20 -070068 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), temp_reg, k32);
Brian Carlstrom7940e442013-07-12 13:46:57 -070069 }
buzbee2700f7e2014-03-07 09:46:20 -080070 if (!zero_reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070071 FreeTemp(temp_reg);
72 }
73 }
74 }
75}
76
Brian Carlstrom7940e442013-07-12 13:46:57 -070077/*
78 * Load a Dalvik register into a physical register. Take care when
79 * using this routine, as it doesn't perform any bookkeeping regarding
80 * register liveness. That is the responsibility of the caller.
81 */
buzbee2700f7e2014-03-07 09:46:20 -080082void Mir2Lir::LoadValueDirect(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070083 rl_src = UpdateLoc(rl_src);
84 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -080085 OpRegCopy(r_dest, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070086 } else if (IsInexpensiveConstant(rl_src)) {
buzbee695d13a2014-04-19 13:32:20 -070087 // On 64-bit targets, will sign extend. Make sure constant reference is always NULL.
88 DCHECK(!rl_src.ref || (mir_graph_->ConstantValue(rl_src) == 0));
Brian Carlstrom7940e442013-07-12 13:46:57 -070089 LoadConstantNoClobber(r_dest, mir_graph_->ConstantValue(rl_src));
90 } else {
91 DCHECK((rl_src.location == kLocDalvikFrame) ||
92 (rl_src.location == kLocCompilerTemp));
buzbee695d13a2014-04-19 13:32:20 -070093 if (rl_src.ref) {
94 LoadRefDisp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest);
95 } else {
96 Load32Disp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest);
97 }
Brian Carlstrom7940e442013-07-12 13:46:57 -070098 }
99}
100
101/*
102 * Similar to LoadValueDirect, but clobbers and allocates the target
103 * register. Should be used when loading to a fixed register (for example,
104 * loading arguments to an out of line call.
105 */
buzbee2700f7e2014-03-07 09:46:20 -0800106void Mir2Lir::LoadValueDirectFixed(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700107 Clobber(r_dest);
108 MarkInUse(r_dest);
109 LoadValueDirect(rl_src, r_dest);
110}
111
112/*
113 * Load a Dalvik register pair into a physical register[s]. Take care when
114 * using this routine, as it doesn't perform any bookkeeping regarding
115 * register liveness. That is the responsibility of the caller.
116 */
buzbee2700f7e2014-03-07 09:46:20 -0800117void Mir2Lir::LoadValueDirectWide(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118 rl_src = UpdateLocWide(rl_src);
119 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800120 OpRegCopyWide(r_dest, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700121 } else if (IsInexpensiveConstant(rl_src)) {
buzbee2700f7e2014-03-07 09:46:20 -0800122 LoadConstantWide(r_dest, mir_graph_->ConstantValueWide(rl_src));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123 } else {
124 DCHECK((rl_src.location == kLocDalvikFrame) ||
125 (rl_src.location == kLocCompilerTemp));
Vladimir Marko3bf7c602014-05-07 14:55:43 +0100126 LoadBaseDisp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest, k64);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700127 }
128}
129
130/*
131 * Similar to LoadValueDirect, but clobbers and allocates the target
132 * registers. Should be used when loading to a fixed registers (for example,
133 * loading arguments to an out of line call.
134 */
buzbee2700f7e2014-03-07 09:46:20 -0800135void Mir2Lir::LoadValueDirectWideFixed(RegLocation rl_src, RegStorage r_dest) {
136 Clobber(r_dest);
137 MarkInUse(r_dest);
138 LoadValueDirectWide(rl_src, r_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700139}
140
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700141RegLocation Mir2Lir::LoadValue(RegLocation rl_src, RegisterClass op_kind) {
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100142 rl_src = UpdateLoc(rl_src);
143 if (rl_src.location == kLocPhysReg) {
144 if (!RegClassMatches(op_kind, rl_src.reg)) {
145 // Wrong register class, realloc, copy and transfer ownership.
146 RegStorage new_reg = AllocTypedTemp(rl_src.fp, op_kind);
147 OpRegCopy(new_reg, rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700148 // Clobber the old reg.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100149 Clobber(rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700150 // ...and mark the new one live.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100151 rl_src.reg = new_reg;
buzbee082833c2014-05-17 23:16:26 -0700152 MarkLive(rl_src);
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100153 }
154 return rl_src;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700155 }
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100156
157 DCHECK_NE(rl_src.s_reg_low, INVALID_SREG);
158 rl_src.reg = AllocTypedTemp(rl_src.fp, op_kind);
159 LoadValueDirect(rl_src, rl_src.reg);
160 rl_src.location = kLocPhysReg;
161 MarkLive(rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 return rl_src;
163}
164
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700165void Mir2Lir::StoreValue(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700166 /*
167 * Sanity checking - should never try to store to the same
168 * ssa name during the compilation of a single instruction
169 * without an intervening ClobberSReg().
170 */
171 if (kIsDebugBuild) {
172 DCHECK((live_sreg_ == INVALID_SREG) ||
173 (rl_dest.s_reg_low != live_sreg_));
174 live_sreg_ = rl_dest.s_reg_low;
175 }
176 LIR* def_start;
177 LIR* def_end;
178 DCHECK(!rl_dest.wide);
179 DCHECK(!rl_src.wide);
180 rl_src = UpdateLoc(rl_src);
181 rl_dest = UpdateLoc(rl_dest);
182 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800183 if (IsLive(rl_src.reg) ||
184 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700185 (rl_dest.location == kLocPhysReg)) {
186 // Src is live/promoted or Dest has assigned reg.
187 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800188 OpRegCopy(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700189 } else {
190 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000191 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800192 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700193 }
194 } else {
195 // Load Src either into promoted Dest or temps allocated for Dest
196 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800197 LoadValueDirect(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700198 }
199
200 // Dest is now live and dirty (until/if we flush it to home location)
buzbee091cc402014-03-31 10:14:40 -0700201 MarkLive(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700202 MarkDirty(rl_dest);
203
204
205 ResetDefLoc(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700206 if (IsDirty(rl_dest.reg) && LiveOut(rl_dest.s_reg_low)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700207 def_start = last_lir_insn_;
buzbee695d13a2014-04-19 13:32:20 -0700208 Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700209 MarkClean(rl_dest);
210 def_end = last_lir_insn_;
211 if (!rl_dest.ref) {
212 // Exclude references from store elimination
213 MarkDef(rl_dest, def_start, def_end);
214 }
215 }
216}
217
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700218RegLocation Mir2Lir::LoadValueWide(RegLocation rl_src, RegisterClass op_kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700219 DCHECK(rl_src.wide);
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100220 rl_src = UpdateLocWide(rl_src);
221 if (rl_src.location == kLocPhysReg) {
222 if (!RegClassMatches(op_kind, rl_src.reg)) {
223 // Wrong register class, realloc, copy and transfer ownership.
224 RegStorage new_regs = AllocTypedTempWide(rl_src.fp, op_kind);
225 OpRegCopyWide(new_regs, rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700226 // Clobber the old regs.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100227 Clobber(rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700228 // ...and mark the new ones live.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100229 rl_src.reg = new_regs;
buzbee082833c2014-05-17 23:16:26 -0700230 MarkLive(rl_src);
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100231 }
232 return rl_src;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700233 }
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100234
235 DCHECK_NE(rl_src.s_reg_low, INVALID_SREG);
236 DCHECK_NE(GetSRegHi(rl_src.s_reg_low), INVALID_SREG);
237 rl_src.reg = AllocTypedTempWide(rl_src.fp, op_kind);
238 LoadValueDirectWide(rl_src, rl_src.reg);
239 rl_src.location = kLocPhysReg;
240 MarkLive(rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700241 return rl_src;
242}
243
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700244void Mir2Lir::StoreValueWide(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700245 /*
246 * Sanity checking - should never try to store to the same
247 * ssa name during the compilation of a single instruction
248 * without an intervening ClobberSReg().
249 */
250 if (kIsDebugBuild) {
251 DCHECK((live_sreg_ == INVALID_SREG) ||
252 (rl_dest.s_reg_low != live_sreg_));
253 live_sreg_ = rl_dest.s_reg_low;
254 }
255 LIR* def_start;
256 LIR* def_end;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700257 DCHECK(rl_dest.wide);
258 DCHECK(rl_src.wide);
Alexei Zavjalovc17ebe82014-02-26 10:38:23 +0700259 rl_src = UpdateLocWide(rl_src);
260 rl_dest = UpdateLocWide(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700261 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800262 if (IsLive(rl_src.reg) ||
263 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700264 (rl_dest.location == kLocPhysReg)) {
buzbee30adc732014-05-09 15:10:18 -0700265 /*
266 * If src reg[s] are tied to the original Dalvik vreg via liveness or promotion, we
267 * can't repurpose them. Similarly, if the dest reg[s] are tied to Dalvik vregs via
268 * promotion, we can't just re-assign. In these cases, we have to copy.
269 */
Brian Carlstrom7940e442013-07-12 13:46:57 -0700270 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800271 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700272 } else {
273 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000274 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800275 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700276 }
277 } else {
278 // Load Src either into promoted Dest or temps allocated for Dest
279 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800280 LoadValueDirectWide(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700281 }
282
283 // Dest is now live and dirty (until/if we flush it to home location)
buzbee091cc402014-03-31 10:14:40 -0700284 MarkLive(rl_dest);
285 MarkWide(rl_dest.reg);
286 MarkDirty(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700287
288 ResetDefLocWide(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700289 if (IsDirty(rl_dest.reg) && (LiveOut(rl_dest.s_reg_low) ||
290 LiveOut(GetSRegHi(rl_dest.s_reg_low)))) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700291 def_start = last_lir_insn_;
292 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
293 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
Vladimir Marko455759b2014-05-06 20:49:36 +0100294 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, k64);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700295 MarkClean(rl_dest);
296 def_end = last_lir_insn_;
297 MarkDefWide(rl_dest, def_start, def_end);
298 }
299}
300
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800301void Mir2Lir::StoreFinalValue(RegLocation rl_dest, RegLocation rl_src) {
302 DCHECK_EQ(rl_src.location, kLocPhysReg);
303
304 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800305 OpRegCopy(rl_dest.reg, rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800306 } else {
307 // Just re-assign the register. Dest gets Src's reg.
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800308 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000309 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800310 Clobber(rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800311 }
312
313 // Dest is now live and dirty (until/if we flush it to home location)
buzbee091cc402014-03-31 10:14:40 -0700314 MarkLive(rl_dest);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800315 MarkDirty(rl_dest);
316
317
318 ResetDefLoc(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700319 if (IsDirty(rl_dest.reg) && LiveOut(rl_dest.s_reg_low)) {
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800320 LIR *def_start = last_lir_insn_;
buzbee695d13a2014-04-19 13:32:20 -0700321 Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800322 MarkClean(rl_dest);
323 LIR *def_end = last_lir_insn_;
324 if (!rl_dest.ref) {
325 // Exclude references from store elimination
326 MarkDef(rl_dest, def_start, def_end);
327 }
328 }
329}
330
Mark Mendelle02d48f2014-01-15 11:19:23 -0800331void Mir2Lir::StoreFinalValueWide(RegLocation rl_dest, RegLocation rl_src) {
Mark Mendelle02d48f2014-01-15 11:19:23 -0800332 DCHECK(rl_dest.wide);
333 DCHECK(rl_src.wide);
334 DCHECK_EQ(rl_src.location, kLocPhysReg);
335
336 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800337 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800338 } else {
339 // Just re-assign the registers. Dest gets Src's regs.
Mark Mendelle02d48f2014-01-15 11:19:23 -0800340 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000341 rl_dest.reg = rl_src.reg;
buzbee091cc402014-03-31 10:14:40 -0700342 Clobber(rl_src.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800343 }
344
345 // Dest is now live and dirty (until/if we flush it to home location).
buzbee091cc402014-03-31 10:14:40 -0700346 MarkLive(rl_dest);
347 MarkWide(rl_dest.reg);
348 MarkDirty(rl_dest);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800349
350 ResetDefLocWide(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700351 if (IsDirty(rl_dest.reg) && (LiveOut(rl_dest.s_reg_low) ||
352 LiveOut(GetSRegHi(rl_dest.s_reg_low)))) {
Mark Mendelle02d48f2014-01-15 11:19:23 -0800353 LIR *def_start = last_lir_insn_;
354 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
355 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
Vladimir Marko455759b2014-05-06 20:49:36 +0100356 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, k64);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800357 MarkClean(rl_dest);
358 LIR *def_end = last_lir_insn_;
359 MarkDefWide(rl_dest, def_start, def_end);
360 }
361}
362
Brian Carlstrom7940e442013-07-12 13:46:57 -0700363/* Utilities to load the current Method* */
buzbee2700f7e2014-03-07 09:46:20 -0800364void Mir2Lir::LoadCurrMethodDirect(RegStorage r_tgt) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700365 LoadValueDirectFixed(mir_graph_->GetMethodLoc(), r_tgt);
366}
367
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700368RegLocation Mir2Lir::LoadCurrMethod() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700369 return LoadValue(mir_graph_->GetMethodLoc(), kCoreReg);
370}
371
Mark Mendelle02d48f2014-01-15 11:19:23 -0800372RegLocation Mir2Lir::ForceTemp(RegLocation loc) {
373 DCHECK(!loc.wide);
374 DCHECK(loc.location == kLocPhysReg);
buzbee091cc402014-03-31 10:14:40 -0700375 DCHECK(!loc.reg.IsFloat());
buzbee2700f7e2014-03-07 09:46:20 -0800376 if (IsTemp(loc.reg)) {
377 Clobber(loc.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800378 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800379 RegStorage temp_low = AllocTemp();
380 OpRegCopy(temp_low, loc.reg);
381 loc.reg = temp_low;
Mark Mendelle02d48f2014-01-15 11:19:23 -0800382 }
383
384 // Ensure that this doesn't represent the original SR any more.
385 loc.s_reg_low = INVALID_SREG;
386 return loc;
387}
388
buzbee091cc402014-03-31 10:14:40 -0700389// FIXME: will need an update for 64-bit core regs.
Mark Mendelle02d48f2014-01-15 11:19:23 -0800390RegLocation Mir2Lir::ForceTempWide(RegLocation loc) {
391 DCHECK(loc.wide);
392 DCHECK(loc.location == kLocPhysReg);
buzbee091cc402014-03-31 10:14:40 -0700393 DCHECK(!loc.reg.IsFloat());
394 if (IsTemp(loc.reg.GetLow())) {
395 Clobber(loc.reg.GetLow());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800396 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800397 RegStorage temp_low = AllocTemp();
398 OpRegCopy(temp_low, loc.reg.GetLow());
399 loc.reg.SetLowReg(temp_low.GetReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800400 }
buzbee091cc402014-03-31 10:14:40 -0700401 if (IsTemp(loc.reg.GetHigh())) {
402 Clobber(loc.reg.GetHigh());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800403 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800404 RegStorage temp_high = AllocTemp();
405 OpRegCopy(temp_high, loc.reg.GetHigh());
406 loc.reg.SetHighReg(temp_high.GetReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800407 }
408
409 // Ensure that this doesn't represent the original SR any more.
410 loc.s_reg_low = INVALID_SREG;
411 return loc;
412}
413
Brian Carlstrom7940e442013-07-12 13:46:57 -0700414} // namespace art