blob: a541c7d7a7da52c7f64da7eaac8a20be7df9ae0e [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 "compiler_internals.h"
18#include "dex/dataflow_iterator-inl.h"
19
20namespace art {
21
22bool MIRGraph::SetFp(int index, bool is_fp) {
23 bool change = false;
24 if (is_fp && !reg_location_[index].fp) {
25 reg_location_[index].fp = true;
26 reg_location_[index].defined = true;
27 change = true;
28 }
29 return change;
30}
31
buzbee28c23002013-09-07 09:12:27 -070032bool MIRGraph::SetFp(int index) {
33 bool change = false;
34 if (!reg_location_[index].fp) {
35 reg_location_[index].fp = true;
36 reg_location_[index].defined = true;
37 change = true;
38 }
39 return change;
40}
41
Brian Carlstrom7940e442013-07-12 13:46:57 -070042bool MIRGraph::SetCore(int index, bool is_core) {
43 bool change = false;
44 if (is_core && !reg_location_[index].defined) {
45 reg_location_[index].core = true;
46 reg_location_[index].defined = true;
47 change = true;
48 }
49 return change;
50}
51
buzbee28c23002013-09-07 09:12:27 -070052bool MIRGraph::SetCore(int index) {
53 bool change = false;
54 if (!reg_location_[index].defined) {
55 reg_location_[index].core = true;
56 reg_location_[index].defined = true;
57 change = true;
58 }
59 return change;
60}
61
Brian Carlstrom7940e442013-07-12 13:46:57 -070062bool MIRGraph::SetRef(int index, bool is_ref) {
63 bool change = false;
64 if (is_ref && !reg_location_[index].defined) {
65 reg_location_[index].ref = true;
66 reg_location_[index].defined = true;
67 change = true;
68 }
69 return change;
70}
71
buzbee28c23002013-09-07 09:12:27 -070072bool MIRGraph::SetRef(int index) {
73 bool change = false;
74 if (!reg_location_[index].defined) {
75 reg_location_[index].ref = true;
76 reg_location_[index].defined = true;
77 change = true;
78 }
79 return change;
80}
81
Brian Carlstrom7940e442013-07-12 13:46:57 -070082bool MIRGraph::SetWide(int index, bool is_wide) {
83 bool change = false;
84 if (is_wide && !reg_location_[index].wide) {
85 reg_location_[index].wide = true;
86 change = true;
87 }
88 return change;
89}
90
buzbee28c23002013-09-07 09:12:27 -070091bool MIRGraph::SetWide(int index) {
92 bool change = false;
93 if (!reg_location_[index].wide) {
94 reg_location_[index].wide = true;
95 change = true;
96 }
97 return change;
98}
99
Brian Carlstrom7940e442013-07-12 13:46:57 -0700100bool MIRGraph::SetHigh(int index, bool is_high) {
101 bool change = false;
102 if (is_high && !reg_location_[index].high_word) {
103 reg_location_[index].high_word = true;
104 change = true;
105 }
106 return change;
107}
108
buzbee28c23002013-09-07 09:12:27 -0700109bool MIRGraph::SetHigh(int index) {
110 bool change = false;
111 if (!reg_location_[index].high_word) {
112 reg_location_[index].high_word = true;
113 change = true;
114 }
115 return change;
116}
117
118
Brian Carlstrom7940e442013-07-12 13:46:57 -0700119/*
120 * Infer types and sizes. We don't need to track change on sizes,
121 * as it doesn't propagate. We're guaranteed at least one pass through
122 * the cfg.
123 */
buzbee1da1e2f2013-11-15 13:37:01 -0800124bool MIRGraph::InferTypeAndSize(BasicBlock* bb, MIR* mir, bool changed) {
125 SSARepresentation *ssa_rep = mir->ssa_rep;
buzbee8c7a02a2014-06-14 12:33:09 -0700126
127 /*
128 * The dex bytecode definition does not explicitly outlaw the definition of the same
129 * virtual register to be used in both a 32-bit and 64-bit pair context. However, dx
130 * does not generate this pattern (at least recently). Further, in the next revision of
131 * dex, we will forbid this. To support the few cases in the wild, detect this pattern
132 * and punt to the interpreter.
133 */
134 bool type_mismatch = false;
135
buzbee1da1e2f2013-11-15 13:37:01 -0800136 if (ssa_rep) {
Jean Christophe Beylercc794c32014-05-02 09:34:13 -0700137 uint64_t attrs = GetDataFlowAttributes(mir);
buzbee1da1e2f2013-11-15 13:37:01 -0800138 const int* uses = ssa_rep->uses;
139 const int* defs = ssa_rep->defs;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140
buzbee1da1e2f2013-11-15 13:37:01 -0800141 // Handle defs
142 if (attrs & DF_DA) {
143 if (attrs & DF_CORE_A) {
144 changed |= SetCore(defs[0]);
145 }
146 if (attrs & DF_REF_A) {
147 changed |= SetRef(defs[0]);
148 }
149 if (attrs & DF_A_WIDE) {
150 reg_location_[defs[0]].wide = true;
151 reg_location_[defs[1]].wide = true;
152 reg_location_[defs[1]].high_word = true;
153 DCHECK_EQ(SRegToVReg(defs[0])+1,
154 SRegToVReg(defs[1]));
155 }
156 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700157
buzbee8c7a02a2014-06-14 12:33:09 -0700158
buzbee1da1e2f2013-11-15 13:37:01 -0800159 // Handles uses
160 int next = 0;
161 if (attrs & DF_UA) {
162 if (attrs & DF_CORE_A) {
163 changed |= SetCore(uses[next]);
164 }
165 if (attrs & DF_REF_A) {
166 changed |= SetRef(uses[next]);
167 }
168 if (attrs & DF_A_WIDE) {
169 reg_location_[uses[next]].wide = true;
170 reg_location_[uses[next + 1]].wide = true;
171 reg_location_[uses[next + 1]].high_word = true;
172 DCHECK_EQ(SRegToVReg(uses[next])+1,
173 SRegToVReg(uses[next + 1]));
174 next += 2;
175 } else {
buzbee8c7a02a2014-06-14 12:33:09 -0700176 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800177 next++;
178 }
179 }
180 if (attrs & DF_UB) {
181 if (attrs & DF_CORE_B) {
182 changed |= SetCore(uses[next]);
183 }
184 if (attrs & DF_REF_B) {
185 changed |= SetRef(uses[next]);
186 }
187 if (attrs & DF_B_WIDE) {
188 reg_location_[uses[next]].wide = true;
189 reg_location_[uses[next + 1]].wide = true;
190 reg_location_[uses[next + 1]].high_word = true;
191 DCHECK_EQ(SRegToVReg(uses[next])+1,
192 SRegToVReg(uses[next + 1]));
193 next += 2;
194 } else {
buzbee8c7a02a2014-06-14 12:33:09 -0700195 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800196 next++;
197 }
198 }
199 if (attrs & DF_UC) {
200 if (attrs & DF_CORE_C) {
201 changed |= SetCore(uses[next]);
202 }
203 if (attrs & DF_REF_C) {
204 changed |= SetRef(uses[next]);
205 }
206 if (attrs & DF_C_WIDE) {
207 reg_location_[uses[next]].wide = true;
208 reg_location_[uses[next + 1]].wide = true;
209 reg_location_[uses[next + 1]].high_word = true;
210 DCHECK_EQ(SRegToVReg(uses[next])+1,
211 SRegToVReg(uses[next + 1]));
buzbee8c7a02a2014-06-14 12:33:09 -0700212 } else {
213 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800214 }
215 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700216
buzbee1da1e2f2013-11-15 13:37:01 -0800217 // Special-case return handling
218 if ((mir->dalvikInsn.opcode == Instruction::RETURN) ||
219 (mir->dalvikInsn.opcode == Instruction::RETURN_WIDE) ||
220 (mir->dalvikInsn.opcode == Instruction::RETURN_OBJECT)) {
221 switch (cu_->shorty[0]) {
222 case 'I':
buzbee8c7a02a2014-06-14 12:33:09 -0700223 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800224 changed |= SetCore(uses[0]);
225 break;
226 case 'J':
227 changed |= SetCore(uses[0]);
228 changed |= SetCore(uses[1]);
229 reg_location_[uses[0]].wide = true;
230 reg_location_[uses[1]].wide = true;
231 reg_location_[uses[1]].high_word = true;
232 break;
233 case 'F':
buzbee8c7a02a2014-06-14 12:33:09 -0700234 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800235 changed |= SetFp(uses[0]);
236 break;
237 case 'D':
238 changed |= SetFp(uses[0]);
239 changed |= SetFp(uses[1]);
240 reg_location_[uses[0]].wide = true;
241 reg_location_[uses[1]].wide = true;
242 reg_location_[uses[1]].high_word = true;
243 break;
244 case 'L':
buzbee8c7a02a2014-06-14 12:33:09 -0700245 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800246 changed |= SetRef(uses[0]);
247 break;
248 default: break;
249 }
250 }
251
252 // Special-case handling for format 35c/3rc invokes
253 Instruction::Code opcode = mir->dalvikInsn.opcode;
Jean Christophe Beyler2ab40eb2014-06-02 09:03:14 -0700254 int flags = MIR::DecodedInstruction::IsPseudoMirOp(opcode) ?
Jean Christophe Beylerfb0ea2d2014-07-29 13:20:42 -0700255 0 : mir->dalvikInsn.FlagsOf();
buzbee1da1e2f2013-11-15 13:37:01 -0800256 if ((flags & Instruction::kInvoke) &&
257 (attrs & (DF_FORMAT_35C | DF_FORMAT_3RC))) {
258 DCHECK_EQ(next, 0);
259 int target_idx = mir->dalvikInsn.vB;
260 const char* shorty = GetShortyFromTargetIdx(target_idx);
261 // Handle result type if floating point
262 if ((shorty[0] == 'F') || (shorty[0] == 'D')) {
263 MIR* move_result_mir = FindMoveResult(bb, mir);
264 // Result might not be used at all, so no move-result
265 if (move_result_mir && (move_result_mir->dalvikInsn.opcode !=
266 Instruction::MOVE_RESULT_OBJECT)) {
267 SSARepresentation* tgt_rep = move_result_mir->ssa_rep;
268 DCHECK(tgt_rep != NULL);
269 tgt_rep->fp_def[0] = true;
270 changed |= SetFp(tgt_rep->defs[0]);
271 if (shorty[0] == 'D') {
272 tgt_rep->fp_def[1] = true;
273 changed |= SetFp(tgt_rep->defs[1]);
274 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700275 }
276 }
buzbee1da1e2f2013-11-15 13:37:01 -0800277 int num_uses = mir->dalvikInsn.vA;
278 // If this is a non-static invoke, mark implicit "this"
Vladimir Marko321b9872014-11-24 16:33:51 +0000279 if (!IsInstructionInvokeStatic(mir->dalvikInsn.opcode)) {
buzbee1da1e2f2013-11-15 13:37:01 -0800280 reg_location_[uses[next]].defined = true;
281 reg_location_[uses[next]].ref = true;
buzbee8c7a02a2014-06-14 12:33:09 -0700282 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800283 next++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700284 }
buzbee1da1e2f2013-11-15 13:37:01 -0800285 uint32_t cpos = 1;
286 if (strlen(shorty) > 1) {
287 for (int i = next; i < num_uses;) {
288 DCHECK_LT(cpos, strlen(shorty));
289 switch (shorty[cpos++]) {
290 case 'D':
291 ssa_rep->fp_use[i] = true;
292 ssa_rep->fp_use[i+1] = true;
293 reg_location_[uses[i]].wide = true;
294 reg_location_[uses[i+1]].wide = true;
295 reg_location_[uses[i+1]].high_word = true;
296 DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1]));
297 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700298 break;
299 case 'J':
buzbee1da1e2f2013-11-15 13:37:01 -0800300 reg_location_[uses[i]].wide = true;
301 reg_location_[uses[i+1]].wide = true;
302 reg_location_[uses[i+1]].high_word = true;
303 DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1]));
304 changed |= SetCore(uses[i]);
305 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700306 break;
307 case 'F':
buzbee8c7a02a2014-06-14 12:33:09 -0700308 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800309 ssa_rep->fp_use[i] = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700310 break;
311 case 'L':
buzbee8c7a02a2014-06-14 12:33:09 -0700312 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800313 changed |= SetRef(uses[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 break;
buzbee1da1e2f2013-11-15 13:37:01 -0800315 default:
buzbee8c7a02a2014-06-14 12:33:09 -0700316 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800317 changed |= SetCore(uses[i]);
318 break;
319 }
320 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700321 }
322 }
buzbee1da1e2f2013-11-15 13:37:01 -0800323 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700324
buzbee1da1e2f2013-11-15 13:37:01 -0800325 for (int i = 0; ssa_rep->fp_use && i< ssa_rep->num_uses; i++) {
Vladimir Marko55fff042014-07-10 12:42:52 +0100326 if (ssa_rep->fp_use[i]) {
buzbee1da1e2f2013-11-15 13:37:01 -0800327 changed |= SetFp(uses[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700328 }
Vladimir Marko55fff042014-07-10 12:42:52 +0100329 }
buzbee1da1e2f2013-11-15 13:37:01 -0800330 for (int i = 0; ssa_rep->fp_def && i< ssa_rep->num_defs; i++) {
Vladimir Marko55fff042014-07-10 12:42:52 +0100331 if (ssa_rep->fp_def[i]) {
buzbee1da1e2f2013-11-15 13:37:01 -0800332 changed |= SetFp(defs[i]);
333 }
Vladimir Marko55fff042014-07-10 12:42:52 +0100334 }
buzbee1da1e2f2013-11-15 13:37:01 -0800335 // Special-case handling for moves & Phi
336 if (attrs & (DF_IS_MOVE | DF_NULL_TRANSFER_N)) {
337 /*
338 * If any of our inputs or outputs is defined, set all.
339 * Some ugliness related to Phi nodes and wide values.
340 * The Phi set will include all low words or all high
341 * words, so we have to treat them specially.
342 */
buzbee35ba7f32014-05-31 08:59:01 -0700343 bool is_phi = (static_cast<int>(mir->dalvikInsn.opcode) == kMirOpPhi);
buzbee1da1e2f2013-11-15 13:37:01 -0800344 RegLocation rl_temp = reg_location_[defs[0]];
345 bool defined_fp = rl_temp.defined && rl_temp.fp;
346 bool defined_core = rl_temp.defined && rl_temp.core;
347 bool defined_ref = rl_temp.defined && rl_temp.ref;
348 bool is_wide = rl_temp.wide || ((attrs & DF_A_WIDE) != 0);
349 bool is_high = is_phi && rl_temp.wide && rl_temp.high_word;
350 for (int i = 0; i < ssa_rep->num_uses; i++) {
351 rl_temp = reg_location_[uses[i]];
352 defined_fp |= rl_temp.defined && rl_temp.fp;
353 defined_core |= rl_temp.defined && rl_temp.core;
354 defined_ref |= rl_temp.defined && rl_temp.ref;
355 is_wide |= rl_temp.wide;
356 is_high |= is_phi && rl_temp.wide && rl_temp.high_word;
357 }
358 /*
359 * We don't normally expect to see a Dalvik register definition used both as a
360 * floating point and core value, though technically it could happen with constants.
361 * Until we have proper typing, detect this situation and disable register promotion
362 * (which relies on the distinction between core a fp usages).
363 */
364 if ((defined_fp && (defined_core | defined_ref)) &&
365 ((cu_->disable_opt & (1 << kPromoteRegs)) == 0)) {
366 LOG(WARNING) << PrettyMethod(cu_->method_idx, *cu_->dex_file)
367 << " op at block " << bb->id
368 << " has both fp and core/ref uses for same def.";
369 cu_->disable_opt |= (1 << kPromoteRegs);
370 }
371 changed |= SetFp(defs[0], defined_fp);
372 changed |= SetCore(defs[0], defined_core);
373 changed |= SetRef(defs[0], defined_ref);
374 changed |= SetWide(defs[0], is_wide);
375 changed |= SetHigh(defs[0], is_high);
376 if (attrs & DF_A_WIDE) {
377 changed |= SetWide(defs[1]);
378 changed |= SetHigh(defs[1]);
379 }
Stephen Kyle8fe0e352014-10-16 15:02:42 +0100380
381 bool has_ins = (GetNumOfInVRs() > 0);
382
buzbee1da1e2f2013-11-15 13:37:01 -0800383 for (int i = 0; i < ssa_rep->num_uses; i++) {
Stephen Kyle8fe0e352014-10-16 15:02:42 +0100384 if (has_ins && IsInVReg(uses[i])) {
385 // NB: The SSA name for the first def of an in-reg will be the same as
386 // the reg's actual name.
387 if (!reg_location_[uses[i]].fp && defined_fp) {
388 // If we were about to infer that this first def of an in-reg is a float
389 // when it wasn't previously (because float/int is set during SSA initialization),
390 // do not allow this to happen.
391 continue;
392 }
393 }
buzbee1da1e2f2013-11-15 13:37:01 -0800394 changed |= SetFp(uses[i], defined_fp);
395 changed |= SetCore(uses[i], defined_core);
396 changed |= SetRef(uses[i], defined_ref);
397 changed |= SetWide(uses[i], is_wide);
398 changed |= SetHigh(uses[i], is_high);
399 }
400 if (attrs & DF_A_WIDE) {
401 DCHECK_EQ(ssa_rep->num_uses, 2);
402 changed |= SetWide(uses[1]);
403 changed |= SetHigh(uses[1]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700404 }
405 }
406 }
buzbee8c7a02a2014-06-14 12:33:09 -0700407 if (type_mismatch) {
408 LOG(WARNING) << "Deprecated dex type mismatch, interpreting "
409 << PrettyMethod(cu_->method_idx, *cu_->dex_file);
410 LOG(INFO) << "@ 0x" << std::hex << mir->offset;
411 SetPuntToInterpreter(true);
412 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700413 return changed;
414}
415
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700416static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700417
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700418void MIRGraph::DumpRegLocTable(RegLocation* table, int count) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700419 for (int i = 0; i < count; i++) {
420 LOG(INFO) << StringPrintf("Loc[%02d] : %s, %c %c %c %c %c %c 0x%04x S%d",
421 table[i].orig_sreg, storage_name[table[i].location],
422 table[i].wide ? 'W' : 'N', table[i].defined ? 'D' : 'U',
423 table[i].fp ? 'F' : table[i].ref ? 'R' :'C',
424 table[i].is_const ? 'c' : 'n',
425 table[i].high_word ? 'H' : 'L', table[i].home ? 'h' : 't',
426 table[i].reg.GetRawBits(),
427 table[i].s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700428 }
429}
430
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000431// FIXME - will likely need to revisit all uses of this.
buzbee091cc402014-03-31 10:14:40 -0700432static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000433 RegStorage(), INVALID_SREG, INVALID_SREG};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700434
buzbee1da1e2f2013-11-15 13:37:01 -0800435void MIRGraph::InitRegLocations() {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700436 // Allocate the location map. We also include the maximum possible temps because
437 // the temp allocation initializes reg location as well (in order to deal with
438 // case when it will be called after this pass).
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800439 int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps();
440 RegLocation* loc = static_cast<RegLocation*>(arena_->Alloc(max_regs * sizeof(*loc),
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000441 kArenaAllocRegAlloc));
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700442 for (int i = 0; i < GetNumSSARegs(); i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700443 loc[i] = fresh_loc;
444 loc[i].s_reg_low = i;
445 loc[i].is_const = is_constant_v_->IsBitSet(i);
Jean Christophe Beyler1ceea7e2014-04-15 16:18:48 -0700446 loc[i].wide = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700447 }
448
buzbeef2c3e562014-05-29 12:37:25 -0700449 /* Treat Method* as a normal reference */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700450 int method_sreg = GetMethodSReg();
451 loc[method_sreg].ref = true;
452 loc[method_sreg].location = kLocCompilerTemp;
453 loc[method_sreg].defined = true;
buzbeef2c3e562014-05-29 12:37:25 -0700454
Brian Carlstrom7940e442013-07-12 13:46:57 -0700455 reg_location_ = loc;
456
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700457 int num_regs = GetNumOfCodeVRs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700458
459 /* Add types of incoming arguments based on signature */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700460 int num_ins = GetNumOfInVRs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700461 if (num_ins > 0) {
462 int s_reg = num_regs - num_ins;
463 if ((cu_->access_flags & kAccStatic) == 0) {
464 // For non-static, skip past "this"
465 reg_location_[s_reg].defined = true;
466 reg_location_[s_reg].ref = true;
467 s_reg++;
468 }
469 const char* shorty = cu_->shorty;
470 int shorty_len = strlen(shorty);
471 for (int i = 1; i < shorty_len; i++) {
472 switch (shorty[i]) {
473 case 'D':
474 reg_location_[s_reg].wide = true;
475 reg_location_[s_reg+1].high_word = true;
476 reg_location_[s_reg+1].fp = true;
477 DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1));
478 reg_location_[s_reg].fp = true;
479 reg_location_[s_reg].defined = true;
480 s_reg++;
481 break;
482 case 'J':
483 reg_location_[s_reg].wide = true;
484 reg_location_[s_reg+1].high_word = true;
485 DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1));
486 reg_location_[s_reg].core = true;
487 reg_location_[s_reg].defined = true;
488 s_reg++;
489 break;
490 case 'F':
491 reg_location_[s_reg].fp = true;
492 reg_location_[s_reg].defined = true;
493 break;
494 case 'L':
495 reg_location_[s_reg].ref = true;
496 reg_location_[s_reg].defined = true;
497 break;
498 default:
499 reg_location_[s_reg].core = true;
500 reg_location_[s_reg].defined = true;
501 break;
502 }
503 s_reg++;
504 }
505 }
buzbee1da1e2f2013-11-15 13:37:01 -0800506}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700507
buzbee1da1e2f2013-11-15 13:37:01 -0800508/*
509 * Set the s_reg_low field to refer to the pre-SSA name of the
510 * base Dalvik virtual register. Once we add a better register
511 * allocator, remove this remapping.
512 */
513void MIRGraph::RemapRegLocations() {
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700514 for (int i = 0; i < GetNumSSARegs(); i++) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700515 int orig_sreg = reg_location_[i].s_reg_low;
516 reg_location_[i].orig_sreg = orig_sreg;
517 reg_location_[i].s_reg_low = SRegToVReg(orig_sreg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700518 }
519}
520
521} // namespace art