blob: 2b78e38f5aa43ad630b02b828b5483f3226d73f3 [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
Andreas Gampe0b9203e2015-01-22 20:39:27 -080017#include "base/logging.h"
18#include "base/stringprintf.h"
19#include "compiler_ir.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070020#include "dex/dataflow_iterator-inl.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080021#include "dex_flags.h"
Mathieu Chartiere5f13e52015-02-24 09:37:21 -080022#include "driver/dex_compilation_unit.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023
24namespace art {
25
26bool MIRGraph::SetFp(int index, bool is_fp) {
27 bool change = false;
28 if (is_fp && !reg_location_[index].fp) {
29 reg_location_[index].fp = true;
30 reg_location_[index].defined = true;
31 change = true;
32 }
33 return change;
34}
35
buzbee28c23002013-09-07 09:12:27 -070036bool MIRGraph::SetFp(int index) {
37 bool change = false;
38 if (!reg_location_[index].fp) {
39 reg_location_[index].fp = true;
40 reg_location_[index].defined = true;
41 change = true;
42 }
43 return change;
44}
45
Brian Carlstrom7940e442013-07-12 13:46:57 -070046bool MIRGraph::SetCore(int index, bool is_core) {
47 bool change = false;
48 if (is_core && !reg_location_[index].defined) {
49 reg_location_[index].core = true;
50 reg_location_[index].defined = true;
51 change = true;
52 }
53 return change;
54}
55
buzbee28c23002013-09-07 09:12:27 -070056bool MIRGraph::SetCore(int index) {
57 bool change = false;
58 if (!reg_location_[index].defined) {
59 reg_location_[index].core = true;
60 reg_location_[index].defined = true;
61 change = true;
62 }
63 return change;
64}
65
Brian Carlstrom7940e442013-07-12 13:46:57 -070066bool MIRGraph::SetRef(int index, bool is_ref) {
67 bool change = false;
68 if (is_ref && !reg_location_[index].defined) {
69 reg_location_[index].ref = true;
70 reg_location_[index].defined = true;
71 change = true;
72 }
73 return change;
74}
75
buzbee28c23002013-09-07 09:12:27 -070076bool MIRGraph::SetRef(int index) {
77 bool change = false;
78 if (!reg_location_[index].defined) {
79 reg_location_[index].ref = true;
80 reg_location_[index].defined = true;
81 change = true;
82 }
83 return change;
84}
85
Brian Carlstrom7940e442013-07-12 13:46:57 -070086bool MIRGraph::SetWide(int index, bool is_wide) {
87 bool change = false;
88 if (is_wide && !reg_location_[index].wide) {
89 reg_location_[index].wide = true;
90 change = true;
91 }
92 return change;
93}
94
buzbee28c23002013-09-07 09:12:27 -070095bool MIRGraph::SetWide(int index) {
96 bool change = false;
97 if (!reg_location_[index].wide) {
98 reg_location_[index].wide = true;
99 change = true;
100 }
101 return change;
102}
103
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104bool MIRGraph::SetHigh(int index, bool is_high) {
105 bool change = false;
106 if (is_high && !reg_location_[index].high_word) {
107 reg_location_[index].high_word = true;
108 change = true;
109 }
110 return change;
111}
112
buzbee28c23002013-09-07 09:12:27 -0700113bool MIRGraph::SetHigh(int index) {
114 bool change = false;
115 if (!reg_location_[index].high_word) {
116 reg_location_[index].high_word = true;
117 change = true;
118 }
119 return change;
120}
121
122
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123/*
124 * Infer types and sizes. We don't need to track change on sizes,
125 * as it doesn't propagate. We're guaranteed at least one pass through
126 * the cfg.
127 */
buzbee1da1e2f2013-11-15 13:37:01 -0800128bool MIRGraph::InferTypeAndSize(BasicBlock* bb, MIR* mir, bool changed) {
129 SSARepresentation *ssa_rep = mir->ssa_rep;
buzbee8c7a02a2014-06-14 12:33:09 -0700130
131 /*
132 * The dex bytecode definition does not explicitly outlaw the definition of the same
133 * virtual register to be used in both a 32-bit and 64-bit pair context. However, dx
134 * does not generate this pattern (at least recently). Further, in the next revision of
135 * dex, we will forbid this. To support the few cases in the wild, detect this pattern
136 * and punt to the interpreter.
137 */
138 bool type_mismatch = false;
139
buzbee1da1e2f2013-11-15 13:37:01 -0800140 if (ssa_rep) {
Jean Christophe Beylercc794c32014-05-02 09:34:13 -0700141 uint64_t attrs = GetDataFlowAttributes(mir);
buzbee1da1e2f2013-11-15 13:37:01 -0800142 const int* uses = ssa_rep->uses;
143 const int* defs = ssa_rep->defs;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700144
buzbee1da1e2f2013-11-15 13:37:01 -0800145 // Handle defs
146 if (attrs & DF_DA) {
147 if (attrs & DF_CORE_A) {
148 changed |= SetCore(defs[0]);
149 }
150 if (attrs & DF_REF_A) {
151 changed |= SetRef(defs[0]);
152 }
153 if (attrs & DF_A_WIDE) {
154 reg_location_[defs[0]].wide = true;
155 reg_location_[defs[1]].wide = true;
156 reg_location_[defs[1]].high_word = true;
157 DCHECK_EQ(SRegToVReg(defs[0])+1,
158 SRegToVReg(defs[1]));
159 }
160 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700161
buzbee8c7a02a2014-06-14 12:33:09 -0700162
buzbee1da1e2f2013-11-15 13:37:01 -0800163 // Handles uses
164 int next = 0;
165 if (attrs & DF_UA) {
166 if (attrs & DF_CORE_A) {
167 changed |= SetCore(uses[next]);
168 }
169 if (attrs & DF_REF_A) {
170 changed |= SetRef(uses[next]);
171 }
172 if (attrs & DF_A_WIDE) {
173 reg_location_[uses[next]].wide = true;
174 reg_location_[uses[next + 1]].wide = true;
175 reg_location_[uses[next + 1]].high_word = true;
176 DCHECK_EQ(SRegToVReg(uses[next])+1,
177 SRegToVReg(uses[next + 1]));
178 next += 2;
179 } else {
buzbee8c7a02a2014-06-14 12:33:09 -0700180 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800181 next++;
182 }
183 }
184 if (attrs & DF_UB) {
185 if (attrs & DF_CORE_B) {
186 changed |= SetCore(uses[next]);
187 }
188 if (attrs & DF_REF_B) {
189 changed |= SetRef(uses[next]);
190 }
191 if (attrs & DF_B_WIDE) {
192 reg_location_[uses[next]].wide = true;
193 reg_location_[uses[next + 1]].wide = true;
194 reg_location_[uses[next + 1]].high_word = true;
195 DCHECK_EQ(SRegToVReg(uses[next])+1,
196 SRegToVReg(uses[next + 1]));
197 next += 2;
198 } else {
buzbee8c7a02a2014-06-14 12:33:09 -0700199 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800200 next++;
201 }
202 }
203 if (attrs & DF_UC) {
204 if (attrs & DF_CORE_C) {
205 changed |= SetCore(uses[next]);
206 }
207 if (attrs & DF_REF_C) {
208 changed |= SetRef(uses[next]);
209 }
210 if (attrs & DF_C_WIDE) {
211 reg_location_[uses[next]].wide = true;
212 reg_location_[uses[next + 1]].wide = true;
213 reg_location_[uses[next + 1]].high_word = true;
214 DCHECK_EQ(SRegToVReg(uses[next])+1,
215 SRegToVReg(uses[next + 1]));
buzbee8c7a02a2014-06-14 12:33:09 -0700216 } else {
217 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800218 }
219 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700220
buzbee1da1e2f2013-11-15 13:37:01 -0800221 // Special-case return handling
222 if ((mir->dalvikInsn.opcode == Instruction::RETURN) ||
223 (mir->dalvikInsn.opcode == Instruction::RETURN_WIDE) ||
224 (mir->dalvikInsn.opcode == Instruction::RETURN_OBJECT)) {
225 switch (cu_->shorty[0]) {
226 case 'I':
buzbee8c7a02a2014-06-14 12:33:09 -0700227 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800228 changed |= SetCore(uses[0]);
229 break;
230 case 'J':
231 changed |= SetCore(uses[0]);
232 changed |= SetCore(uses[1]);
233 reg_location_[uses[0]].wide = true;
234 reg_location_[uses[1]].wide = true;
235 reg_location_[uses[1]].high_word = true;
236 break;
237 case 'F':
buzbee8c7a02a2014-06-14 12:33:09 -0700238 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800239 changed |= SetFp(uses[0]);
240 break;
241 case 'D':
242 changed |= SetFp(uses[0]);
243 changed |= SetFp(uses[1]);
244 reg_location_[uses[0]].wide = true;
245 reg_location_[uses[1]].wide = true;
246 reg_location_[uses[1]].high_word = true;
247 break;
248 case 'L':
buzbee8c7a02a2014-06-14 12:33:09 -0700249 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800250 changed |= SetRef(uses[0]);
251 break;
252 default: break;
253 }
254 }
255
256 // Special-case handling for format 35c/3rc invokes
257 Instruction::Code opcode = mir->dalvikInsn.opcode;
Jean Christophe Beyler2ab40eb2014-06-02 09:03:14 -0700258 int flags = MIR::DecodedInstruction::IsPseudoMirOp(opcode) ?
Jean Christophe Beylerfb0ea2d2014-07-29 13:20:42 -0700259 0 : mir->dalvikInsn.FlagsOf();
buzbee1da1e2f2013-11-15 13:37:01 -0800260 if ((flags & Instruction::kInvoke) &&
261 (attrs & (DF_FORMAT_35C | DF_FORMAT_3RC))) {
262 DCHECK_EQ(next, 0);
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800263 const auto& lowering_info = GetMethodLoweringInfo(mir);
264 const char* shorty = GetShortyFromMethodReference(lowering_info.GetTargetMethod());
buzbee1da1e2f2013-11-15 13:37:01 -0800265 // Handle result type if floating point
266 if ((shorty[0] == 'F') || (shorty[0] == 'D')) {
267 MIR* move_result_mir = FindMoveResult(bb, mir);
268 // Result might not be used at all, so no move-result
269 if (move_result_mir && (move_result_mir->dalvikInsn.opcode !=
270 Instruction::MOVE_RESULT_OBJECT)) {
271 SSARepresentation* tgt_rep = move_result_mir->ssa_rep;
272 DCHECK(tgt_rep != NULL);
273 tgt_rep->fp_def[0] = true;
274 changed |= SetFp(tgt_rep->defs[0]);
275 if (shorty[0] == 'D') {
276 tgt_rep->fp_def[1] = true;
277 changed |= SetFp(tgt_rep->defs[1]);
278 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700279 }
280 }
buzbee1da1e2f2013-11-15 13:37:01 -0800281 int num_uses = mir->dalvikInsn.vA;
282 // If this is a non-static invoke, mark implicit "this"
Vladimir Marko321b9872014-11-24 16:33:51 +0000283 if (!IsInstructionInvokeStatic(mir->dalvikInsn.opcode)) {
buzbee1da1e2f2013-11-15 13:37:01 -0800284 reg_location_[uses[next]].defined = true;
285 reg_location_[uses[next]].ref = true;
buzbee8c7a02a2014-06-14 12:33:09 -0700286 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800287 next++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700288 }
buzbee1da1e2f2013-11-15 13:37:01 -0800289 uint32_t cpos = 1;
290 if (strlen(shorty) > 1) {
291 for (int i = next; i < num_uses;) {
292 DCHECK_LT(cpos, strlen(shorty));
293 switch (shorty[cpos++]) {
294 case 'D':
295 ssa_rep->fp_use[i] = true;
296 ssa_rep->fp_use[i+1] = true;
297 reg_location_[uses[i]].wide = true;
298 reg_location_[uses[i+1]].wide = true;
299 reg_location_[uses[i+1]].high_word = true;
300 DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1]));
301 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700302 break;
303 case 'J':
buzbee1da1e2f2013-11-15 13:37:01 -0800304 reg_location_[uses[i]].wide = true;
305 reg_location_[uses[i+1]].wide = true;
306 reg_location_[uses[i+1]].high_word = true;
307 DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1]));
308 changed |= SetCore(uses[i]);
309 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700310 break;
311 case 'F':
buzbee8c7a02a2014-06-14 12:33:09 -0700312 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800313 ssa_rep->fp_use[i] = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 break;
315 case 'L':
buzbee8c7a02a2014-06-14 12:33:09 -0700316 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800317 changed |= SetRef(uses[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700318 break;
buzbee1da1e2f2013-11-15 13:37:01 -0800319 default:
buzbee8c7a02a2014-06-14 12:33:09 -0700320 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800321 changed |= SetCore(uses[i]);
322 break;
323 }
324 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700325 }
326 }
buzbee1da1e2f2013-11-15 13:37:01 -0800327 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700328
buzbee1da1e2f2013-11-15 13:37:01 -0800329 for (int i = 0; ssa_rep->fp_use && i< ssa_rep->num_uses; i++) {
Vladimir Marko55fff042014-07-10 12:42:52 +0100330 if (ssa_rep->fp_use[i]) {
buzbee1da1e2f2013-11-15 13:37:01 -0800331 changed |= SetFp(uses[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700332 }
Vladimir Marko55fff042014-07-10 12:42:52 +0100333 }
buzbee1da1e2f2013-11-15 13:37:01 -0800334 for (int i = 0; ssa_rep->fp_def && i< ssa_rep->num_defs; i++) {
Vladimir Marko55fff042014-07-10 12:42:52 +0100335 if (ssa_rep->fp_def[i]) {
buzbee1da1e2f2013-11-15 13:37:01 -0800336 changed |= SetFp(defs[i]);
337 }
Vladimir Marko55fff042014-07-10 12:42:52 +0100338 }
buzbee1da1e2f2013-11-15 13:37:01 -0800339 // Special-case handling for moves & Phi
340 if (attrs & (DF_IS_MOVE | DF_NULL_TRANSFER_N)) {
341 /*
342 * If any of our inputs or outputs is defined, set all.
343 * Some ugliness related to Phi nodes and wide values.
344 * The Phi set will include all low words or all high
345 * words, so we have to treat them specially.
346 */
buzbee35ba7f32014-05-31 08:59:01 -0700347 bool is_phi = (static_cast<int>(mir->dalvikInsn.opcode) == kMirOpPhi);
buzbee1da1e2f2013-11-15 13:37:01 -0800348 RegLocation rl_temp = reg_location_[defs[0]];
349 bool defined_fp = rl_temp.defined && rl_temp.fp;
350 bool defined_core = rl_temp.defined && rl_temp.core;
351 bool defined_ref = rl_temp.defined && rl_temp.ref;
352 bool is_wide = rl_temp.wide || ((attrs & DF_A_WIDE) != 0);
353 bool is_high = is_phi && rl_temp.wide && rl_temp.high_word;
354 for (int i = 0; i < ssa_rep->num_uses; i++) {
355 rl_temp = reg_location_[uses[i]];
356 defined_fp |= rl_temp.defined && rl_temp.fp;
357 defined_core |= rl_temp.defined && rl_temp.core;
358 defined_ref |= rl_temp.defined && rl_temp.ref;
359 is_wide |= rl_temp.wide;
360 is_high |= is_phi && rl_temp.wide && rl_temp.high_word;
361 }
362 /*
363 * We don't normally expect to see a Dalvik register definition used both as a
364 * floating point and core value, though technically it could happen with constants.
365 * Until we have proper typing, detect this situation and disable register promotion
366 * (which relies on the distinction between core a fp usages).
367 */
368 if ((defined_fp && (defined_core | defined_ref)) &&
369 ((cu_->disable_opt & (1 << kPromoteRegs)) == 0)) {
370 LOG(WARNING) << PrettyMethod(cu_->method_idx, *cu_->dex_file)
371 << " op at block " << bb->id
372 << " has both fp and core/ref uses for same def.";
373 cu_->disable_opt |= (1 << kPromoteRegs);
374 }
375 changed |= SetFp(defs[0], defined_fp);
376 changed |= SetCore(defs[0], defined_core);
377 changed |= SetRef(defs[0], defined_ref);
378 changed |= SetWide(defs[0], is_wide);
379 changed |= SetHigh(defs[0], is_high);
380 if (attrs & DF_A_WIDE) {
381 changed |= SetWide(defs[1]);
382 changed |= SetHigh(defs[1]);
383 }
Stephen Kyle8fe0e352014-10-16 15:02:42 +0100384
385 bool has_ins = (GetNumOfInVRs() > 0);
386
buzbee1da1e2f2013-11-15 13:37:01 -0800387 for (int i = 0; i < ssa_rep->num_uses; i++) {
Stephen Kyle8fe0e352014-10-16 15:02:42 +0100388 if (has_ins && IsInVReg(uses[i])) {
389 // NB: The SSA name for the first def of an in-reg will be the same as
390 // the reg's actual name.
391 if (!reg_location_[uses[i]].fp && defined_fp) {
392 // If we were about to infer that this first def of an in-reg is a float
393 // when it wasn't previously (because float/int is set during SSA initialization),
394 // do not allow this to happen.
395 continue;
396 }
397 }
buzbee1da1e2f2013-11-15 13:37:01 -0800398 changed |= SetFp(uses[i], defined_fp);
399 changed |= SetCore(uses[i], defined_core);
400 changed |= SetRef(uses[i], defined_ref);
401 changed |= SetWide(uses[i], is_wide);
402 changed |= SetHigh(uses[i], is_high);
403 }
404 if (attrs & DF_A_WIDE) {
405 DCHECK_EQ(ssa_rep->num_uses, 2);
406 changed |= SetWide(uses[1]);
407 changed |= SetHigh(uses[1]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700408 }
409 }
410 }
buzbee8c7a02a2014-06-14 12:33:09 -0700411 if (type_mismatch) {
412 LOG(WARNING) << "Deprecated dex type mismatch, interpreting "
413 << PrettyMethod(cu_->method_idx, *cu_->dex_file);
414 LOG(INFO) << "@ 0x" << std::hex << mir->offset;
415 SetPuntToInterpreter(true);
416 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700417 return changed;
418}
419
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700420static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700421
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700422void MIRGraph::DumpRegLocTable(RegLocation* table, int count) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700423 for (int i = 0; i < count; i++) {
424 LOG(INFO) << StringPrintf("Loc[%02d] : %s, %c %c %c %c %c %c 0x%04x S%d",
425 table[i].orig_sreg, storage_name[table[i].location],
426 table[i].wide ? 'W' : 'N', table[i].defined ? 'D' : 'U',
427 table[i].fp ? 'F' : table[i].ref ? 'R' :'C',
428 table[i].is_const ? 'c' : 'n',
429 table[i].high_word ? 'H' : 'L', table[i].home ? 'h' : 't',
430 table[i].reg.GetRawBits(),
431 table[i].s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700432 }
433}
434
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000435// FIXME - will likely need to revisit all uses of this.
buzbee091cc402014-03-31 10:14:40 -0700436static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000437 RegStorage(), INVALID_SREG, INVALID_SREG};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700438
buzbee1da1e2f2013-11-15 13:37:01 -0800439void MIRGraph::InitRegLocations() {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700440 // Allocate the location map. We also include the maximum possible temps because
441 // the temp allocation initializes reg location as well (in order to deal with
442 // case when it will be called after this pass).
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800443 int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps();
Vladimir Markoe4fcc5b2015-02-13 10:28:29 +0000444 RegLocation* loc = arena_->AllocArray<RegLocation>(max_regs, kArenaAllocRegAlloc);
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700445 for (int i = 0; i < GetNumSSARegs(); i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700446 loc[i] = fresh_loc;
447 loc[i].s_reg_low = i;
Vladimir Marko066f9e42015-01-16 16:04:43 +0000448 loc[i].is_const = false; // Constants will be marked by constant propagation pass later.
Jean Christophe Beyler1ceea7e2014-04-15 16:18:48 -0700449 loc[i].wide = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700450 }
451
buzbeef2c3e562014-05-29 12:37:25 -0700452 /* Treat Method* as a normal reference */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700453 int method_sreg = GetMethodSReg();
454 loc[method_sreg].ref = true;
455 loc[method_sreg].location = kLocCompilerTemp;
456 loc[method_sreg].defined = true;
buzbeef2c3e562014-05-29 12:37:25 -0700457
Brian Carlstrom7940e442013-07-12 13:46:57 -0700458 reg_location_ = loc;
459
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700460 int num_regs = GetNumOfCodeVRs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700461
462 /* Add types of incoming arguments based on signature */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700463 int num_ins = GetNumOfInVRs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700464 if (num_ins > 0) {
465 int s_reg = num_regs - num_ins;
466 if ((cu_->access_flags & kAccStatic) == 0) {
467 // For non-static, skip past "this"
468 reg_location_[s_reg].defined = true;
469 reg_location_[s_reg].ref = true;
470 s_reg++;
471 }
472 const char* shorty = cu_->shorty;
473 int shorty_len = strlen(shorty);
474 for (int i = 1; i < shorty_len; i++) {
475 switch (shorty[i]) {
476 case 'D':
477 reg_location_[s_reg].wide = true;
478 reg_location_[s_reg+1].high_word = true;
479 reg_location_[s_reg+1].fp = true;
480 DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1));
481 reg_location_[s_reg].fp = true;
482 reg_location_[s_reg].defined = true;
483 s_reg++;
484 break;
485 case 'J':
486 reg_location_[s_reg].wide = true;
487 reg_location_[s_reg+1].high_word = true;
488 DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1));
489 reg_location_[s_reg].core = true;
490 reg_location_[s_reg].defined = true;
491 s_reg++;
492 break;
493 case 'F':
494 reg_location_[s_reg].fp = true;
495 reg_location_[s_reg].defined = true;
496 break;
497 case 'L':
498 reg_location_[s_reg].ref = true;
499 reg_location_[s_reg].defined = true;
500 break;
501 default:
502 reg_location_[s_reg].core = true;
503 reg_location_[s_reg].defined = true;
504 break;
505 }
506 s_reg++;
507 }
508 }
buzbee1da1e2f2013-11-15 13:37:01 -0800509}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700510
buzbee1da1e2f2013-11-15 13:37:01 -0800511/*
512 * Set the s_reg_low field to refer to the pre-SSA name of the
513 * base Dalvik virtual register. Once we add a better register
514 * allocator, remove this remapping.
515 */
516void MIRGraph::RemapRegLocations() {
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700517 for (int i = 0; i < GetNumSSARegs(); i++) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700518 int orig_sreg = reg_location_[i].s_reg_low;
519 reg_location_[i].orig_sreg = orig_sreg;
520 reg_location_[i].s_reg_low = SRegToVReg(orig_sreg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700521 }
522}
523
524} // namespace art