summaryrefslogtreecommitdiffstats
path: root/compiler/dex/vreg_analysis.cc
blob: 948ba7b273db2adf36b1250e3c8e4def64df9c68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "base/logging.h"
#include "base/stringprintf.h"
#include "compiler_ir.h"
#include "dex/dataflow_iterator-inl.h"
#include "dex_flags.h"
#include "driver/dex_compilation_unit.h"

namespace art {

static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "};

void MIRGraph::DumpRegLocTable(RegLocation* table, int count) {
  for (int i = 0; i < count; i++) {
    LOG(INFO) << StringPrintf("Loc[%02d] : %s, %c %c %c %c %c %c 0x%04x S%d",
                              table[i].orig_sreg, storage_name[table[i].location],
                              table[i].wide ? 'W' : 'N', table[i].defined ? 'D' : 'U',
                              table[i].fp ? 'F' : table[i].ref ? 'R' :'C',
                              table[i].is_const ? 'c' : 'n',
                              table[i].high_word ? 'H' : 'L', table[i].home ? 'h' : 't',
                              table[i].reg.GetRawBits(),
                              table[i].s_reg_low);
  }
}

// FIXME - will likely need to revisit all uses of this.
static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
                                      RegStorage(), INVALID_SREG, INVALID_SREG};

void MIRGraph::InitRegLocations() {
  // Allocate the location map. We also include the maximum possible temps because
  // the temp allocation initializes reg location as well (in order to deal with
  // case when it will be called after this pass).
  int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps();
  RegLocation* loc = arena_->AllocArray<RegLocation>(max_regs, kArenaAllocRegAlloc);
  for (int i = 0; i < GetNumSSARegs(); i++) {
    loc[i] = fresh_loc;
    loc[i].s_reg_low = i;
    loc[i].is_const = false;  // Constants will be marked by constant propagation pass later.
  }

  /* Mark the location of ArtMethod* as temporary */
  loc[GetMethodSReg()].location = kLocCompilerTemp;

  reg_location_ = loc;
}

/*
 * Set the s_reg_low field to refer to the pre-SSA name of the
 * base Dalvik virtual register.  Once we add a better register
 * allocator, remove this remapping.
 */
void MIRGraph::RemapRegLocations() {
  for (int i = 0; i < GetNumSSARegs(); i++) {
    int orig_sreg = reg_location_[i].s_reg_low;
    reg_location_[i].orig_sreg = orig_sreg;
    reg_location_[i].s_reg_low = SRegToVReg(orig_sreg);
  }
}

}  // namespace art