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 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 20 | #include "instruction_simplifier_shared.h" |
Artem Serov | d4cc5b2 | 2016-11-04 11:19:09 +0000 | [diff] [blame] | 21 | #include "locations.h" |
| 22 | #include "nodes.h" |
| 23 | #include "utils/arm/constants_arm.h" |
| 24 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 25 | // TODO(VIXL): Make VIXL compile with -Wshadow. |
| 26 | #pragma GCC diagnostic push |
| 27 | #pragma GCC diagnostic ignored "-Wshadow" |
| 28 | #include "aarch32/macro-assembler-aarch32.h" |
| 29 | #pragma GCC diagnostic pop |
| 30 | |
Vladimir Marko | 0a51605 | 2019-10-14 13:00:44 +0000 | [diff] [blame] | 31 | namespace art { |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 32 | |
| 33 | using helpers::HasShifterOperand; |
| 34 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 35 | namespace arm { |
| 36 | namespace helpers { |
| 37 | |
| 38 | static_assert(vixl::aarch32::kSpCode == SP, "vixl::aarch32::kSpCode must equal ART's SP"); |
| 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 | |
xueliang.zhong | 53463ba | 2017-02-16 15:18:03 +0000 | [diff] [blame] | 60 | inline vixl::aarch32::SRegister HighSRegisterFrom(Location location) { |
| 61 | DCHECK(location.IsFpuRegisterPair()) << location; |
| 62 | return vixl::aarch32::SRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::SRegister>()); |
| 63 | } |
| 64 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 65 | inline vixl::aarch32::Register RegisterFrom(Location location) { |
| 66 | DCHECK(location.IsRegister()) << location; |
| 67 | return vixl::aarch32::Register(location.reg()); |
| 68 | } |
| 69 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 70 | inline vixl::aarch32::Register RegisterFrom(Location location, DataType::Type type) { |
| 71 | DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 72 | return RegisterFrom(location); |
| 73 | } |
| 74 | |
| 75 | inline vixl::aarch32::DRegister DRegisterFrom(Location location) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 76 | DCHECK(location.IsFpuRegisterPair()) << location; |
| 77 | int reg_code = location.low(); |
| 78 | DCHECK_EQ(reg_code % 2, 0) << reg_code; |
| 79 | return vixl::aarch32::DRegister(reg_code / 2); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | inline vixl::aarch32::SRegister SRegisterFrom(Location location) { |
| 83 | DCHECK(location.IsFpuRegister()) << location; |
| 84 | return vixl::aarch32::SRegister(location.reg()); |
| 85 | } |
| 86 | |
| 87 | inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 88 | DataType::Type type = instr->GetType(); |
| 89 | DCHECK_EQ(type, DataType::Type::kFloat32) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 90 | return SRegisterFrom(instr->GetLocations()->Out()); |
| 91 | } |
| 92 | |
| 93 | inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 94 | DataType::Type type = instr->GetType(); |
| 95 | DCHECK_EQ(type, DataType::Type::kFloat64) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 96 | return DRegisterFrom(instr->GetLocations()->Out()); |
| 97 | } |
| 98 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 99 | inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 100 | DataType::Type type = instr->GetType(); |
| 101 | if (type == DataType::Type::kFloat32) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 102 | return OutputSRegister(instr); |
| 103 | } else { |
| 104 | return OutputDRegister(instr); |
| 105 | } |
| 106 | } |
| 107 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 108 | inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 109 | DataType::Type type = instr->InputAt(input_index)->GetType(); |
| 110 | DCHECK_EQ(type, DataType::Type::kFloat32) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 111 | return SRegisterFrom(instr->GetLocations()->InAt(input_index)); |
| 112 | } |
| 113 | |
| 114 | inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 115 | DataType::Type type = instr->InputAt(input_index)->GetType(); |
| 116 | DCHECK_EQ(type, DataType::Type::kFloat64) << type; |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 117 | return DRegisterFrom(instr->GetLocations()->InAt(input_index)); |
| 118 | } |
| 119 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 120 | inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 121 | DataType::Type type = instr->InputAt(input_index)->GetType(); |
| 122 | if (type == DataType::Type::kFloat32) { |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 123 | return InputSRegisterAt(instr, input_index); |
| 124 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 125 | DCHECK_EQ(type, DataType::Type::kFloat64); |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 126 | return InputDRegisterAt(instr, input_index); |
| 127 | } |
| 128 | } |
| 129 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 130 | inline vixl::aarch32::VRegister InputVRegister(HInstruction* instr) { |
| 131 | DCHECK_EQ(instr->InputCount(), 1u); |
| 132 | return InputVRegisterAt(instr, 0); |
| 133 | } |
| 134 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 135 | inline vixl::aarch32::Register OutputRegister(HInstruction* instr) { |
| 136 | return RegisterFrom(instr->GetLocations()->Out(), instr->GetType()); |
| 137 | } |
| 138 | |
| 139 | inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) { |
| 140 | return RegisterFrom(instr->GetLocations()->InAt(input_index), |
| 141 | instr->InputAt(input_index)->GetType()); |
| 142 | } |
| 143 | |
Scott Wakeling | c34dba7 | 2016-10-03 10:14:44 +0100 | [diff] [blame] | 144 | inline vixl::aarch32::Register InputRegister(HInstruction* instr) { |
| 145 | DCHECK_EQ(instr->InputCount(), 1u); |
| 146 | return InputRegisterAt(instr, 0); |
| 147 | } |
| 148 | |
xueliang.zhong | c032e74 | 2016-03-28 16:44:32 +0100 | [diff] [blame] | 149 | inline vixl::aarch32::DRegister DRegisterFromS(vixl::aarch32::SRegister s) { |
| 150 | vixl::aarch32::DRegister d = vixl::aarch32::DRegister(s.GetCode() / 2); |
| 151 | DCHECK(s.Is(d.GetLane(0)) || s.Is(d.GetLane(1))); |
| 152 | return d; |
| 153 | } |
| 154 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 155 | inline int32_t Int32ConstantFrom(HInstruction* instr) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 156 | if (instr->IsIntConstant()) { |
| 157 | return instr->AsIntConstant()->GetValue(); |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 158 | } else if (instr->IsNullConstant()) { |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 159 | return 0; |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 160 | } else { |
| 161 | DCHECK(instr->IsLongConstant()) << instr->DebugName(); |
| 162 | const int64_t ret = instr->AsLongConstant()->GetValue(); |
| 163 | DCHECK_GE(ret, std::numeric_limits<int32_t>::min()); |
| 164 | DCHECK_LE(ret, std::numeric_limits<int32_t>::max()); |
| 165 | return ret; |
Anton Kirilov | e28d9ae | 2016-10-25 18:17:23 +0100 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 169 | inline int32_t Int32ConstantFrom(Location location) { |
| 170 | return Int32ConstantFrom(location.GetConstant()); |
| 171 | } |
| 172 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 173 | inline int64_t Int64ConstantFrom(Location location) { |
| 174 | HConstant* instr = location.GetConstant(); |
| 175 | if (instr->IsIntConstant()) { |
| 176 | return instr->AsIntConstant()->GetValue(); |
| 177 | } else if (instr->IsNullConstant()) { |
| 178 | return 0; |
| 179 | } else { |
| 180 | DCHECK(instr->IsLongConstant()) << instr->DebugName(); |
| 181 | return instr->AsLongConstant()->GetValue(); |
| 182 | } |
| 183 | } |
| 184 | |
Anton Kirilov | 644032c | 2016-12-06 17:51:43 +0000 | [diff] [blame] | 185 | inline uint64_t Uint64ConstantFrom(HInstruction* instr) { |
| 186 | DCHECK(instr->IsConstant()) << instr->DebugName(); |
| 187 | return instr->AsConstant()->GetValueAsUint64(); |
| 188 | } |
| 189 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 190 | inline vixl::aarch32::Operand OperandFrom(Location location, DataType::Type type) { |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 191 | if (location.IsRegister()) { |
| 192 | return vixl::aarch32::Operand(RegisterFrom(location, type)); |
| 193 | } else { |
Scott Wakeling | b77051e | 2016-11-21 19:46:00 +0000 | [diff] [blame] | 194 | return vixl::aarch32::Operand(Int32ConstantFrom(location)); |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) { |
| 199 | return OperandFrom(instr->GetLocations()->InAt(input_index), |
| 200 | instr->InputAt(input_index)->GetType()); |
| 201 | } |
| 202 | |
Scott Wakeling | a7812ae | 2016-10-17 10:03:36 +0100 | [diff] [blame] | 203 | inline Location LocationFrom(const vixl::aarch32::Register& reg) { |
| 204 | return Location::RegisterLocation(reg.GetCode()); |
| 205 | } |
| 206 | |
| 207 | inline Location LocationFrom(const vixl::aarch32::SRegister& reg) { |
| 208 | return Location::FpuRegisterLocation(reg.GetCode()); |
| 209 | } |
| 210 | |
| 211 | inline Location LocationFrom(const vixl::aarch32::Register& low, |
| 212 | const vixl::aarch32::Register& high) { |
| 213 | return Location::RegisterPairLocation(low.GetCode(), high.GetCode()); |
| 214 | } |
| 215 | |
| 216 | inline Location LocationFrom(const vixl::aarch32::SRegister& low, |
| 217 | const vixl::aarch32::SRegister& high) { |
| 218 | return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode()); |
| 219 | } |
| 220 | |
Scott Wakeling | fe88546 | 2016-09-22 10:24:38 +0100 | [diff] [blame] | 221 | } // namespace helpers |
| 222 | } // namespace arm |
| 223 | } // namespace art |
| 224 | |
| 225 | #endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_ |