blob: 9808f7f36f5466c48127d325212f898be6ce4a76 [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));
buzbee2700f7e2014-03-07 09:46:20 -0800126 LoadBaseDispWide(TargetReg(kSp), SRegOffset(rl_src.s_reg_low), r_dest, INVALID_SREG);
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) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700142 rl_src = EvalLoc(rl_src, op_kind, false);
143 if (IsInexpensiveConstant(rl_src) || rl_src.location != kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800144 LoadValueDirect(rl_src, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700145 rl_src.location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800146 MarkLive(rl_src.reg, rl_src.s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700147 }
148 return rl_src;
149}
150
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700151void Mir2Lir::StoreValue(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700152 /*
153 * Sanity checking - should never try to store to the same
154 * ssa name during the compilation of a single instruction
155 * without an intervening ClobberSReg().
156 */
157 if (kIsDebugBuild) {
158 DCHECK((live_sreg_ == INVALID_SREG) ||
159 (rl_dest.s_reg_low != live_sreg_));
160 live_sreg_ = rl_dest.s_reg_low;
161 }
162 LIR* def_start;
163 LIR* def_end;
164 DCHECK(!rl_dest.wide);
165 DCHECK(!rl_src.wide);
166 rl_src = UpdateLoc(rl_src);
167 rl_dest = UpdateLoc(rl_dest);
168 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800169 if (IsLive(rl_src.reg) ||
170 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700171 (rl_dest.location == kLocPhysReg)) {
172 // Src is live/promoted or Dest has assigned reg.
173 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800174 OpRegCopy(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700175 } else {
176 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000177 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800178 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700179 }
180 } else {
181 // Load Src either into promoted Dest or temps allocated for Dest
182 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800183 LoadValueDirect(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700184 }
185
186 // Dest is now live and dirty (until/if we flush it to home location)
buzbee2700f7e2014-03-07 09:46:20 -0800187 MarkLive(rl_dest.reg, rl_dest.s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700188 MarkDirty(rl_dest);
189
190
191 ResetDefLoc(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800192 if (IsDirty(rl_dest.reg) && oat_live_out(rl_dest.s_reg_low)) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700193 def_start = last_lir_insn_;
buzbee695d13a2014-04-19 13:32:20 -0700194 Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700195 MarkClean(rl_dest);
196 def_end = last_lir_insn_;
197 if (!rl_dest.ref) {
198 // Exclude references from store elimination
199 MarkDef(rl_dest, def_start, def_end);
200 }
201 }
202}
203
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700204RegLocation Mir2Lir::LoadValueWide(RegLocation rl_src, RegisterClass op_kind) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700205 DCHECK(rl_src.wide);
206 rl_src = EvalLoc(rl_src, op_kind, false);
207 if (IsInexpensiveConstant(rl_src) || rl_src.location != kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800208 LoadValueDirectWide(rl_src, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700209 rl_src.location = kLocPhysReg;
buzbee2700f7e2014-03-07 09:46:20 -0800210 MarkLive(rl_src.reg.GetLow(), rl_src.s_reg_low);
Chao-ying Fucbd18b72014-04-03 15:09:37 -0700211 if (rl_src.reg.GetLowReg() != rl_src.reg.GetHighReg()) {
212 MarkLive(rl_src.reg.GetHigh(), GetSRegHi(rl_src.s_reg_low));
213 } else {
214 // This must be an x86 vector register value.
215 DCHECK(IsFpReg(rl_src.reg) && (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64));
216 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700217 }
218 return rl_src;
219}
220
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700221void Mir2Lir::StoreValueWide(RegLocation rl_dest, RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700222 /*
223 * Sanity checking - should never try to store to the same
224 * ssa name during the compilation of a single instruction
225 * without an intervening ClobberSReg().
226 */
227 if (kIsDebugBuild) {
228 DCHECK((live_sreg_ == INVALID_SREG) ||
229 (rl_dest.s_reg_low != live_sreg_));
230 live_sreg_ = rl_dest.s_reg_low;
231 }
232 LIR* def_start;
233 LIR* def_end;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700234 DCHECK(rl_dest.wide);
235 DCHECK(rl_src.wide);
Alexei Zavjalovc17ebe82014-02-26 10:38:23 +0700236 rl_src = UpdateLocWide(rl_src);
237 rl_dest = UpdateLocWide(rl_dest);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700238 if (rl_src.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800239 if (IsLive(rl_src.reg) ||
240 IsPromoted(rl_src.reg) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700241 (rl_dest.location == kLocPhysReg)) {
242 // Src is live or promoted or Dest has assigned reg.
243 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800244 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700245 } else {
246 // Just re-assign the registers. Dest gets Src's regs
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000247 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800248 Clobber(rl_src.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700249 }
250 } else {
251 // Load Src either into promoted Dest or temps allocated for Dest
252 rl_dest = EvalLoc(rl_dest, kAnyReg, false);
buzbee2700f7e2014-03-07 09:46:20 -0800253 LoadValueDirectWide(rl_src, rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700254 }
255
256 // Dest is now live and dirty (until/if we flush it to home location)
buzbee2700f7e2014-03-07 09:46:20 -0800257 MarkLive(rl_dest.reg.GetLow(), rl_dest.s_reg_low);
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000258
259 // Does this wide value live in two registers (or one vector one)?
buzbee2700f7e2014-03-07 09:46:20 -0800260 // FIXME: wide reg update.
261 if (rl_dest.reg.GetLowReg() != rl_dest.reg.GetHighReg()) {
262 MarkLive(rl_dest.reg.GetHigh(), GetSRegHi(rl_dest.s_reg_low));
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000263 MarkDirty(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800264 MarkPair(rl_dest.reg.GetLowReg(), rl_dest.reg.GetHighReg());
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000265 } else {
266 // This must be an x86 vector register value,
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700267 DCHECK(IsFpReg(rl_dest.reg) && (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64));
Bill Buzbeed61ba4b2014-01-13 21:44:01 +0000268 MarkDirty(rl_dest);
269 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700270
271
272 ResetDefLocWide(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800273 if (IsDirty(rl_dest.reg) && (oat_live_out(rl_dest.s_reg_low) ||
Brian Carlstrom7940e442013-07-12 13:46:57 -0700274 oat_live_out(GetSRegHi(rl_dest.s_reg_low)))) {
275 def_start = last_lir_insn_;
276 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
277 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
buzbee2700f7e2014-03-07 09:46:20 -0800278 StoreBaseDispWide(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700279 MarkClean(rl_dest);
280 def_end = last_lir_insn_;
281 MarkDefWide(rl_dest, def_start, def_end);
282 }
283}
284
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800285void Mir2Lir::StoreFinalValue(RegLocation rl_dest, RegLocation rl_src) {
286 DCHECK_EQ(rl_src.location, kLocPhysReg);
287
288 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800289 OpRegCopy(rl_dest.reg, rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800290 } else {
291 // Just re-assign the register. Dest gets Src's reg.
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800292 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000293 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800294 Clobber(rl_src.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800295 }
296
297 // Dest is now live and dirty (until/if we flush it to home location)
buzbee2700f7e2014-03-07 09:46:20 -0800298 MarkLive(rl_dest.reg, rl_dest.s_reg_low);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800299 MarkDirty(rl_dest);
300
301
302 ResetDefLoc(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800303 if (IsDirty(rl_dest.reg) &&
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800304 oat_live_out(rl_dest.s_reg_low)) {
305 LIR *def_start = last_lir_insn_;
buzbee695d13a2014-04-19 13:32:20 -0700306 Store32Disp(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Mark Mendellfeb2b4e2014-01-28 12:59:49 -0800307 MarkClean(rl_dest);
308 LIR *def_end = last_lir_insn_;
309 if (!rl_dest.ref) {
310 // Exclude references from store elimination
311 MarkDef(rl_dest, def_start, def_end);
312 }
313 }
314}
315
Mark Mendelle02d48f2014-01-15 11:19:23 -0800316void Mir2Lir::StoreFinalValueWide(RegLocation rl_dest, RegLocation rl_src) {
buzbee2700f7e2014-03-07 09:46:20 -0800317 DCHECK_EQ(IsFpReg(rl_src.reg.GetLowReg()), IsFpReg(rl_src.reg.GetHighReg()));
Mark Mendelle02d48f2014-01-15 11:19:23 -0800318 DCHECK(rl_dest.wide);
319 DCHECK(rl_src.wide);
320 DCHECK_EQ(rl_src.location, kLocPhysReg);
321
322 if (rl_dest.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -0800323 OpRegCopyWide(rl_dest.reg, rl_src.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800324 } else {
325 // Just re-assign the registers. Dest gets Src's regs.
Mark Mendelle02d48f2014-01-15 11:19:23 -0800326 rl_dest.location = kLocPhysReg;
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000327 rl_dest.reg = rl_src.reg;
buzbee2700f7e2014-03-07 09:46:20 -0800328 Clobber(rl_src.reg.GetLowReg());
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000329 Clobber(rl_src.reg.GetHighReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800330 }
331
332 // Dest is now live and dirty (until/if we flush it to home location).
buzbee2700f7e2014-03-07 09:46:20 -0800333 MarkLive(rl_dest.reg.GetLow(), rl_dest.s_reg_low);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800334
335 // Does this wide value live in two registers (or one vector one)?
buzbee2700f7e2014-03-07 09:46:20 -0800336 // FIXME: wide reg.
337 if (rl_dest.reg.GetLowReg() != rl_dest.reg.GetHighReg()) {
338 MarkLive(rl_dest.reg.GetHigh(), GetSRegHi(rl_dest.s_reg_low));
Mark Mendelle02d48f2014-01-15 11:19:23 -0800339 MarkDirty(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800340 MarkPair(rl_dest.reg.GetLowReg(), rl_dest.reg.GetHighReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800341 } else {
342 // This must be an x86 vector register value,
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700343 DCHECK(IsFpReg(rl_dest.reg) && (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64));
Mark Mendelle02d48f2014-01-15 11:19:23 -0800344 MarkDirty(rl_dest);
345 }
346
347 ResetDefLocWide(rl_dest);
buzbee2700f7e2014-03-07 09:46:20 -0800348 if (IsDirty(rl_dest.reg) && (oat_live_out(rl_dest.s_reg_low) ||
Mark Mendelle02d48f2014-01-15 11:19:23 -0800349 oat_live_out(GetSRegHi(rl_dest.s_reg_low)))) {
350 LIR *def_start = last_lir_insn_;
351 DCHECK_EQ((mir_graph_->SRegToVReg(rl_dest.s_reg_low)+1),
352 mir_graph_->SRegToVReg(GetSRegHi(rl_dest.s_reg_low)));
buzbee2700f7e2014-03-07 09:46:20 -0800353 StoreBaseDispWide(TargetReg(kSp), SRegOffset(rl_dest.s_reg_low), rl_dest.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800354 MarkClean(rl_dest);
355 LIR *def_end = last_lir_insn_;
356 MarkDefWide(rl_dest, def_start, def_end);
357 }
358}
359
Brian Carlstrom7940e442013-07-12 13:46:57 -0700360/* Utilities to load the current Method* */
buzbee2700f7e2014-03-07 09:46:20 -0800361void Mir2Lir::LoadCurrMethodDirect(RegStorage r_tgt) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700362 LoadValueDirectFixed(mir_graph_->GetMethodLoc(), r_tgt);
363}
364
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700365RegLocation Mir2Lir::LoadCurrMethod() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700366 return LoadValue(mir_graph_->GetMethodLoc(), kCoreReg);
367}
368
Mark Mendelle02d48f2014-01-15 11:19:23 -0800369RegLocation Mir2Lir::ForceTemp(RegLocation loc) {
370 DCHECK(!loc.wide);
371 DCHECK(loc.location == kLocPhysReg);
buzbee2700f7e2014-03-07 09:46:20 -0800372 DCHECK(!IsFpReg(loc.reg));
373 if (IsTemp(loc.reg)) {
374 Clobber(loc.reg);
Mark Mendelle02d48f2014-01-15 11:19:23 -0800375 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800376 RegStorage temp_low = AllocTemp();
377 OpRegCopy(temp_low, loc.reg);
378 loc.reg = temp_low;
Mark Mendelle02d48f2014-01-15 11:19:23 -0800379 }
380
381 // Ensure that this doesn't represent the original SR any more.
382 loc.s_reg_low = INVALID_SREG;
383 return loc;
384}
385
buzbee2700f7e2014-03-07 09:46:20 -0800386// FIXME: wide regs.
Mark Mendelle02d48f2014-01-15 11:19:23 -0800387RegLocation Mir2Lir::ForceTempWide(RegLocation loc) {
388 DCHECK(loc.wide);
389 DCHECK(loc.location == kLocPhysReg);
buzbee2700f7e2014-03-07 09:46:20 -0800390 DCHECK(!IsFpReg(loc.reg.GetLowReg()));
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000391 DCHECK(!IsFpReg(loc.reg.GetHighReg()));
buzbee2700f7e2014-03-07 09:46:20 -0800392 if (IsTemp(loc.reg.GetLowReg())) {
393 Clobber(loc.reg.GetLowReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800394 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800395 RegStorage temp_low = AllocTemp();
396 OpRegCopy(temp_low, loc.reg.GetLow());
397 loc.reg.SetLowReg(temp_low.GetReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800398 }
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000399 if (IsTemp(loc.reg.GetHighReg())) {
400 Clobber(loc.reg.GetHighReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800401 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800402 RegStorage temp_high = AllocTemp();
403 OpRegCopy(temp_high, loc.reg.GetHigh());
404 loc.reg.SetHighReg(temp_high.GetReg());
Mark Mendelle02d48f2014-01-15 11:19:23 -0800405 }
406
407 // Ensure that this doesn't represent the original SR any more.
408 loc.s_reg_low = INVALID_SREG;
409 return loc;
410}
411
Brian Carlstrom7940e442013-07-12 13:46:57 -0700412} // namespace art