Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 "inferred_reg_category_map.h" |
| 18 | |
| 19 | #include "backend_types.h" |
| 20 | #include "stl_util.h" |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <vector> |
| 24 | |
| 25 | namespace art { |
| 26 | namespace compiler_llvm { |
| 27 | |
| 28 | |
| 29 | InferredRegCategoryMap::InferredRegCategoryMap(uint32_t insns_size, |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 30 | uint16_t regs_size) |
| 31 | : registers_size_(regs_size), can_be_object_(regs_size) { |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | InferredRegCategoryMap::~InferredRegCategoryMap() { |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 35 | STLDeleteValues(&lines_); |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | RegCategory InferredRegCategoryMap::GetRegCategory(uint32_t dex_pc, |
| 39 | uint16_t reg_idx) const { |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 40 | if (lines_.count(dex_pc) == 0) { |
TDYa127 | 33206c2 | 2012-04-10 04:37:29 -0700 | [diff] [blame] | 41 | return kRegUnknown; |
| 42 | } |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 43 | return lines_.Get(dex_pc)->GetRegCategory(reg_idx); |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void InferredRegCategoryMap::SetRegCategory(uint32_t dex_pc, |
| 47 | uint16_t reg_idx, |
| 48 | RegCategory cat) { |
TDYa127 | 33206c2 | 2012-04-10 04:37:29 -0700 | [diff] [blame] | 49 | if (cat != kRegUnknown) { |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 50 | if (lines_.count(dex_pc) == 0) { |
| 51 | lines_.Put(dex_pc, new RegCategoryLine(registers_size_)); |
TDYa127 | 33206c2 | 2012-04-10 04:37:29 -0700 | [diff] [blame] | 52 | } |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 53 | |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 54 | lines_.Get(dex_pc)->SetRegCategory(reg_idx, cat); |
TDYa127 | 33206c2 | 2012-04-10 04:37:29 -0700 | [diff] [blame] | 55 | } |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 56 | } |
| 57 | |
TDYa127 | 1d7e510 | 2012-05-13 09:27:05 -0700 | [diff] [blame] | 58 | bool InferredRegCategoryMap::IsRegCanBeObject(uint16_t reg_idx) const { |
| 59 | return can_be_object_[reg_idx]; |
| 60 | } |
| 61 | |
| 62 | void InferredRegCategoryMap::SetRegCanBeObject(uint16_t reg_idx) { |
| 63 | can_be_object_[reg_idx] = true; |
| 64 | } |
| 65 | |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 66 | bool InferredRegCategoryMap:: |
| 67 | operator==(InferredRegCategoryMap const& rhs) const { |
| 68 | |
| 69 | if (registers_size_ != rhs.registers_size_) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | if (lines_.size() != rhs.lines_.size()) { |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | for (size_t i = 0; i < lines_.size(); ++i) { |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 78 | if (lines_.count(i) == 0 && rhs.lines_.count(i) == 0) { |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 79 | continue; |
| 80 | } |
| 81 | |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 82 | if ((lines_.count(i) == 0 && rhs.lines_.count(i) != 0) || |
| 83 | (lines_.count(i) != 0 && rhs.lines_.count(i) == 0)) { |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 84 | return false; |
| 85 | } |
| 86 | |
TDYa127 | b2eb5c1 | 2012-05-24 15:52:10 -0700 | [diff] [blame^] | 87 | if (*lines_.Get(i) != *rhs.lines_.Get(i)) { |
Logan Chien | fca7e87 | 2011-12-20 20:08:22 +0800 | [diff] [blame] | 88 | return false; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | bool InferredRegCategoryMap:: |
| 96 | operator!=(InferredRegCategoryMap const& rhs) const { |
| 97 | |
| 98 | return !(*this == rhs); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | } // namespace compiler_llvm |
| 103 | } // namespace art |