Home | History | Annotate | Download | only in dex
      1 /*
      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 "base/logging.h"
     18 #include "base/stringprintf.h"
     19 #include "compiler_ir.h"
     20 #include "dex/dataflow_iterator-inl.h"
     21 #include "dex_flags.h"
     22 #include "driver/dex_compilation_unit.h"
     23 
     24 namespace art {
     25 
     26 static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "};
     27 
     28 void MIRGraph::DumpRegLocTable(RegLocation* table, int count) {
     29   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);
     38   }
     39 }
     40 
     41 // FIXME - will likely need to revisit all uses of this.
     42 static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
     43                                       RegStorage(), INVALID_SREG, INVALID_SREG};
     44 
     45 void MIRGraph::InitRegLocations() {
     46   // 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).
     49   int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps();
     50   RegLocation* loc = arena_->AllocArray<RegLocation>(max_regs, kArenaAllocRegAlloc);
     51   for (int i = 0; i < GetNumSSARegs(); i++) {
     52     loc[i] = fresh_loc;
     53     loc[i].s_reg_low = i;
     54     loc[i].is_const = false;  // Constants will be marked by constant propagation pass later.
     55   }
     56 
     57   /* Mark the location of ArtMethod* as temporary */
     58   loc[GetMethodSReg()].location = kLocCompilerTemp;
     59 
     60   reg_location_ = loc;
     61 }
     62 
     63 /*
     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  */
     68 void MIRGraph::RemapRegLocations() {
     69   for (int i = 0; i < GetNumSSARegs(); i++) {
     70     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);
     73   }
     74 }
     75 
     76 }  // namespace art
     77