Add inferred register category map to Method object.
Change-Id: I69456c79eb3ce3df1924bffe4db5314b0552f1de
diff --git a/src/compiler_llvm/inferred_reg_category_map.cc b/src/compiler_llvm/inferred_reg_category_map.cc
new file mode 100644
index 0000000..528247b
--- /dev/null
+++ b/src/compiler_llvm/inferred_reg_category_map.cc
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2012 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 "inferred_reg_category_map.h"
+
+#include "backend_types.h"
+#include "stl_util.h"
+
+#include <stdint.h>
+#include <vector>
+
+namespace art {
+namespace compiler_llvm {
+
+
+InferredRegCategoryMap::InferredRegCategoryMap(uint32_t insns_size,
+ uint8_t regs_size)
+: registers_size_(regs_size), lines_(insns_size, NULL) {
+}
+
+InferredRegCategoryMap::~InferredRegCategoryMap() {
+ STLDeleteElements(&lines_);
+}
+
+RegCategory InferredRegCategoryMap::GetRegCategory(uint32_t dex_pc,
+ uint16_t reg_idx) const {
+ CHECK_NE(lines_[dex_pc], static_cast<RegCategoryLine*>(NULL));
+ return static_cast<RegCategory>((*lines_[dex_pc])[reg_idx]);
+}
+
+void InferredRegCategoryMap::SetRegCategory(uint32_t dex_pc,
+ uint16_t reg_idx,
+ RegCategory cat) {
+ if (lines_[dex_pc] == NULL) {
+ lines_[dex_pc] = new RegCategoryLine(registers_size_, kRegUnknown);
+ }
+
+ (*lines_[dex_pc])[reg_idx] = cat;
+}
+
+bool InferredRegCategoryMap::
+operator==(InferredRegCategoryMap const& rhs) const {
+
+ if (registers_size_ != rhs.registers_size_) {
+ return false;
+ }
+
+ if (lines_.size() != rhs.lines_.size()) {
+ return false;
+ }
+
+ for (size_t i = 0; i < lines_.size(); ++i) {
+ if (lines_[i] == NULL && rhs.lines_[i] == NULL) {
+ continue;
+ }
+
+ if ((lines_[i] == NULL && rhs.lines_[i] != NULL) ||
+ (lines_[i] != NULL && rhs.lines_[i] == NULL)) {
+ return false;
+ }
+
+ if (*lines_[i] != *rhs.lines_[i]) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool InferredRegCategoryMap::
+operator!=(InferredRegCategoryMap const& rhs) const {
+
+ return !(*this == rhs);
+}
+
+
+} // namespace compiler_llvm
+} // namespace art
diff --git a/src/compiler_llvm/inferred_reg_category_map.h b/src/compiler_llvm/inferred_reg_category_map.h
new file mode 100644
index 0000000..55d64fe
--- /dev/null
+++ b/src/compiler_llvm/inferred_reg_category_map.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#ifndef ART_SRC_COMPILER_LLVM_INFERRED_REG_CATEGORY_MAP_H_
+#define ART_SRC_COMPILER_LLVM_INFERRED_REG_CATEGORY_MAP_H_
+
+#include "backend_types.h"
+
+#include <stdint.h>
+#include <vector>
+
+namespace art {
+namespace compiler_llvm {
+
+
+class InferredRegCategoryMap {
+ private:
+ typedef std::vector<uint8_t> RegCategoryLine;
+
+ public:
+ InferredRegCategoryMap(uint32_t insns_size_in_code_units, uint8_t regs_size);
+
+ ~InferredRegCategoryMap();
+
+ RegCategory GetRegCategory(uint32_t dex_pc, uint16_t reg_idx) const;
+ void SetRegCategory(uint32_t dex_pc, uint16_t reg_idx, RegCategory cat);
+
+ bool operator==(InferredRegCategoryMap const& rhs) const;
+ bool operator!=(InferredRegCategoryMap const& rhs) const;
+
+ private:
+ uint16_t registers_size_;
+
+ std::vector<RegCategoryLine*> lines_;
+
+ DISALLOW_COPY_AND_ASSIGN(InferredRegCategoryMap);
+};
+
+
+} // namespace compiler_llvm
+} // namespace art
+
+#endif // ART_SRC_COMPILER_LLVM_INFERRED_REG_CATEGORY_MAP_H_
diff --git a/src/compiler_llvm/method_compiler.cc b/src/compiler_llvm/method_compiler.cc
index cf0ea3e..767897c 100644
--- a/src/compiler_llvm/method_compiler.cc
+++ b/src/compiler_llvm/method_compiler.cc
@@ -16,6 +16,7 @@
#include "method_compiler.h"
+#include "backend_types.h"
#include "compiler.h"
#include "ir_builder.h"
#include "logging.h"
diff --git a/src/compiler_llvm/method_compiler.h b/src/compiler_llvm/method_compiler.h
index 8d9820a..7b1154d 100644
--- a/src/compiler_llvm/method_compiler.h
+++ b/src/compiler_llvm/method_compiler.h
@@ -17,6 +17,7 @@
#ifndef ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_
#define ART_SRC_COMPILER_LLVM_METHOD_COMPILER_H_
+#include "backend_types.h"
#include "constants.h"
#include "dex_file.h"
#include "dex_instruction.h"