blob: 0875a3f8a0d086b7650fe6e3b6405cdf0af076b2 [file] [log] [blame]
Logan Chienfca7e872011-12-20 20:08:22 +08001/*
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
25namespace art {
26namespace compiler_llvm {
27
28
29InferredRegCategoryMap::InferredRegCategoryMap(uint32_t insns_size,
TDYa127b2eb5c12012-05-24 15:52:10 -070030 uint16_t regs_size)
31: registers_size_(regs_size), can_be_object_(regs_size) {
Logan Chienfca7e872011-12-20 20:08:22 +080032}
33
34InferredRegCategoryMap::~InferredRegCategoryMap() {
TDYa127b2eb5c12012-05-24 15:52:10 -070035 STLDeleteValues(&lines_);
Logan Chienfca7e872011-12-20 20:08:22 +080036}
37
38RegCategory InferredRegCategoryMap::GetRegCategory(uint32_t dex_pc,
39 uint16_t reg_idx) const {
TDYa127b2eb5c12012-05-24 15:52:10 -070040 if (lines_.count(dex_pc) == 0) {
TDYa12733206c22012-04-10 04:37:29 -070041 return kRegUnknown;
42 }
TDYa127b2eb5c12012-05-24 15:52:10 -070043 return lines_.Get(dex_pc)->GetRegCategory(reg_idx);
Logan Chienfca7e872011-12-20 20:08:22 +080044}
45
46void InferredRegCategoryMap::SetRegCategory(uint32_t dex_pc,
47 uint16_t reg_idx,
48 RegCategory cat) {
TDYa12733206c22012-04-10 04:37:29 -070049 if (cat != kRegUnknown) {
TDYa127b2eb5c12012-05-24 15:52:10 -070050 if (lines_.count(dex_pc) == 0) {
51 lines_.Put(dex_pc, new RegCategoryLine(registers_size_));
TDYa12733206c22012-04-10 04:37:29 -070052 }
Logan Chienfca7e872011-12-20 20:08:22 +080053
TDYa127b2eb5c12012-05-24 15:52:10 -070054 lines_.Get(dex_pc)->SetRegCategory(reg_idx, cat);
TDYa12733206c22012-04-10 04:37:29 -070055 }
Logan Chienfca7e872011-12-20 20:08:22 +080056}
57
TDYa1271d7e5102012-05-13 09:27:05 -070058bool InferredRegCategoryMap::IsRegCanBeObject(uint16_t reg_idx) const {
59 return can_be_object_[reg_idx];
60}
61
62void InferredRegCategoryMap::SetRegCanBeObject(uint16_t reg_idx) {
63 can_be_object_[reg_idx] = true;
64}
65
Logan Chienfca7e872011-12-20 20:08:22 +080066bool InferredRegCategoryMap::
67operator==(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) {
TDYa127b2eb5c12012-05-24 15:52:10 -070078 if (lines_.count(i) == 0 && rhs.lines_.count(i) == 0) {
Logan Chienfca7e872011-12-20 20:08:22 +080079 continue;
80 }
81
TDYa127b2eb5c12012-05-24 15:52:10 -070082 if ((lines_.count(i) == 0 && rhs.lines_.count(i) != 0) ||
83 (lines_.count(i) != 0 && rhs.lines_.count(i) == 0)) {
Logan Chienfca7e872011-12-20 20:08:22 +080084 return false;
85 }
86
TDYa127b2eb5c12012-05-24 15:52:10 -070087 if (*lines_.Get(i) != *rhs.lines_.Get(i)) {
Logan Chienfca7e872011-12-20 20:08:22 +080088 return false;
89 }
90 }
91
92 return true;
93}
94
95bool InferredRegCategoryMap::
96operator!=(InferredRegCategoryMap const& rhs) const {
97
98 return !(*this == rhs);
99}
100
101
102} // namespace compiler_llvm
103} // namespace art