blob: 893daff719727f73cba6002af300535cc8c3747e [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Ian Rogersb033c752011-07-20 12:22:35 -070016
Ian Rogers166db042013-07-26 12:05:57 -070017#ifndef ART_COMPILER_UTILS_MANAGED_REGISTER_H_
18#define ART_COMPILER_UTILS_MANAGED_REGISTER_H_
Ian Rogersb033c752011-07-20 12:22:35 -070019
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070020#include <vector>
21
Ian Rogers2c8f6532011-09-02 17:16:34 -070022namespace art {
23
Ian Rogers2c8f6532011-09-02 17:16:34 -070024namespace arm {
25class ArmManagedRegister;
26}
Serban Constantinescued8dd492014-02-11 14:15:10 +000027namespace arm64 {
28class Arm64ManagedRegister;
29}
jeffhao7fbee072012-08-24 17:56:54 -070030namespace mips {
31class MipsManagedRegister;
32}
Andreas Gampe57b34292015-01-14 15:45:59 -080033namespace mips64 {
34class Mips64ManagedRegister;
35}
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070036
jeffhao7fbee072012-08-24 17:56:54 -070037namespace x86 {
38class X86ManagedRegister;
39}
Ian Rogers2c8f6532011-09-02 17:16:34 -070040
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070041namespace x86_64 {
42class X86_64ManagedRegister;
43}
44
Ian Rogers2c8f6532011-09-02 17:16:34 -070045class ManagedRegister {
46 public:
47 // ManagedRegister is a value class. There exists no method to change the
48 // internal state. We therefore allow a copy constructor and an
49 // assignment-operator.
50 ManagedRegister(const ManagedRegister& other) : id_(other.id_) { }
51
52 ManagedRegister& operator=(const ManagedRegister& other) {
53 id_ = other.id_;
54 return *this;
55 }
56
Ian Rogers2c8f6532011-09-02 17:16:34 -070057 arm::ArmManagedRegister AsArm() const;
Serban Constantinescued8dd492014-02-11 14:15:10 +000058 arm64::Arm64ManagedRegister AsArm64() const;
jeffhao7fbee072012-08-24 17:56:54 -070059 mips::MipsManagedRegister AsMips() const;
Andreas Gampe57b34292015-01-14 15:45:59 -080060 mips64::Mips64ManagedRegister AsMips64() const;
jeffhao7fbee072012-08-24 17:56:54 -070061 x86::X86ManagedRegister AsX86() const;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070062 x86_64::X86_64ManagedRegister AsX86_64() const;
Ian Rogers2c8f6532011-09-02 17:16:34 -070063
64 // It is valid to invoke Equals on and with a NoRegister.
65 bool Equals(const ManagedRegister& other) const {
66 return id_ == other.id_;
67 }
68
69 bool IsNoRegister() const {
70 return id_ == kNoRegister;
71 }
72
73 static ManagedRegister NoRegister() {
74 return ManagedRegister();
75 }
76
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010077 int RegId() const { return id_; }
78 explicit ManagedRegister(int reg_id) : id_(reg_id) { }
79
Ian Rogers2c8f6532011-09-02 17:16:34 -070080 protected:
81 static const int kNoRegister = -1;
82
83 ManagedRegister() : id_(kNoRegister) { }
Ian Rogers2c8f6532011-09-02 17:16:34 -070084
85 int id_;
86};
87
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070088class ManagedRegisterSpill : public ManagedRegister {
89 public:
90 // ManagedRegisterSpill contains information about data type size and location in caller frame
91 // These additional attributes could be defined by calling convention (EntrySpills)
92 ManagedRegisterSpill(const ManagedRegister& other, uint32_t size, uint32_t spill_offset)
93 : ManagedRegister(other), size_(size), spill_offset_(spill_offset) { }
94
95 explicit ManagedRegisterSpill(const ManagedRegister& other)
96 : ManagedRegister(other), size_(-1), spill_offset_(-1) { }
97
Roland Levillain3887c462015-08-12 18:15:42 +010098 ManagedRegisterSpill(const ManagedRegister& other, int32_t size)
Serban Constantinescu75b91132014-04-09 18:39:10 +010099 : ManagedRegister(other), size_(size), spill_offset_(-1) { }
100
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700101 int32_t getSpillOffset() {
102 return spill_offset_;
103 }
104
105 int32_t getSize() {
106 return size_;
107 }
108
109 private:
110 int32_t size_;
111 int32_t spill_offset_;
112};
113
114class ManagedRegisterEntrySpills : public std::vector<ManagedRegisterSpill> {
115 public:
116 // The ManagedRegister does not have information about size and offset.
117 // In this case it's size and offset determined by BuildFrame (assembler)
118 void push_back(ManagedRegister __x) {
119 ManagedRegisterSpill spill(__x);
120 std::vector<ManagedRegisterSpill>::push_back(spill);
121 }
122
Serban Constantinescu75b91132014-04-09 18:39:10 +0100123 void push_back(ManagedRegister __x, int32_t __size) {
124 ManagedRegisterSpill spill(__x, __size);
125 std::vector<ManagedRegisterSpill>::push_back(spill);
126 }
127
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700128 void push_back(ManagedRegisterSpill __x) {
129 std::vector<ManagedRegisterSpill>::push_back(__x);
130 }
131 private:
132};
133
Ian Rogers2c8f6532011-09-02 17:16:34 -0700134} // namespace art
Ian Rogersb033c752011-07-20 12:22:35 -0700135
Ian Rogers166db042013-07-26 12:05:57 -0700136#endif // ART_COMPILER_UTILS_MANAGED_REGISTER_H_