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 #include "managed_register_arm.h"
18
19 #include "globals.h"
20
21 namespace art {
22 namespace arm {
23
24 // We need all registers for caching of locals.
25 // Register R9 .. R15 are reserved.
26 static const int kNumberOfAvailableCoreRegisters = (R8 - R0) + 1;
27 static const int kNumberOfAvailableSRegisters = kNumberOfSRegisters;
28 static const int kNumberOfAvailableDRegisters = kNumberOfDRegisters;
29 static const int kNumberOfAvailableOverlappingDRegisters =
30 kNumberOfOverlappingDRegisters;
31 static const int kNumberOfAvailableRegisterPairs = kNumberOfRegisterPairs;
32
33
34 // Returns true if this managed-register overlaps the other managed-register.
Overlaps(const ArmManagedRegister & other) const35 bool ArmManagedRegister::Overlaps(const ArmManagedRegister& other) const {
36 if (IsNoRegister() || other.IsNoRegister()) return false;
37 if (Equals(other)) return true;
38 if (IsRegisterPair()) {
39 Register low = AsRegisterPairLow();
40 Register high = AsRegisterPairHigh();
41 return ArmManagedRegister::FromCoreRegister(low).Overlaps(other) ||
42 ArmManagedRegister::FromCoreRegister(high).Overlaps(other);
43 }
44 if (IsOverlappingDRegister()) {
45 if (other.IsDRegister()) return Equals(other);
46 if (other.IsSRegister()) {
47 SRegister low = AsOverlappingDRegisterLow();
48 SRegister high = AsOverlappingDRegisterHigh();
49 SRegister other_sreg = other.AsSRegister();
50 return (low == other_sreg) || (high == other_sreg);
51 }
52 return false;
53 }
54 if (other.IsRegisterPair() || other.IsOverlappingDRegister()) {
55 return other.Overlaps(*this);
56 }
57 return false;
58 }
59
60
AllocIdLow() const61 int ArmManagedRegister::AllocIdLow() const {
62 CHECK(IsOverlappingDRegister() || IsRegisterPair());
63 const int r = RegId() - (kNumberOfCoreRegIds + kNumberOfSRegIds);
64 int low;
65 if (r < kNumberOfOverlappingDRegIds) {
66 CHECK(IsOverlappingDRegister());
67 low = (r * 2) + kNumberOfCoreRegIds; // Return a SRegister.
68 } else {
69 CHECK(IsRegisterPair());
70 low = (r - kNumberOfDRegIds) * 2; // Return a Register.
71 if (low > 6) {
72 // we didn't got a pair higher than R6_R7, must be the dalvik special case
73 low = 1;
74 }
75 }
76 return low;
77 }
78
79
AllocIdHigh() const80 int ArmManagedRegister::AllocIdHigh() const {
81 return AllocIdLow() + 1;
82 }
83
84
Print(std::ostream & os) const85 void ArmManagedRegister::Print(std::ostream& os) const {
86 if (!IsValidManagedRegister()) {
87 os << "No Register";
88 } else if (IsCoreRegister()) {
89 os << "Core: " << static_cast<int>(AsCoreRegister());
90 } else if (IsRegisterPair()) {
91 os << "Pair: " << static_cast<int>(AsRegisterPairLow()) << ", "
92 << static_cast<int>(AsRegisterPairHigh());
93 } else if (IsSRegister()) {
94 os << "SRegister: " << static_cast<int>(AsSRegister());
95 } else if (IsDRegister()) {
96 os << "DRegister: " << static_cast<int>(AsDRegister());
97 } else {
98 os << "??: " << RegId();
99 }
100 }
101
operator <<(std::ostream & os,const ArmManagedRegister & reg)102 std::ostream& operator<<(std::ostream& os, const ArmManagedRegister& reg) {
103 reg.Print(os);
104 return os;
105 }
106
operator <<(std::ostream & os,const RegisterPair & r)107 std::ostream& operator<<(std::ostream& os, const RegisterPair& r) {
108 os << ArmManagedRegister::FromRegisterPair(r);
109 return os;
110 }
111
112 } // namespace arm
113 } // namespace art
114