blob: bfb2829a32dc6eb432a8d6f412a90ddd3a71bfdf [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}
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070033
jeffhao7fbee072012-08-24 17:56:54 -070034namespace x86 {
35class X86ManagedRegister;
36}
Ian Rogers2c8f6532011-09-02 17:16:34 -070037
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070038namespace x86_64 {
39class X86_64ManagedRegister;
40}
41
Ian Rogers2c8f6532011-09-02 17:16:34 -070042class 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
Ian Rogers2c8f6532011-09-02 17:16:34 -070054 arm::ArmManagedRegister AsArm() const;
Serban Constantinescued8dd492014-02-11 14:15:10 +000055 arm64::Arm64ManagedRegister AsArm64() const;
jeffhao7fbee072012-08-24 17:56:54 -070056 mips::MipsManagedRegister AsMips() const;
57 x86::X86ManagedRegister AsX86() const;
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070058 x86_64::X86_64ManagedRegister AsX86_64() const;
Ian Rogers2c8f6532011-09-02 17:16:34 -070059
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
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +010073 int RegId() const { return id_; }
74 explicit ManagedRegister(int reg_id) : id_(reg_id) { }
75
Ian Rogers2c8f6532011-09-02 17:16:34 -070076 protected:
77 static const int kNoRegister = -1;
78
79 ManagedRegister() : id_(kNoRegister) { }
Ian Rogers2c8f6532011-09-02 17:16:34 -070080
81 int id_;
82};
83
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070084class ManagedRegisterSpill : public ManagedRegister {
85 public:
86 // ManagedRegisterSpill contains information about data type size and location in caller frame
87 // These additional attributes could be defined by calling convention (EntrySpills)
88 ManagedRegisterSpill(const ManagedRegister& other, uint32_t size, uint32_t spill_offset)
89 : ManagedRegister(other), size_(size), spill_offset_(spill_offset) { }
90
91 explicit ManagedRegisterSpill(const ManagedRegister& other)
92 : ManagedRegister(other), size_(-1), spill_offset_(-1) { }
93
Serban Constantinescu75b91132014-04-09 18:39:10 +010094 explicit ManagedRegisterSpill(const ManagedRegister& other, int32_t size)
95 : ManagedRegister(other), size_(size), spill_offset_(-1) { }
96
Dmitry Petrochenkofca82202014-03-21 11:21:37 +070097 int32_t getSpillOffset() {
98 return spill_offset_;
99 }
100
101 int32_t getSize() {
102 return size_;
103 }
104
105 private:
106 int32_t size_;
107 int32_t spill_offset_;
108};
109
110class ManagedRegisterEntrySpills : public std::vector<ManagedRegisterSpill> {
111 public:
112 // The ManagedRegister does not have information about size and offset.
113 // In this case it's size and offset determined by BuildFrame (assembler)
114 void push_back(ManagedRegister __x) {
115 ManagedRegisterSpill spill(__x);
116 std::vector<ManagedRegisterSpill>::push_back(spill);
117 }
118
Serban Constantinescu75b91132014-04-09 18:39:10 +0100119 void push_back(ManagedRegister __x, int32_t __size) {
120 ManagedRegisterSpill spill(__x, __size);
121 std::vector<ManagedRegisterSpill>::push_back(spill);
122 }
123
Dmitry Petrochenkofca82202014-03-21 11:21:37 +0700124 void push_back(ManagedRegisterSpill __x) {
125 std::vector<ManagedRegisterSpill>::push_back(__x);
126 }
127 private:
128};
129
Ian Rogers2c8f6532011-09-02 17:16:34 -0700130} // namespace art
Ian Rogersb033c752011-07-20 12:22:35 -0700131
Ian Rogers166db042013-07-26 12:05:57 -0700132#endif // ART_COMPILER_UTILS_MANAGED_REGISTER_H_