blob: 6469d9c4f13908d5ec9d1f2c16357e5b3a1fcd97 [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.
Vladimir Marko8dea81c2014-06-06 14:50:36 +010068 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
buzbee695d13a2014-04-19 13:32:20 -070069 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), temp_reg, k32);
Brian Carlstrom7940e442013-07-12 13:46:57 -070070 }
buzbee2700f7e2014-03-07 09:46:20 -080071 if (!zero_reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070072 FreeTemp(temp_reg);
73 }
74 }
75 }
76}
77
Brian Carlstrom7940e442013-07-12 13:46:57 -070078/*
79 * Load a Dalvik register into a physical register. Take care when
80 * using this routine, as it doesn't perform any bookkeeping regarding
81 * register liveness. That is the responsibility of the caller.
82 */
buzbee2700f7e2014-03-07 09:46:20 -080083void Mir2Lir::LoadValueDirect(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070084 rl_src = UpdateLoc(rl_src);
85 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -080086 OpRegCopy(r_dest, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070087 } else if (IsInexpensiveConstant(rl_src)) {
buzbee695d13a2014-04-19 13:32:20 -070088 // On 64-bit targets, will sign extend. Make sure constant reference is always NULL.
89 DCHECK(!rl_src.ref || (mir_graph_->ConstantValue(rl_src) == 0));
Brian Carlstrom7940e442013-07-12 13:46:57 -070090 LoadConstantNoClobber(r_dest, mir_graph_->ConstantValue(rl_src));
91 } else {
92 DCHECK((rl_src.location == kLocDalvikFrame) ||
93 (rl_src.location == kLocCompilerTemp));
Vladimir Marko8dea81c2014-06-06 14:50:36 +010094 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
buzbee695d13a2014-04-19 13:32:20 -070095 if (rl_src.ref) {
96 LoadRefDisp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest);
97 } else {
98 Load32Disp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest);
99 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700100 }
101}
102
103/*
104 * Similar to LoadValueDirect, but clobbers and allocates the target
105 * register. Should be used when loading to a fixed register (for example,
106 * loading arguments to an out of line call.
107 */
buzbee2700f7e2014-03-07 09:46:20 -0800108void Mir2Lir::LoadValueDirectFixed(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700109 Clobber(r_dest);
110 MarkInUse(r_dest);
111 LoadValueDirect(rl_src, r_dest);
112}
113
114/*
115 * Load a Dalvik register pair into a physical register[s]. Take care when
116 * using this routine, as it doesn't perform any bookkeeping regarding
117 * register liveness. That is the responsibility of the caller.
118 */
buzbee2700f7e2014-03-07 09:46:20 -0800119void Mir2Lir::LoadValueDirectWide(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700120 rl_src = UpdateLocWide(rl_src);
121 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800122 OpRegCopyWide(r_dest, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123 } else if (IsInexpensiveConstant(rl_src)) {
buzbee2700f7e2014-03-07 09:46:20 -0800124 LoadConstantWide(r_dest, mir_graph_->ConstantValueWide(rl_src));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700125 } else {
126 DCHECK((rl_src.location == kLocDalvikFrame) ||
127 (rl_src.location == kLocCompilerTemp));
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100128 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Vladimir Marko3bf7c602014-05-07 14:55:43 +0100129 LoadBaseDisp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest, k64);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700130 }
131}
132
133/*
134 * Similar to LoadValueDirect, but clobbers and allocates the target
135 * registers. Should be used when loading to a fixed registers (for example,
136 * loading arguments to an out of line call.
137 */
buzbee2700f7e2014-03-07 09:46:20 -0800138void Mir2Lir::LoadValueDirectWideFixed(RegLocation rl_src, RegStorage r_dest) {
139 Clobber(r_dest);
140 MarkInUse(r_dest);
141 LoadValueDirectWide(rl_src, r_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700142}
143
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700144RegLocation Mir2Lir::LoadValue(RegLocation rl_src, RegisterClass op_kind) {
buzbeea0cd2d72014-06-01 09:33:49 -0700145 DCHECK(!rl_src.ref || op_kind == kRefReg);
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100146 rl_src = UpdateLoc(rl_src);
147 if (rl_src.location == kLocPhysReg) {
148 if (!RegClassMatches(op_kind, rl_src.reg)) {
149 // Wrong register class, realloc, copy and transfer ownership.
150 RegStorage new_reg = AllocTypedTemp(rl_src.fp, op_kind);
151 OpRegCopy(new_reg, rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700152 // Clobber the old reg.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100153 Clobber(rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700154 // ...and mark the new one live.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100155 rl_src.reg = new_reg;
buzbee082833c2014-05-17 23:16:26 -0700156 MarkLive(rl_src);
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100157 }
158 return rl_src;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700159 }
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100160
161 DCHECK_NE(rl_src.s_reg_low, INVALID_SREG);
162 rl_src.reg = AllocTypedTemp(rl_src.fp, op_kind);
163 LoadValueDirect(rl_src, rl_src.reg);
164 rl_src.location = kLocPhysReg;
165 MarkLive(rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700166 return rl_src;
167}
168
buzbeea0cd2d72014-06-01 09:33:49 -0700169RegLocation Mir2Lir::LoadValue(RegLocation rl_src) {
170 return LoadValue(rl_src, LocToRegClass(rl_src));
171}
172
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700173void Mir2Lir::StoreValue(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700174 /*
175 * Sanity checking - should never try to store to the same
176 * ssa name during the compilation of a single instruction
177 * without an intervening ClobberSReg().
178 */
179 if (kIsDebugBuild) {
180 DCHECK((live_sreg_ == INVALID_SREG) ||
181 (rl_dest.s_reg_low != live_sreg_));
182 live_sreg_ = rl_dest.s_reg_low;
183 }
184 LIR* def_start;
185 LIR* def_end;
186 DCHECK(!rl_dest.wide);
187 DCHECK(!rl_src.wide);
188 rl_src = UpdateLoc(rl_src);
189 rl_dest = UpdateLoc(rl_dest);
190 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800191 if (IsLive(rl_src.reg) ||
192 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700193 (rl_dest.location == kLocPhysReg)) {
194 // Src is live/promoted or Dest has assigned reg.
195 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800196 OpRegCopy(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700197 } else {
198 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000199 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800200 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700201 }
202 } else {
203 // Load Src either into promoted Dest or temps allocated for Dest
204 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800205 LoadValueDirect(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700206 }
207
208 // Dest is now live and dirty (until/if we flush it to home location)
buzbee091cc402014-03-31 10:14:40 -0700209 MarkLive(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700210 MarkDirty(rl_dest);
211
212
213 ResetDefLoc(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700214 if (IsDirty(rl_dest.reg) && LiveOut(rl_dest.s_reg_low)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700215 def_start = last_lir_insn_;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100216 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
buzbee695d13a2014-04-19 13:32:20 -0700217 Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700218 MarkClean(rl_dest);
219 def_end = last_lir_insn_;
220 if (!rl_dest.ref) {
221 // Exclude references from store elimination
222 MarkDef(rl_dest, def_start, def_end);
223 }
224 }
225}
226
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700227RegLocation Mir2Lir::LoadValueWide(RegLocation rl_src, RegisterClass op_kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228 DCHECK(rl_src.wide);
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100229 rl_src = UpdateLocWide(rl_src);
230 if (rl_src.location == kLocPhysReg) {
231 if (!RegClassMatches(op_kind, rl_src.reg)) {
232 // Wrong register class, realloc, copy and transfer ownership.
233 RegStorage new_regs = AllocTypedTempWide(rl_src.fp, op_kind);
234 OpRegCopyWide(new_regs, rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700235 // Clobber the old regs.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100236 Clobber(rl_src.reg);
buzbee082833c2014-05-17 23:16:26 -0700237 // ...and mark the new ones live.
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100238 rl_src.reg = new_regs;
buzbee082833c2014-05-17 23:16:26 -0700239 MarkLive(rl_src);
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100240 }
241 return rl_src;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700242 }
Vladimir Marko0dc242d2014-05-12 16:22:14 +0100243
244 DCHECK_NE(rl_src.s_reg_low, INVALID_SREG);
245 DCHECK_NE(GetSRegHi(rl_src.s_reg_low), INVALID_SREG);
246 rl_src.reg = AllocTypedTempWide(rl_src.fp, op_kind);
247 LoadValueDirectWide(rl_src, rl_src.reg);
248 rl_src.location = kLocPhysReg;
249 MarkLive(rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700250 return rl_src;
251}
252
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700253void Mir2Lir::StoreValueWide(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700254 /*
255 * Sanity checking - should never try to store to the same
256 * ssa name during the compilation of a single instruction
257 * without an intervening ClobberSReg().
258 */
259 if (kIsDebugBuild) {
260 DCHECK((live_sreg_ == INVALID_SREG) ||
261 (rl_dest.s_reg_low != live_sreg_));
262 live_sreg_ = rl_dest.s_reg_low;
263 }
264 LIR* def_start;
265 LIR* def_end;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700266 DCHECK(rl_dest.wide);
267 DCHECK(rl_src.wide);
Alexei Zavjalovc17ebe82014-02-26 10:38:23 +0700268 rl_src = UpdateLocWide(rl_src);
269 rl_dest = UpdateLocWide(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700270 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800271 if (IsLive(rl_src.reg) ||
272 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700273 (rl_dest.location == kLocPhysReg)) {
buzbee30adc732014-05-09 15:10:18 -0700274 /*
275 * If src reg[s] are tied to the original Dalvik vreg via liveness or promotion, we
276 * can't repurpose them. Similarly, if the dest reg[s] are tied to Dalvik vregs via
277 * promotion, we can't just re-assign. In these cases, we have to copy.
278 */
Brian Carlstrom7940e442013-07-12 13:46:57 -0700279 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800280 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700281 } else {
282 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000283 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800284 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700285 }
286 } else {
287 // Load Src either into promoted Dest or temps allocated for Dest
288 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800289 LoadValueDirectWide(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700290 }
291
292 // Dest is now live and dirty (until/if we flush it to home location)
buzbee091cc402014-03-31 10:14:40 -0700293 MarkLive(rl_dest);
294 MarkWide(rl_dest.reg);
295 MarkDirty(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700296
297 ResetDefLocWide(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700298 if (IsDirty(rl_dest.reg) && (LiveOut(rl_dest.s_reg_low) ||
299 LiveOut(GetSRegHi(rl_dest.s_reg_low)))) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700300 def_start = last_lir_insn_;
301 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
302 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100303 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Vladimir Marko455759b2014-05-06 20:49:36 +0100304 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, k64);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700305 MarkClean(rl_dest);
306 def_end = last_lir_insn_;
307 MarkDefWide(rl_dest, def_start, def_end);
308 }
309}
310
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800311void Mir2Lir::StoreFinalValue(RegLocation rl_dest, RegLocation rl_src) {
312 DCHECK_EQ(rl_src.location, kLocPhysReg);
313
314 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800315 OpRegCopy(rl_dest.reg, rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800316 } else {
317 // Just re-assign the register. Dest gets Src's reg.
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800318 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000319 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800320 Clobber(rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800321 }
322
323 // Dest is now live and dirty (until/if we flush it to home location)
buzbee091cc402014-03-31 10:14:40 -0700324 MarkLive(rl_dest);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800325 MarkDirty(rl_dest);
326
327
328 ResetDefLoc(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700329 if (IsDirty(rl_dest.reg) && LiveOut(rl_dest.s_reg_low)) {
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800330 LIR *def_start = last_lir_insn_;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100331 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
buzbee695d13a2014-04-19 13:32:20 -0700332 Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800333 MarkClean(rl_dest);
334 LIR *def_end = last_lir_insn_;
335 if (!rl_dest.ref) {
336 // Exclude references from store elimination
337 MarkDef(rl_dest, def_start, def_end);
338 }
339 }
340}
341
Mark Mendelle02d48f2014-01-15 11:19:23 -0800342void Mir2Lir::StoreFinalValueWide(RegLocation rl_dest, RegLocation rl_src) {
Mark Mendelle02d48f2014-01-15 11:19:23 -0800343 DCHECK(rl_dest.wide);
344 DCHECK(rl_src.wide);
345 DCHECK_EQ(rl_src.location, kLocPhysReg);
346
347 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800348 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800349 } else {
350 // Just re-assign the registers. Dest gets Src's regs.
Mark Mendelle02d48f2014-01-15 11:19:23 -0800351 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000352 rl_dest.reg = rl_src.reg;
buzbee091cc402014-03-31 10:14:40 -0700353 Clobber(rl_src.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800354 }
355
356 // Dest is now live and dirty (until/if we flush it to home location).
buzbee091cc402014-03-31 10:14:40 -0700357 MarkLive(rl_dest);
358 MarkWide(rl_dest.reg);
359 MarkDirty(rl_dest);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800360
361 ResetDefLocWide(rl_dest);
buzbee091cc402014-03-31 10:14:40 -0700362 if (IsDirty(rl_dest.reg) && (LiveOut(rl_dest.s_reg_low) ||
363 LiveOut(GetSRegHi(rl_dest.s_reg_low)))) {
Mark Mendelle02d48f2014-01-15 11:19:23 -0800364 LIR *def_start = last_lir_insn_;
365 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
366 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100367 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Vladimir Marko455759b2014-05-06 20:49:36 +0100368 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, k64);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800369 MarkClean(rl_dest);
370 LIR *def_end = last_lir_insn_;
371 MarkDefWide(rl_dest, def_start, def_end);
372 }
373}
374
Brian Carlstrom7940e442013-07-12 13:46:57 -0700375/* Utilities to load the current Method* */
buzbee2700f7e2014-03-07 09:46:20 -0800376void Mir2Lir::LoadCurrMethodDirect(RegStorage r_tgt) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700377 LoadValueDirectFixed(mir_graph_->GetMethodLoc(), r_tgt);
378}
379
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700380RegLocation Mir2Lir::LoadCurrMethod() {
buzbeea0cd2d72014-06-01 09:33:49 -0700381 return LoadValue(mir_graph_->GetMethodLoc(), kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700382}
383
Mark Mendelle02d48f2014-01-15 11:19:23 -0800384RegLocation Mir2Lir::ForceTemp(RegLocation loc) {
385 DCHECK(!loc.wide);
386 DCHECK(loc.location == kLocPhysReg);
buzbee091cc402014-03-31 10:14:40 -0700387 DCHECK(!loc.reg.IsFloat());
buzbee2700f7e2014-03-07 09:46:20 -0800388 if (IsTemp(loc.reg)) {
389 Clobber(loc.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800390 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800391 RegStorage temp_low = AllocTemp();
392 OpRegCopy(temp_low, loc.reg);
393 loc.reg = temp_low;
Mark Mendelle02d48f2014-01-15 11:19:23 -0800394 }
395
396 // Ensure that this doesn't represent the original SR any more.
397 loc.s_reg_low = INVALID_SREG;
398 return loc;
399}
400
401RegLocation Mir2Lir::ForceTempWide(RegLocation loc) {
402 DCHECK(loc.wide);
403 DCHECK(loc.location == kLocPhysReg);
buzbee091cc402014-03-31 10:14:40 -0700404 DCHECK(!loc.reg.IsFloat());
Chao-ying Fue0ccdc02014-06-06 17:32:37 -0700405
406 if (!loc.reg.IsPair()) {
407 if (IsTemp(loc.reg)) {
408 Clobber(loc.reg);
409 } else {
410 RegStorage temp = AllocTempWide();
411 OpRegCopy(temp, loc.reg);
412 loc.reg = temp;
413 }
Mark Mendelle02d48f2014-01-15 11:19:23 -0800414 } else {
Chao-ying Fue0ccdc02014-06-06 17:32:37 -0700415 if (IsTemp(loc.reg.GetLow())) {
416 Clobber(loc.reg.GetLow());
417 } else {
418 RegStorage temp_low = AllocTemp();
419 OpRegCopy(temp_low, loc.reg.GetLow());
420 loc.reg.SetLowReg(temp_low.GetReg());
421 }
422 if (IsTemp(loc.reg.GetHigh())) {
423 Clobber(loc.reg.GetHigh());
424 } else {
425 RegStorage temp_high = AllocTemp();
426 OpRegCopy(temp_high, loc.reg.GetHigh());
427 loc.reg.SetHighReg(temp_high.GetReg());
428 }
Mark Mendelle02d48f2014-01-15 11:19:23 -0800429 }
430
431 // Ensure that this doesn't represent the original SR any more.
432 loc.s_reg_low = INVALID_SREG;
433 return loc;
434}
435
Brian Carlstrom7940e442013-07-12 13:46:57 -0700436} // namespace art