blob: b620969ae2fbb3cbf8db1fe8cc363cefeb895372 [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"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022
23namespace art {
24
25bool MIRGraph::SetFp(int index, bool is_fp) {
26 bool change = false;
27 if (is_fp && !reg_location_[index].fp) {
28 reg_location_[index].fp = true;
29 reg_location_[index].defined = true;
30 change = true;
31 }
32 return change;
33}
34
buzbee28c23002013-09-07 09:12:27 -070035bool MIRGraph::SetFp(int index) {
36 bool change = false;
37 if (!reg_location_[index].fp) {
38 reg_location_[index].fp = true;
39 reg_location_[index].defined = true;
40 change = true;
41 }
42 return change;
43}
44
Brian Carlstrom7940e442013-07-12 13:46:57 -070045bool MIRGraph::SetCore(int index, bool is_core) {
46 bool change = false;
47 if (is_core && !reg_location_[index].defined) {
48 reg_location_[index].core = true;
49 reg_location_[index].defined = true;
50 change = true;
51 }
52 return change;
53}
54
buzbee28c23002013-09-07 09:12:27 -070055bool MIRGraph::SetCore(int index) {
56 bool change = false;
57 if (!reg_location_[index].defined) {
58 reg_location_[index].core = true;
59 reg_location_[index].defined = true;
60 change = true;
61 }
62 return change;
63}
64
Brian Carlstrom7940e442013-07-12 13:46:57 -070065bool MIRGraph::SetRef(int index, bool is_ref) {
66 bool change = false;
67 if (is_ref && !reg_location_[index].defined) {
68 reg_location_[index].ref = true;
69 reg_location_[index].defined = true;
70 change = true;
71 }
72 return change;
73}
74
buzbee28c23002013-09-07 09:12:27 -070075bool MIRGraph::SetRef(int index) {
76 bool change = false;
77 if (!reg_location_[index].defined) {
78 reg_location_[index].ref = true;
79 reg_location_[index].defined = true;
80 change = true;
81 }
82 return change;
83}
84
Brian Carlstrom7940e442013-07-12 13:46:57 -070085bool MIRGraph::SetWide(int index, bool is_wide) {
86 bool change = false;
87 if (is_wide && !reg_location_[index].wide) {
88 reg_location_[index].wide = true;
89 change = true;
90 }
91 return change;
92}
93
buzbee28c23002013-09-07 09:12:27 -070094bool MIRGraph::SetWide(int index) {
95 bool change = false;
96 if (!reg_location_[index].wide) {
97 reg_location_[index].wide = true;
98 change = true;
99 }
100 return change;
101}
102
Brian Carlstrom7940e442013-07-12 13:46:57 -0700103bool MIRGraph::SetHigh(int index, bool is_high) {
104 bool change = false;
105 if (is_high && !reg_location_[index].high_word) {
106 reg_location_[index].high_word = true;
107 change = true;
108 }
109 return change;
110}
111
buzbee28c23002013-09-07 09:12:27 -0700112bool MIRGraph::SetHigh(int index) {
113 bool change = false;
114 if (!reg_location_[index].high_word) {
115 reg_location_[index].high_word = true;
116 change = true;
117 }
118 return change;
119}
120
121
Brian Carlstrom7940e442013-07-12 13:46:57 -0700122/*
123 * Infer types and sizes. We don't need to track change on sizes,
124 * as it doesn't propagate. We're guaranteed at least one pass through
125 * the cfg.
126 */
buzbee1da1e2f2013-11-15 13:37:01 -0800127bool MIRGraph::InferTypeAndSize(BasicBlock* bb, MIR* mir, bool changed) {
128 SSARepresentation *ssa_rep = mir->ssa_rep;
buzbee8c7a02a2014-06-14 12:33:09 -0700129
130 /*
131 * The dex bytecode definition does not explicitly outlaw the definition of the same
132 * virtual register to be used in both a 32-bit and 64-bit pair context. However, dx
133 * does not generate this pattern (at least recently). Further, in the next revision of
134 * dex, we will forbid this. To support the few cases in the wild, detect this pattern
135 * and punt to the interpreter.
136 */
137 bool type_mismatch = false;
138
buzbee1da1e2f2013-11-15 13:37:01 -0800139 if (ssa_rep) {
Jean Christophe Beylercc794c32014-05-02 09:34:13 -0700140 uint64_t attrs = GetDataFlowAttributes(mir);
buzbee1da1e2f2013-11-15 13:37:01 -0800141 const int* uses = ssa_rep->uses;
142 const int* defs = ssa_rep->defs;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700143
buzbee1da1e2f2013-11-15 13:37:01 -0800144 // Handle defs
145 if (attrs & DF_DA) {
146 if (attrs & DF_CORE_A) {
147 changed |= SetCore(defs[0]);
148 }
149 if (attrs & DF_REF_A) {
150 changed |= SetRef(defs[0]);
151 }
152 if (attrs & DF_A_WIDE) {
153 reg_location_[defs[0]].wide = true;
154 reg_location_[defs[1]].wide = true;
155 reg_location_[defs[1]].high_word = true;
156 DCHECK_EQ(SRegToVReg(defs[0])+1,
157 SRegToVReg(defs[1]));
158 }
159 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700160
buzbee8c7a02a2014-06-14 12:33:09 -0700161
buzbee1da1e2f2013-11-15 13:37:01 -0800162 // Handles uses
163 int next = 0;
164 if (attrs & DF_UA) {
165 if (attrs & DF_CORE_A) {
166 changed |= SetCore(uses[next]);
167 }
168 if (attrs & DF_REF_A) {
169 changed |= SetRef(uses[next]);
170 }
171 if (attrs & DF_A_WIDE) {
172 reg_location_[uses[next]].wide = true;
173 reg_location_[uses[next + 1]].wide = true;
174 reg_location_[uses[next + 1]].high_word = true;
175 DCHECK_EQ(SRegToVReg(uses[next])+1,
176 SRegToVReg(uses[next + 1]));
177 next += 2;
178 } else {
buzbee8c7a02a2014-06-14 12:33:09 -0700179 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800180 next++;
181 }
182 }
183 if (attrs & DF_UB) {
184 if (attrs & DF_CORE_B) {
185 changed |= SetCore(uses[next]);
186 }
187 if (attrs & DF_REF_B) {
188 changed |= SetRef(uses[next]);
189 }
190 if (attrs & DF_B_WIDE) {
191 reg_location_[uses[next]].wide = true;
192 reg_location_[uses[next + 1]].wide = true;
193 reg_location_[uses[next + 1]].high_word = true;
194 DCHECK_EQ(SRegToVReg(uses[next])+1,
195 SRegToVReg(uses[next + 1]));
196 next += 2;
197 } else {
buzbee8c7a02a2014-06-14 12:33:09 -0700198 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800199 next++;
200 }
201 }
202 if (attrs & DF_UC) {
203 if (attrs & DF_CORE_C) {
204 changed |= SetCore(uses[next]);
205 }
206 if (attrs & DF_REF_C) {
207 changed |= SetRef(uses[next]);
208 }
209 if (attrs & DF_C_WIDE) {
210 reg_location_[uses[next]].wide = true;
211 reg_location_[uses[next + 1]].wide = true;
212 reg_location_[uses[next + 1]].high_word = true;
213 DCHECK_EQ(SRegToVReg(uses[next])+1,
214 SRegToVReg(uses[next + 1]));
buzbee8c7a02a2014-06-14 12:33:09 -0700215 } else {
216 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800217 }
218 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700219
buzbee1da1e2f2013-11-15 13:37:01 -0800220 // Special-case return handling
221 if ((mir->dalvikInsn.opcode == Instruction::RETURN) ||
222 (mir->dalvikInsn.opcode == Instruction::RETURN_WIDE) ||
223 (mir->dalvikInsn.opcode == Instruction::RETURN_OBJECT)) {
224 switch (cu_->shorty[0]) {
225 case 'I':
buzbee8c7a02a2014-06-14 12:33:09 -0700226 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800227 changed |= SetCore(uses[0]);
228 break;
229 case 'J':
230 changed |= SetCore(uses[0]);
231 changed |= SetCore(uses[1]);
232 reg_location_[uses[0]].wide = true;
233 reg_location_[uses[1]].wide = true;
234 reg_location_[uses[1]].high_word = true;
235 break;
236 case 'F':
buzbee8c7a02a2014-06-14 12:33:09 -0700237 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800238 changed |= SetFp(uses[0]);
239 break;
240 case 'D':
241 changed |= SetFp(uses[0]);
242 changed |= SetFp(uses[1]);
243 reg_location_[uses[0]].wide = true;
244 reg_location_[uses[1]].wide = true;
245 reg_location_[uses[1]].high_word = true;
246 break;
247 case 'L':
buzbee8c7a02a2014-06-14 12:33:09 -0700248 type_mismatch |= reg_location_[uses[0]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800249 changed |= SetRef(uses[0]);
250 break;
251 default: break;
252 }
253 }
254
255 // Special-case handling for format 35c/3rc invokes
256 Instruction::Code opcode = mir->dalvikInsn.opcode;
Jean Christophe Beyler2ab40eb2014-06-02 09:03:14 -0700257 int flags = MIR::DecodedInstruction::IsPseudoMirOp(opcode) ?
Jean Christophe Beylerfb0ea2d2014-07-29 13:20:42 -0700258 0 : mir->dalvikInsn.FlagsOf();
buzbee1da1e2f2013-11-15 13:37:01 -0800259 if ((flags & Instruction::kInvoke) &&
260 (attrs & (DF_FORMAT_35C | DF_FORMAT_3RC))) {
261 DCHECK_EQ(next, 0);
262 int target_idx = mir->dalvikInsn.vB;
263 const char* shorty = GetShortyFromTargetIdx(target_idx);
264 // Handle result type if floating point
265 if ((shorty[0] == 'F') || (shorty[0] == 'D')) {
266 MIR* move_result_mir = FindMoveResult(bb, mir);
267 // Result might not be used at all, so no move-result
268 if (move_result_mir && (move_result_mir->dalvikInsn.opcode !=
269 Instruction::MOVE_RESULT_OBJECT)) {
270 SSARepresentation* tgt_rep = move_result_mir->ssa_rep;
271 DCHECK(tgt_rep != NULL);
272 tgt_rep->fp_def[0] = true;
273 changed |= SetFp(tgt_rep->defs[0]);
274 if (shorty[0] == 'D') {
275 tgt_rep->fp_def[1] = true;
276 changed |= SetFp(tgt_rep->defs[1]);
277 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700278 }
279 }
buzbee1da1e2f2013-11-15 13:37:01 -0800280 int num_uses = mir->dalvikInsn.vA;
281 // If this is a non-static invoke, mark implicit "this"
Vladimir Marko321b9872014-11-24 16:33:51 +0000282 if (!IsInstructionInvokeStatic(mir->dalvikInsn.opcode)) {
buzbee1da1e2f2013-11-15 13:37:01 -0800283 reg_location_[uses[next]].defined = true;
284 reg_location_[uses[next]].ref = true;
buzbee8c7a02a2014-06-14 12:33:09 -0700285 type_mismatch |= reg_location_[uses[next]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800286 next++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700287 }
buzbee1da1e2f2013-11-15 13:37:01 -0800288 uint32_t cpos = 1;
289 if (strlen(shorty) > 1) {
290 for (int i = next; i < num_uses;) {
291 DCHECK_LT(cpos, strlen(shorty));
292 switch (shorty[cpos++]) {
293 case 'D':
294 ssa_rep->fp_use[i] = true;
295 ssa_rep->fp_use[i+1] = true;
296 reg_location_[uses[i]].wide = true;
297 reg_location_[uses[i+1]].wide = true;
298 reg_location_[uses[i+1]].high_word = true;
299 DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1]));
300 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700301 break;
302 case 'J':
buzbee1da1e2f2013-11-15 13:37:01 -0800303 reg_location_[uses[i]].wide = true;
304 reg_location_[uses[i+1]].wide = true;
305 reg_location_[uses[i+1]].high_word = true;
306 DCHECK_EQ(SRegToVReg(uses[i])+1, SRegToVReg(uses[i+1]));
307 changed |= SetCore(uses[i]);
308 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700309 break;
310 case 'F':
buzbee8c7a02a2014-06-14 12:33:09 -0700311 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800312 ssa_rep->fp_use[i] = true;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700313 break;
314 case 'L':
buzbee8c7a02a2014-06-14 12:33:09 -0700315 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800316 changed |= SetRef(uses[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700317 break;
buzbee1da1e2f2013-11-15 13:37:01 -0800318 default:
buzbee8c7a02a2014-06-14 12:33:09 -0700319 type_mismatch |= reg_location_[uses[i]].wide;
buzbee1da1e2f2013-11-15 13:37:01 -0800320 changed |= SetCore(uses[i]);
321 break;
322 }
323 i++;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700324 }
325 }
buzbee1da1e2f2013-11-15 13:37:01 -0800326 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700327
buzbee1da1e2f2013-11-15 13:37:01 -0800328 for (int i = 0; ssa_rep->fp_use && i< ssa_rep->num_uses; i++) {
Vladimir Marko55fff042014-07-10 12:42:52 +0100329 if (ssa_rep->fp_use[i]) {
buzbee1da1e2f2013-11-15 13:37:01 -0800330 changed |= SetFp(uses[i]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700331 }
Vladimir Marko55fff042014-07-10 12:42:52 +0100332 }
buzbee1da1e2f2013-11-15 13:37:01 -0800333 for (int i = 0; ssa_rep->fp_def && i< ssa_rep->num_defs; i++) {
Vladimir Marko55fff042014-07-10 12:42:52 +0100334 if (ssa_rep->fp_def[i]) {
buzbee1da1e2f2013-11-15 13:37:01 -0800335 changed |= SetFp(defs[i]);
336 }
Vladimir Marko55fff042014-07-10 12:42:52 +0100337 }
buzbee1da1e2f2013-11-15 13:37:01 -0800338 // Special-case handling for moves & Phi
339 if (attrs & (DF_IS_MOVE | DF_NULL_TRANSFER_N)) {
340 /*
341 * If any of our inputs or outputs is defined, set all.
342 * Some ugliness related to Phi nodes and wide values.
343 * The Phi set will include all low words or all high
344 * words, so we have to treat them specially.
345 */
buzbee35ba7f32014-05-31 08:59:01 -0700346 bool is_phi = (static_cast<int>(mir->dalvikInsn.opcode) == kMirOpPhi);
buzbee1da1e2f2013-11-15 13:37:01 -0800347 RegLocation rl_temp = reg_location_[defs[0]];
348 bool defined_fp = rl_temp.defined && rl_temp.fp;
349 bool defined_core = rl_temp.defined && rl_temp.core;
350 bool defined_ref = rl_temp.defined && rl_temp.ref;
351 bool is_wide = rl_temp.wide || ((attrs & DF_A_WIDE) != 0);
352 bool is_high = is_phi && rl_temp.wide && rl_temp.high_word;
353 for (int i = 0; i < ssa_rep->num_uses; i++) {
354 rl_temp = reg_location_[uses[i]];
355 defined_fp |= rl_temp.defined && rl_temp.fp;
356 defined_core |= rl_temp.defined && rl_temp.core;
357 defined_ref |= rl_temp.defined && rl_temp.ref;
358 is_wide |= rl_temp.wide;
359 is_high |= is_phi && rl_temp.wide && rl_temp.high_word;
360 }
361 /*
362 * We don't normally expect to see a Dalvik register definition used both as a
363 * floating point and core value, though technically it could happen with constants.
364 * Until we have proper typing, detect this situation and disable register promotion
365 * (which relies on the distinction between core a fp usages).
366 */
367 if ((defined_fp && (defined_core | defined_ref)) &&
368 ((cu_->disable_opt & (1 << kPromoteRegs)) == 0)) {
369 LOG(WARNING) << PrettyMethod(cu_->method_idx, *cu_->dex_file)
370 << " op at block " << bb->id
371 << " has both fp and core/ref uses for same def.";
372 cu_->disable_opt |= (1 << kPromoteRegs);
373 }
374 changed |= SetFp(defs[0], defined_fp);
375 changed |= SetCore(defs[0], defined_core);
376 changed |= SetRef(defs[0], defined_ref);
377 changed |= SetWide(defs[0], is_wide);
378 changed |= SetHigh(defs[0], is_high);
379 if (attrs & DF_A_WIDE) {
380 changed |= SetWide(defs[1]);
381 changed |= SetHigh(defs[1]);
382 }
Stephen Kyle8fe0e352014-10-16 15:02:42 +0100383
384 bool has_ins = (GetNumOfInVRs() > 0);
385
buzbee1da1e2f2013-11-15 13:37:01 -0800386 for (int i = 0; i < ssa_rep->num_uses; i++) {
Stephen Kyle8fe0e352014-10-16 15:02:42 +0100387 if (has_ins && IsInVReg(uses[i])) {
388 // NB: The SSA name for the first def of an in-reg will be the same as
389 // the reg's actual name.
390 if (!reg_location_[uses[i]].fp && defined_fp) {
391 // If we were about to infer that this first def of an in-reg is a float
392 // when it wasn't previously (because float/int is set during SSA initialization),
393 // do not allow this to happen.
394 continue;
395 }
396 }
buzbee1da1e2f2013-11-15 13:37:01 -0800397 changed |= SetFp(uses[i], defined_fp);
398 changed |= SetCore(uses[i], defined_core);
399 changed |= SetRef(uses[i], defined_ref);
400 changed |= SetWide(uses[i], is_wide);
401 changed |= SetHigh(uses[i], is_high);
402 }
403 if (attrs & DF_A_WIDE) {
404 DCHECK_EQ(ssa_rep->num_uses, 2);
405 changed |= SetWide(uses[1]);
406 changed |= SetHigh(uses[1]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700407 }
408 }
409 }
buzbee8c7a02a2014-06-14 12:33:09 -0700410 if (type_mismatch) {
411 LOG(WARNING) << "Deprecated dex type mismatch, interpreting "
412 << PrettyMethod(cu_->method_idx, *cu_->dex_file);
413 LOG(INFO) << "@ 0x" << std::hex << mir->offset;
414 SetPuntToInterpreter(true);
415 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700416 return changed;
417}
418
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700419static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700420
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700421void MIRGraph::DumpRegLocTable(RegLocation* table, int count) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700422 for (int i = 0; i < count; i++) {
423 LOG(INFO) << StringPrintf("Loc[%02d] : %s, %c %c %c %c %c %c 0x%04x S%d",
424 table[i].orig_sreg, storage_name[table[i].location],
425 table[i].wide ? 'W' : 'N', table[i].defined ? 'D' : 'U',
426 table[i].fp ? 'F' : table[i].ref ? 'R' :'C',
427 table[i].is_const ? 'c' : 'n',
428 table[i].high_word ? 'H' : 'L', table[i].home ? 'h' : 't',
429 table[i].reg.GetRawBits(),
430 table[i].s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700431 }
432}
433
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000434// FIXME - will likely need to revisit all uses of this.
buzbee091cc402014-03-31 10:14:40 -0700435static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
Bill Buzbee00e1ec62014-02-27 23:44:13 +0000436 RegStorage(), INVALID_SREG, INVALID_SREG};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700437
buzbee1da1e2f2013-11-15 13:37:01 -0800438void MIRGraph::InitRegLocations() {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700439 // Allocate the location map. We also include the maximum possible temps because
440 // the temp allocation initializes reg location as well (in order to deal with
441 // case when it will be called after this pass).
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800442 int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps();
Vladimir Markoe4fcc5b2015-02-13 10:28:29 +0000443 RegLocation* loc = arena_->AllocArray<RegLocation>(max_regs, kArenaAllocRegAlloc);
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700444 for (int i = 0; i < GetNumSSARegs(); i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700445 loc[i] = fresh_loc;
446 loc[i].s_reg_low = i;
Vladimir Marko066f9e42015-01-16 16:04:43 +0000447 loc[i].is_const = false; // Constants will be marked by constant propagation pass later.
Jean Christophe Beyler1ceea7e2014-04-15 16:18:48 -0700448 loc[i].wide = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700449 }
450
buzbeef2c3e562014-05-29 12:37:25 -0700451 /* Treat Method* as a normal reference */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700452 int method_sreg = GetMethodSReg();
453 loc[method_sreg].ref = true;
454 loc[method_sreg].location = kLocCompilerTemp;
455 loc[method_sreg].defined = true;
buzbeef2c3e562014-05-29 12:37:25 -0700456
Brian Carlstrom7940e442013-07-12 13:46:57 -0700457 reg_location_ = loc;
458
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700459 int num_regs = GetNumOfCodeVRs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700460
461 /* Add types of incoming arguments based on signature */
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700462 int num_ins = GetNumOfInVRs();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700463 if (num_ins > 0) {
464 int s_reg = num_regs - num_ins;
465 if ((cu_->access_flags & kAccStatic) == 0) {
466 // For non-static, skip past "this"
467 reg_location_[s_reg].defined = true;
468 reg_location_[s_reg].ref = true;
469 s_reg++;
470 }
471 const char* shorty = cu_->shorty;
472 int shorty_len = strlen(shorty);
473 for (int i = 1; i < shorty_len; i++) {
474 switch (shorty[i]) {
475 case 'D':
476 reg_location_[s_reg].wide = true;
477 reg_location_[s_reg+1].high_word = true;
478 reg_location_[s_reg+1].fp = true;
479 DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1));
480 reg_location_[s_reg].fp = true;
481 reg_location_[s_reg].defined = true;
482 s_reg++;
483 break;
484 case 'J':
485 reg_location_[s_reg].wide = true;
486 reg_location_[s_reg+1].high_word = true;
487 DCHECK_EQ(SRegToVReg(s_reg)+1, SRegToVReg(s_reg+1));
488 reg_location_[s_reg].core = true;
489 reg_location_[s_reg].defined = true;
490 s_reg++;
491 break;
492 case 'F':
493 reg_location_[s_reg].fp = true;
494 reg_location_[s_reg].defined = true;
495 break;
496 case 'L':
497 reg_location_[s_reg].ref = true;
498 reg_location_[s_reg].defined = true;
499 break;
500 default:
501 reg_location_[s_reg].core = true;
502 reg_location_[s_reg].defined = true;
503 break;
504 }
505 s_reg++;
506 }
507 }
buzbee1da1e2f2013-11-15 13:37:01 -0800508}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700509
buzbee1da1e2f2013-11-15 13:37:01 -0800510/*
511 * Set the s_reg_low field to refer to the pre-SSA name of the
512 * base Dalvik virtual register. Once we add a better register
513 * allocator, remove this remapping.
514 */
515void MIRGraph::RemapRegLocations() {
Brian Carlstrom38f85e42013-07-18 14:45:22 -0700516 for (int i = 0; i < GetNumSSARegs(); i++) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700517 int orig_sreg = reg_location_[i].s_reg_low;
518 reg_location_[i].orig_sreg = orig_sreg;
519 reg_location_[i].s_reg_low = SRegToVReg(orig_sreg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700520 }
521}
522
523} // namespace art