blob: 948ba7b273db2adf36b1250e3c8e4def64df9c68 [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
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -070026static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "};
Brian Carlstrom7940e442013-07-12 13:46:57 -070027
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070028void MIRGraph::DumpRegLocTable(RegLocation* table, int count) {
Andreas Gampe53c913b2014-08-12 23:19:23 -070029 for (int i = 0; i < count; i++) {
30 LOG(INFO) << StringPrintf("Loc[%02d] : %s, %c %c %c %c %c %c 0x%04x S%d",
31 table[i].orig_sreg, storage_name[table[i].location],
32 table[i].wide ? 'W' : 'N', table[i].defined ? 'D' : 'U',
33 table[i].fp ? 'F' : table[i].ref ? 'R' :'C',
34 table[i].is_const ? 'c' : 'n',
35 table[i].high_word ? 'H' : 'L', table[i].home ? 'h' : 't',
36 table[i].reg.GetRawBits(),
37 table[i].s_reg_low);
Brian Carlstrom7940e442013-07-12 13:46:57 -070038 }
39}
40
Bill Buzbee00e1ec62014-02-27 23:44:13 +000041// FIXME - will likely need to revisit all uses of this.
buzbee091cc402014-03-31 10:14:40 -070042static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
Bill Buzbee00e1ec62014-02-27 23:44:13 +000043 RegStorage(), INVALID_SREG, INVALID_SREG};
Brian Carlstrom7940e442013-07-12 13:46:57 -070044
buzbee1da1e2f2013-11-15 13:37:01 -080045void MIRGraph::InitRegLocations() {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -070046 // Allocate the location map. We also include the maximum possible temps because
47 // the temp allocation initializes reg location as well (in order to deal with
48 // case when it will be called after this pass).
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -080049 int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps();
Vladimir Markoe4fcc5b2015-02-13 10:28:29 +000050 RegLocation* loc = arena_->AllocArray<RegLocation>(max_regs, kArenaAllocRegAlloc);
Brian Carlstrom38f85e42013-07-18 14:45:22 -070051 for (int i = 0; i < GetNumSSARegs(); i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070052 loc[i] = fresh_loc;
53 loc[i].s_reg_low = i;
Vladimir Marko066f9e42015-01-16 16:04:43 +000054 loc[i].is_const = false; // Constants will be marked by constant propagation pass later.
Brian Carlstrom7940e442013-07-12 13:46:57 -070055 }
56
Vladimir Markoc91df2d2015-04-23 09:29:21 +000057 /* Mark the location of ArtMethod* as temporary */
58 loc[GetMethodSReg()].location = kLocCompilerTemp;
buzbeef2c3e562014-05-29 12:37:25 -070059
Brian Carlstrom7940e442013-07-12 13:46:57 -070060 reg_location_ = loc;
buzbee1da1e2f2013-11-15 13:37:01 -080061}
Brian Carlstrom7940e442013-07-12 13:46:57 -070062
buzbee1da1e2f2013-11-15 13:37:01 -080063/*
64 * Set the s_reg_low field to refer to the pre-SSA name of the
65 * base Dalvik virtual register. Once we add a better register
66 * allocator, remove this remapping.
67 */
68void MIRGraph::RemapRegLocations() {
Brian Carlstrom38f85e42013-07-18 14:45:22 -070069 for (int i = 0; i < GetNumSSARegs(); i++) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -070070 int orig_sreg = reg_location_[i].s_reg_low;
71 reg_location_[i].orig_sreg = orig_sreg;
72 reg_location_[i].s_reg_low = SRegToVReg(orig_sreg);
Brian Carlstrom7940e442013-07-12 13:46:57 -070073 }
74}
75
76} // namespace art