managed_register.h revision 75b9113b2b0a5807043af2a669a93d1579af8e2c
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#ifndef ART_COMPILER_UTILS_MANAGED_REGISTER_H_
18#define ART_COMPILER_UTILS_MANAGED_REGISTER_H_
19
20#include <vector>
21
22namespace art {
23
24namespace arm {
25class ArmManagedRegister;
26}
27namespace arm64 {
28class Arm64ManagedRegister;
29}
30namespace mips {
31class MipsManagedRegister;
32}
33
34namespace x86 {
35class X86ManagedRegister;
36}
37
38namespace x86_64 {
39class X86_64ManagedRegister;
40}
41
42class ManagedRegister {
43 public:
44  // ManagedRegister is a value class. There exists no method to change the
45  // internal state. We therefore allow a copy constructor and an
46  // assignment-operator.
47  ManagedRegister(const ManagedRegister& other) : id_(other.id_) { }
48
49  ManagedRegister& operator=(const ManagedRegister& other) {
50    id_ = other.id_;
51    return *this;
52  }
53
54  arm::ArmManagedRegister AsArm() const;
55  arm64::Arm64ManagedRegister AsArm64() const;
56  mips::MipsManagedRegister AsMips() const;
57  x86::X86ManagedRegister AsX86() const;
58  x86_64::X86_64ManagedRegister AsX86_64() const;
59
60  // It is valid to invoke Equals on and with a NoRegister.
61  bool Equals(const ManagedRegister& other) const {
62    return id_ == other.id_;
63  }
64
65  bool IsNoRegister() const {
66    return id_ == kNoRegister;
67  }
68
69  static ManagedRegister NoRegister() {
70    return ManagedRegister();
71  }
72
73 protected:
74  static const int kNoRegister = -1;
75
76  ManagedRegister() : id_(kNoRegister) { }
77  explicit ManagedRegister(int reg_id) : id_(reg_id) { }
78
79  int id_;
80};
81
82class ManagedRegisterSpill : public ManagedRegister {
83 public:
84  // ManagedRegisterSpill contains information about data type size and location in caller frame
85  // These additional attributes could be defined by calling convention (EntrySpills)
86  ManagedRegisterSpill(const ManagedRegister& other, uint32_t size, uint32_t spill_offset)
87      : ManagedRegister(other), size_(size), spill_offset_(spill_offset)  { }
88
89  explicit ManagedRegisterSpill(const ManagedRegister& other)
90      : ManagedRegister(other), size_(-1), spill_offset_(-1) { }
91
92  explicit ManagedRegisterSpill(const ManagedRegister& other, int32_t size)
93      : ManagedRegister(other), size_(size), spill_offset_(-1) { }
94
95  int32_t getSpillOffset() {
96    return spill_offset_;
97  }
98
99  int32_t getSize() {
100    return size_;
101  }
102
103 private:
104  int32_t size_;
105  int32_t spill_offset_;
106};
107
108class ManagedRegisterEntrySpills : public std::vector<ManagedRegisterSpill> {
109 public:
110  // The ManagedRegister does not have information about size and offset.
111  // In this case it's size and offset determined by BuildFrame (assembler)
112  void push_back(ManagedRegister __x) {
113    ManagedRegisterSpill spill(__x);
114    std::vector<ManagedRegisterSpill>::push_back(spill);
115  }
116
117  void push_back(ManagedRegister __x, int32_t __size) {
118    ManagedRegisterSpill spill(__x, __size);
119    std::vector<ManagedRegisterSpill>::push_back(spill);
120  }
121
122  void push_back(ManagedRegisterSpill __x) {
123    std::vector<ManagedRegisterSpill>::push_back(__x);
124  }
125 private:
126};
127
128}  // namespace art
129
130#endif  // ART_COMPILER_UTILS_MANAGED_REGISTER_H_
131