Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 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 | |
Andreas Gampe | 0b9203e | 2015-01-22 20:39:27 -0800 | [diff] [blame] | 17 | #include "base/logging.h" |
| 18 | #include "base/stringprintf.h" |
| 19 | #include "compiler_ir.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 20 | #include "dex/dataflow_iterator-inl.h" |
Andreas Gampe | 0b9203e | 2015-01-22 20:39:27 -0800 | [diff] [blame] | 21 | #include "dex_flags.h" |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 22 | #include "driver/dex_compilation_unit.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 26 | static const char* storage_name[] = {" Frame ", "PhysReg", " CompilerTemp "}; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 28 | void MIRGraph::DumpRegLocTable(RegLocation* table, int count) { |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 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); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 41 | // FIXME - will likely need to revisit all uses of this. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 42 | static const RegLocation fresh_loc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0, |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 43 | RegStorage(), INVALID_SREG, INVALID_SREG}; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 44 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 45 | void MIRGraph::InitRegLocations() { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 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). |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 49 | int max_regs = GetNumSSARegs() + GetMaxPossibleCompilerTemps(); |
Vladimir Marko | e4fcc5b | 2015-02-13 10:28:29 +0000 | [diff] [blame] | 50 | RegLocation* loc = arena_->AllocArray<RegLocation>(max_regs, kArenaAllocRegAlloc); |
Brian Carlstrom | 38f85e4 | 2013-07-18 14:45:22 -0700 | [diff] [blame] | 51 | for (int i = 0; i < GetNumSSARegs(); i++) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 52 | loc[i] = fresh_loc; |
| 53 | loc[i].s_reg_low = i; |
Vladimir Marko | 066f9e4 | 2015-01-16 16:04:43 +0000 | [diff] [blame] | 54 | loc[i].is_const = false; // Constants will be marked by constant propagation pass later. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Vladimir Marko | c91df2d | 2015-04-23 09:29:21 +0000 | [diff] [blame] | 57 | /* Mark the location of ArtMethod* as temporary */ |
| 58 | loc[GetMethodSReg()].location = kLocCompilerTemp; |
buzbee | f2c3e56 | 2014-05-29 12:37:25 -0700 | [diff] [blame] | 59 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 60 | reg_location_ = loc; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 61 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 62 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 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() { |
Brian Carlstrom | 38f85e4 | 2013-07-18 14:45:22 -0700 | [diff] [blame] | 69 | for (int i = 0; i < GetNumSSARegs(); i++) { |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 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); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | } // namespace art |