blob: 897d86d09a90633a3491f623f57544e837129504 [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.
68 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), temp_reg, kWord);
69 }
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
77/* Load a word at base + displacement. Displacement must be word multiple */
buzbee2700f7e2014-03-07 09:46:20 -080078LIR* Mir2Lir::LoadWordDisp(RegStorage r_base, int displacement, RegStorage r_dest) {
79 return LoadBaseDisp(r_base, displacement, r_dest, kWord, INVALID_SREG);
Brian Carlstrom7940e442013-07-12 13:46:57 -070080}
81
buzbee2700f7e2014-03-07 09:46:20 -080082LIR* Mir2Lir::StoreWordDisp(RegStorage r_base, int displacement, RegStorage r_src) {
83 return StoreBaseDisp(r_base, displacement, r_src, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -070084}
85
86/*
87 * Load a Dalvik register into a physical register. Take care when
88 * using this routine, as it doesn't perform any bookkeeping regarding
89 * register liveness. That is the responsibility of the caller.
90 */
buzbee2700f7e2014-03-07 09:46:20 -080091void Mir2Lir::LoadValueDirect(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070092 rl_src = UpdateLoc(rl_src);
93 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -080094 OpRegCopy(r_dest, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070095 } else if (IsInexpensiveConstant(rl_src)) {
96 LoadConstantNoClobber(r_dest, mir_graph_->ConstantValue(rl_src));
97 } else {
98 DCHECK((rl_src.location == kLocDalvikFrame) ||
99 (rl_src.location == kLocCompilerTemp));
100 LoadWordDisp(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest);
101 }
102}
103
104/*
105 * Similar to LoadValueDirect, but clobbers and allocates the target
106 * register. Should be used when loading to a fixed register (for example,
107 * loading arguments to an out of line call.
108 */
buzbee2700f7e2014-03-07 09:46:20 -0800109void Mir2Lir::LoadValueDirectFixed(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700110 Clobber(r_dest);
111 MarkInUse(r_dest);
112 LoadValueDirect(rl_src, r_dest);
113}
114
115/*
116 * Load a Dalvik register pair into a physical register[s]. Take care when
117 * using this routine, as it doesn't perform any bookkeeping regarding
118 * register liveness. That is the responsibility of the caller.
119 */
buzbee2700f7e2014-03-07 09:46:20 -0800120void Mir2Lir::LoadValueDirectWide(RegLocation rl_src, RegStorage r_dest) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700121 rl_src = UpdateLocWide(rl_src);
122 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800123 OpRegCopyWide(r_dest, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124 } else if (IsInexpensiveConstant(rl_src)) {
buzbee2700f7e2014-03-07 09:46:20 -0800125 LoadConstantWide(r_dest, mir_graph_->ConstantValueWide(rl_src));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700126 } else {
127 DCHECK((rl_src.location == kLocDalvikFrame) ||
128 (rl_src.location == kLocCompilerTemp));
buzbee2700f7e2014-03-07 09:46:20 -0800129 LoadBaseDispWide(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest, INVALID_SREG);
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) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700145 rl_src = EvalLoc(rl_src, op_kind, false);
146 if (IsInexpensiveConstant(rl_src) || rl_src.location != kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800147 LoadValueDirect(rl_src, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 rl_src.location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800149 MarkLive(rl_src.reg, rl_src.s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700150 }
151 return rl_src;
152}
153
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700154void Mir2Lir::StoreValue(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700155 /*
156 * Sanity checking - should never try to store to the same
157 * ssa name during the compilation of a single instruction
158 * without an intervening ClobberSReg().
159 */
160 if (kIsDebugBuild) {
161 DCHECK((live_sreg_ == INVALID_SREG) ||
162 (rl_dest.s_reg_low != live_sreg_));
163 live_sreg_ = rl_dest.s_reg_low;
164 }
165 LIR* def_start;
166 LIR* def_end;
167 DCHECK(!rl_dest.wide);
168 DCHECK(!rl_src.wide);
169 rl_src = UpdateLoc(rl_src);
170 rl_dest = UpdateLoc(rl_dest);
171 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800172 if (IsLive(rl_src.reg) ||
173 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700174 (rl_dest.location == kLocPhysReg)) {
175 // Src is live/promoted or Dest has assigned reg.
176 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800177 OpRegCopy(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700178 } else {
179 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000180 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800181 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700182 }
183 } else {
184 // Load Src either into promoted Dest or temps allocated for Dest
185 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800186 LoadValueDirect(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700187 }
188
189 // Dest is now live and dirty (until/if we flush it to home location)
buzbee2700f7e2014-03-07 09:46:20 -0800190 MarkLive(rl_dest.reg, rl_dest.s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700191 MarkDirty(rl_dest);
192
193
194 ResetDefLoc(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800195 if (IsDirty(rl_dest.reg) && oat_live_out(rl_dest.s_reg_low)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700196 def_start = last_lir_insn_;
buzbee2700f7e2014-03-07 09:46:20 -0800197 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, kWord);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700198 MarkClean(rl_dest);
199 def_end = last_lir_insn_;
200 if (!rl_dest.ref) {
201 // Exclude references from store elimination
202 MarkDef(rl_dest, def_start, def_end);
203 }
204 }
205}
206
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700207RegLocation Mir2Lir::LoadValueWide(RegLocation rl_src, RegisterClass op_kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700208 DCHECK(rl_src.wide);
209 rl_src = EvalLoc(rl_src, op_kind, false);
210 if (IsInexpensiveConstant(rl_src) || rl_src.location != kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800211 LoadValueDirectWide(rl_src, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700212 rl_src.location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800213 MarkLive(rl_src.reg.GetLow(), rl_src.s_reg_low);
214 MarkLive(rl_src.reg.GetHigh(), GetSRegHi(rl_src.s_reg_low));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700215 }
216 return rl_src;
217}
218
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700219void Mir2Lir::StoreValueWide(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700220 /*
221 * Sanity checking - should never try to store to the same
222 * ssa name during the compilation of a single instruction
223 * without an intervening ClobberSReg().
224 */
225 if (kIsDebugBuild) {
226 DCHECK((live_sreg_ == INVALID_SREG) ||
227 (rl_dest.s_reg_low != live_sreg_));
228 live_sreg_ = rl_dest.s_reg_low;
229 }
230 LIR* def_start;
231 LIR* def_end;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700232 DCHECK(rl_dest.wide);
233 DCHECK(rl_src.wide);
Alexei Zavjalovc17ebe82014-02-26 10:38:23 +0700234 rl_src = UpdateLocWide(rl_src);
235 rl_dest = UpdateLocWide(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700236 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800237 if (IsLive(rl_src.reg) ||
238 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700239 (rl_dest.location == kLocPhysReg)) {
240 // Src is live or promoted or Dest has assigned reg.
241 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800242 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700243 } else {
244 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000245 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800246 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700247 }
248 } else {
249 // Load Src either into promoted Dest or temps allocated for Dest
250 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800251 LoadValueDirectWide(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700252 }
253
254 // Dest is now live and dirty (until/if we flush it to home location)
buzbee2700f7e2014-03-07 09:46:20 -0800255 MarkLive(rl_dest.reg.GetLow(), rl_dest.s_reg_low);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000256
257 // Does this wide value live in two registers (or one vector one)?
buzbee2700f7e2014-03-07 09:46:20 -0800258 // FIXME: wide reg update.
259 if (rl_dest.reg.GetLowReg() != rl_dest.reg.GetHighReg()) {
260 MarkLive(rl_dest.reg.GetHigh(), GetSRegHi(rl_dest.s_reg_low));
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000261 MarkDirty(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800262 MarkPair(rl_dest.reg.GetLowReg(), rl_dest.reg.GetHighReg());
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000263 } else {
264 // This must be an x86 vector register value,
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700265 DCHECK(IsFpReg(rl_dest.reg) && (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64));
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000266 MarkDirty(rl_dest);
267 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700268
269
270 ResetDefLocWide(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800271 if (IsDirty(rl_dest.reg) && (oat_live_out(rl_dest.s_reg_low) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700272 oat_live_out(GetSRegHi(rl_dest.s_reg_low)))) {
273 def_start = last_lir_insn_;
274 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
275 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
buzbee2700f7e2014-03-07 09:46:20 -0800276 StoreBaseDispWide(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700277 MarkClean(rl_dest);
278 def_end = last_lir_insn_;
279 MarkDefWide(rl_dest, def_start, def_end);
280 }
281}
282
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800283void Mir2Lir::StoreFinalValue(RegLocation rl_dest, RegLocation rl_src) {
284 DCHECK_EQ(rl_src.location, kLocPhysReg);
285
286 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800287 OpRegCopy(rl_dest.reg, rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800288 } else {
289 // Just re-assign the register. Dest gets Src's reg.
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800290 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000291 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800292 Clobber(rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800293 }
294
295 // Dest is now live and dirty (until/if we flush it to home location)
buzbee2700f7e2014-03-07 09:46:20 -0800296 MarkLive(rl_dest.reg, rl_dest.s_reg_low);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800297 MarkDirty(rl_dest);
298
299
300 ResetDefLoc(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800301 if (IsDirty(rl_dest.reg) &&
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800302 oat_live_out(rl_dest.s_reg_low)) {
303 LIR *def_start = last_lir_insn_;
buzbee2700f7e2014-03-07 09:46:20 -0800304 StoreBaseDisp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg, kWord);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800305 MarkClean(rl_dest);
306 LIR *def_end = last_lir_insn_;
307 if (!rl_dest.ref) {
308 // Exclude references from store elimination
309 MarkDef(rl_dest, def_start, def_end);
310 }
311 }
312}
313
Mark Mendelle02d48f2014-01-15 11:19:23 -0800314void Mir2Lir::StoreFinalValueWide(RegLocation rl_dest, RegLocation rl_src) {
buzbee2700f7e2014-03-07 09:46:20 -0800315 DCHECK_EQ(IsFpReg(rl_src.reg.GetLowReg()), IsFpReg(rl_src.reg.GetHighReg()));
Mark Mendelle02d48f2014-01-15 11:19:23 -0800316 DCHECK(rl_dest.wide);
317 DCHECK(rl_src.wide);
318 DCHECK_EQ(rl_src.location, kLocPhysReg);
319
320 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800321 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800322 } else {
323 // Just re-assign the registers. Dest gets Src's regs.
Mark Mendelle02d48f2014-01-15 11:19:23 -0800324 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000325 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800326 Clobber(rl_src.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000327 Clobber(rl_src.reg.GetHighReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800328 }
329
330 // Dest is now live and dirty (until/if we flush it to home location).
buzbee2700f7e2014-03-07 09:46:20 -0800331 MarkLive(rl_dest.reg.GetLow(), rl_dest.s_reg_low);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800332
333 // Does this wide value live in two registers (or one vector one)?
buzbee2700f7e2014-03-07 09:46:20 -0800334 // FIXME: wide reg.
335 if (rl_dest.reg.GetLowReg() != rl_dest.reg.GetHighReg()) {
336 MarkLive(rl_dest.reg.GetHigh(), GetSRegHi(rl_dest.s_reg_low));
Mark Mendelle02d48f2014-01-15 11:19:23 -0800337 MarkDirty(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800338 MarkPair(rl_dest.reg.GetLowReg(), rl_dest.reg.GetHighReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800339 } else {
340 // This must be an x86 vector register value,
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700341 DCHECK(IsFpReg(rl_dest.reg) && (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64));
Mark Mendelle02d48f2014-01-15 11:19:23 -0800342 MarkDirty(rl_dest);
343 }
344
345 ResetDefLocWide(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800346 if (IsDirty(rl_dest.reg) && (oat_live_out(rl_dest.s_reg_low) ||
Mark Mendelle02d48f2014-01-15 11:19:23 -0800347 oat_live_out(GetSRegHi(rl_dest.s_reg_low)))) {
348 LIR *def_start = last_lir_insn_;
349 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
350 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
buzbee2700f7e2014-03-07 09:46:20 -0800351 StoreBaseDispWide(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800352 MarkClean(rl_dest);
353 LIR *def_end = last_lir_insn_;
354 MarkDefWide(rl_dest, def_start, def_end);
355 }
356}
357
Brian Carlstrom7940e442013-07-12 13:46:57 -0700358/* Utilities to load the current Method* */
buzbee2700f7e2014-03-07 09:46:20 -0800359void Mir2Lir::LoadCurrMethodDirect(RegStorage r_tgt) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700360 LoadValueDirectFixed(mir_graph_->GetMethodLoc(), r_tgt);
361}
362
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700363RegLocation Mir2Lir::LoadCurrMethod() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700364 return LoadValue(mir_graph_->GetMethodLoc(), kCoreReg);
365}
366
Mark Mendelle02d48f2014-01-15 11:19:23 -0800367RegLocation Mir2Lir::ForceTemp(RegLocation loc) {
368 DCHECK(!loc.wide);
369 DCHECK(loc.location == kLocPhysReg);
buzbee2700f7e2014-03-07 09:46:20 -0800370 DCHECK(!IsFpReg(loc.reg));
371 if (IsTemp(loc.reg)) {
372 Clobber(loc.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800373 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800374 RegStorage temp_low = AllocTemp();
375 OpRegCopy(temp_low, loc.reg);
376 loc.reg = temp_low;
Mark Mendelle02d48f2014-01-15 11:19:23 -0800377 }
378
379 // Ensure that this doesn't represent the original SR any more.
380 loc.s_reg_low = INVALID_SREG;
381 return loc;
382}
383
buzbee2700f7e2014-03-07 09:46:20 -0800384// FIXME: wide regs.
Mark Mendelle02d48f2014-01-15 11:19:23 -0800385RegLocation Mir2Lir::ForceTempWide(RegLocation loc) {
386 DCHECK(loc.wide);
387 DCHECK(loc.location == kLocPhysReg);
buzbee2700f7e2014-03-07 09:46:20 -0800388 DCHECK(!IsFpReg(loc.reg.GetLowReg()));
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000389 DCHECK(!IsFpReg(loc.reg.GetHighReg()));
buzbee2700f7e2014-03-07 09:46:20 -0800390 if (IsTemp(loc.reg.GetLowReg())) {
391 Clobber(loc.reg.GetLowReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800392 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800393 RegStorage temp_low = AllocTemp();
394 OpRegCopy(temp_low, loc.reg.GetLow());
395 loc.reg.SetLowReg(temp_low.GetReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800396 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000397 if (IsTemp(loc.reg.GetHighReg())) {
398 Clobber(loc.reg.GetHighReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800399 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800400 RegStorage temp_high = AllocTemp();
401 OpRegCopy(temp_high, loc.reg.GetHigh());
402 loc.reg.SetHighReg(temp_high.GetReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800403 }
404
405 // Ensure that this doesn't represent the original SR any more.
406 loc.s_reg_low = INVALID_SREG;
407 return loc;
408}
409
Brian Carlstrom7940e442013-07-12 13:46:57 -0700410} // namespace art