Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_OPTIMIZING_COMMON_ARM_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_COMMON_ARM_H_ |
| 19 | |
| 20 | // TODO(VIXL): Make VIXL compile with -Wshadow. |
| 21 | #pragma GCC diagnostic push |
| 22 | #pragma GCC diagnostic ignored "-Wshadow" |
| 23 | #include "aarch32/macro-assembler-aarch32.h" |
| 24 | #pragma GCC diagnostic pop |
| 25 | |
| 26 | namespace art { |
| 27 | namespace arm { |
| 28 | namespace helpers { |
| 29 | |
| 30 | static_assert(vixl::aarch32::kSpCode == SP, "vixl::aarch32::kSpCode must equal ART's SP"); |
| 31 | |
| 32 | inline dwarf::Reg DWARFReg(vixl::aarch32::Register reg) { |
| 33 | return dwarf::Reg::ArmCore(static_cast<int>(reg.GetCode())); |
| 34 | } |
| 35 | |
| 36 | inline dwarf::Reg DWARFReg(vixl::aarch32::SRegister reg) { |
| 37 | return dwarf::Reg::ArmFp(static_cast<int>(reg.GetCode())); |
| 38 | } |
| 39 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 40 | inline vixl::aarch32::Register HighRegisterFrom(Location location) { |
| 41 | DCHECK(location.IsRegisterPair()) << location; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 42 | return vixl::aarch32::Register(location.AsRegisterPairHigh<vixl::aarch32::Register>()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | inline vixl::aarch32::DRegister HighDRegisterFrom(Location location) { |
| 46 | DCHECK(location.IsFpuRegisterPair()) << location; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 47 | return vixl::aarch32::DRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::DRegister>()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | inline vixl::aarch32::Register LowRegisterFrom(Location location) { |
| 51 | DCHECK(location.IsRegisterPair()) << location; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 52 | return vixl::aarch32::Register(location.AsRegisterPairLow<vixl::aarch32::Register>()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | inline vixl::aarch32::SRegister LowSRegisterFrom(Location location) { |
| 56 | DCHECK(location.IsFpuRegisterPair()) << location; |
Artem Serov | cfbe913 | 2016-10-14 15:58:56 +0100 | [diff] [blame] | 57 | return vixl::aarch32::SRegister(location.AsFpuRegisterPairLow<vixl::aarch32::SRegister>()); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 60 | inline vixl::aarch32::Register RegisterFrom(Location location) { |
| 61 | DCHECK(location.IsRegister()) << location; |
| 62 | return vixl::aarch32::Register(location.reg()); |
| 63 | } |
| 64 | |
| 65 | inline vixl::aarch32::Register RegisterFrom(Location location, Primitive::Type type) { |
| 66 | DCHECK(type != Primitive::kPrimVoid && !Primitive::IsFloatingPointType(type)) << type; |
| 67 | return RegisterFrom(location); |
| 68 | } |
| 69 | |
| 70 | inline vixl::aarch32::DRegister DRegisterFrom(Location location) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 71 | DCHECK(location.IsFpuRegisterPair()) << location; |
| 72 | int reg_code = location.low(); |
| 73 | DCHECK_EQ(reg_code % 2, 0) << reg_code; |
| 74 | return vixl::aarch32::DRegister(reg_code / 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | inline vixl::aarch32::SRegister SRegisterFrom(Location location) { |
| 78 | DCHECK(location.IsFpuRegister()) << location; |
| 79 | return vixl::aarch32::SRegister(location.reg()); |
| 80 | } |
| 81 | |
| 82 | inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) { |
| 83 | Primitive::Type type = instr->GetType(); |
| 84 | DCHECK_EQ(type, Primitive::kPrimFloat) << type; |
| 85 | return SRegisterFrom(instr->GetLocations()->Out()); |
| 86 | } |
| 87 | |
| 88 | inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) { |
| 89 | Primitive::Type type = instr->GetType(); |
| 90 | DCHECK_EQ(type, Primitive::kPrimDouble) << type; |
| 91 | return DRegisterFrom(instr->GetLocations()->Out()); |
| 92 | } |
| 93 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 94 | inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) { |
| 95 | Primitive::Type type = instr->GetType(); |
| 96 | if (type == Primitive::kPrimFloat) { |
| 97 | return OutputSRegister(instr); |
| 98 | } else { |
| 99 | return OutputDRegister(instr); |
| 100 | } |
| 101 | } |
| 102 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 103 | inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) { |
| 104 | Primitive::Type type = instr->InputAt(input_index)->GetType(); |
| 105 | DCHECK_EQ(type, Primitive::kPrimFloat) << type; |
| 106 | return SRegisterFrom(instr->GetLocations()->InAt(input_index)); |
| 107 | } |
| 108 | |
| 109 | inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) { |
| 110 | Primitive::Type type = instr->InputAt(input_index)->GetType(); |
| 111 | DCHECK_EQ(type, Primitive::kPrimDouble) << type; |
| 112 | return DRegisterFrom(instr->GetLocations()->InAt(input_index)); |
| 113 | } |
| 114 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 115 | inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) { |
| 116 | Primitive::Type type = instr->InputAt(input_index)->GetType(); |
| 117 | if (type == Primitive::kPrimFloat) { |
| 118 | return InputSRegisterAt(instr, input_index); |
| 119 | } else { |
| 120 | return InputDRegisterAt(instr, input_index); |
| 121 | } |
| 122 | } |
| 123 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 124 | inline vixl::aarch32::Register OutputRegister(HInstruction* instr) { |
| 125 | return RegisterFrom(instr->GetLocations()->Out(), instr->GetType()); |
| 126 | } |
| 127 | |
| 128 | inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) { |
| 129 | return RegisterFrom(instr->GetLocations()->InAt(input_index), |
| 130 | instr->InputAt(input_index)->GetType()); |
| 131 | } |
| 132 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 133 | inline vixl::aarch32::Register InputRegister(HInstruction* instr) { |
| 134 | DCHECK_EQ(instr->InputCount(), 1u); |
| 135 | return InputRegisterAt(instr, 0); |
| 136 | } |
| 137 | |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 138 | inline int32_t Int32ConstantFrom(Location location) { |
| 139 | HConstant* instr = location.GetConstant(); |
| 140 | if (instr->IsIntConstant()) { |
| 141 | return instr->AsIntConstant()->GetValue(); |
| 142 | } else { |
| 143 | DCHECK(instr->IsNullConstant()) << instr->DebugName(); |
| 144 | return 0; |
| 145 | } |
| 146 | } |
| 147 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 148 | inline int64_t Int64ConstantFrom(Location location) { |
| 149 | HConstant* instr = location.GetConstant(); |
| 150 | if (instr->IsIntConstant()) { |
| 151 | return instr->AsIntConstant()->GetValue(); |
| 152 | } else if (instr->IsNullConstant()) { |
| 153 | return 0; |
| 154 | } else { |
| 155 | DCHECK(instr->IsLongConstant()) << instr->DebugName(); |
| 156 | return instr->AsLongConstant()->GetValue(); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | inline vixl::aarch32::Operand OperandFrom(Location location, Primitive::Type type) { |
| 161 | if (location.IsRegister()) { |
| 162 | return vixl::aarch32::Operand(RegisterFrom(location, type)); |
| 163 | } else { |
| 164 | return vixl::aarch32::Operand(Int64ConstantFrom(location)); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) { |
| 169 | return OperandFrom(instr->GetLocations()->InAt(input_index), |
| 170 | instr->InputAt(input_index)->GetType()); |
| 171 | } |
| 172 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 173 | inline Location LocationFrom(const vixl::aarch32::Register& reg) { |
| 174 | return Location::RegisterLocation(reg.GetCode()); |
| 175 | } |
| 176 | |
| 177 | inline Location LocationFrom(const vixl::aarch32::SRegister& reg) { |
| 178 | return Location::FpuRegisterLocation(reg.GetCode()); |
| 179 | } |
| 180 | |
| 181 | inline Location LocationFrom(const vixl::aarch32::Register& low, |
| 182 | const vixl::aarch32::Register& high) { |
| 183 | return Location::RegisterPairLocation(low.GetCode(), high.GetCode()); |
| 184 | } |
| 185 | |
| 186 | inline Location LocationFrom(const vixl::aarch32::SRegister& low, |
| 187 | const vixl::aarch32::SRegister& high) { |
| 188 | return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode()); |
| 189 | } |
| 190 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 191 | } // namespace helpers |
| 192 | } // namespace arm |
| 193 | } // namespace art |
| 194 | |
| 195 | #endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_ |