Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 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 | */ |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 16 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_UTILS_MANAGED_REGISTER_H_ |
| 18 | #define ART_COMPILER_UTILS_MANAGED_REGISTER_H_ |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 19 | |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 20 | #include <vector> |
| 21 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 22 | namespace art { |
| 23 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 24 | namespace arm { |
| 25 | class ArmManagedRegister; |
| 26 | } |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 27 | namespace arm64 { |
| 28 | class Arm64ManagedRegister; |
| 29 | } |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 30 | namespace mips { |
| 31 | class MipsManagedRegister; |
| 32 | } |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 33 | namespace mips64 { |
| 34 | class Mips64ManagedRegister; |
| 35 | } |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 36 | |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 37 | namespace x86 { |
| 38 | class X86ManagedRegister; |
| 39 | } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 40 | |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 41 | namespace x86_64 { |
| 42 | class X86_64ManagedRegister; |
| 43 | } |
| 44 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 45 | class 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 Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 57 | arm::ArmManagedRegister AsArm() const; |
Serban Constantinescu | ed8dd49 | 2014-02-11 14:15:10 +0000 | [diff] [blame] | 58 | arm64::Arm64ManagedRegister AsArm64() const; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 59 | mips::MipsManagedRegister AsMips() const; |
Andreas Gampe | 57b3429 | 2015-01-14 15:45:59 -0800 | [diff] [blame] | 60 | mips64::Mips64ManagedRegister AsMips64() const; |
jeffhao | 7fbee07 | 2012-08-24 17:56:54 -0700 | [diff] [blame] | 61 | x86::X86ManagedRegister AsX86() const; |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 62 | x86_64::X86_64ManagedRegister AsX86_64() const; |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 63 | |
| 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 Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 77 | int RegId() const { return id_; } |
| 78 | explicit ManagedRegister(int reg_id) : id_(reg_id) { } |
| 79 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 80 | protected: |
| 81 | static const int kNoRegister = -1; |
| 82 | |
| 83 | ManagedRegister() : id_(kNoRegister) { } |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 84 | |
| 85 | int id_; |
| 86 | }; |
| 87 | |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 88 | class 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 Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 98 | ManagedRegisterSpill(const ManagedRegister& other, int32_t size) |
Serban Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 99 | : ManagedRegister(other), size_(size), spill_offset_(-1) { } |
| 100 | |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 101 | 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 | |
| 114 | class 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 Constantinescu | 75b9113 | 2014-04-09 18:39:10 +0100 | [diff] [blame] | 123 | void push_back(ManagedRegister __x, int32_t __size) { |
| 124 | ManagedRegisterSpill spill(__x, __size); |
| 125 | std::vector<ManagedRegisterSpill>::push_back(spill); |
| 126 | } |
| 127 | |
Dmitry Petrochenko | fca8220 | 2014-03-21 11:21:37 +0700 | [diff] [blame] | 128 | void push_back(ManagedRegisterSpill __x) { |
| 129 | std::vector<ManagedRegisterSpill>::push_back(__x); |
| 130 | } |
| 131 | private: |
| 132 | }; |
| 133 | |
Ian Rogers | 2c8f653 | 2011-09-02 17:16:34 -0700 | [diff] [blame] | 134 | } // namespace art |
Ian Rogers | b033c75 | 2011-07-20 12:22:35 -0700 | [diff] [blame] | 135 | |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 136 | #endif // ART_COMPILER_UTILS_MANAGED_REGISTER_H_ |