blob: 5f71cb906c1cf4ec301d2a391d907f9ad7b70cf4 [file] [log] [blame]
Scott Wakelingfe885462016-09-22 10:24:38 +01001/*
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
Vladimír Marko434d9682022-11-04 14:04:17 +000020#include "base/macros.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070021#include "instruction_simplifier_shared.h"
Artem Serovd4cc5b22016-11-04 11:19:09 +000022#include "locations.h"
23#include "nodes.h"
24#include "utils/arm/constants_arm.h"
25
Scott Wakelingfe885462016-09-22 10:24:38 +010026// TODO(VIXL): Make VIXL compile with -Wshadow.
27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Wshadow"
29#include "aarch32/macro-assembler-aarch32.h"
30#pragma GCC diagnostic pop
31
Vladimír Marko434d9682022-11-04 14:04:17 +000032namespace art HIDDEN {
Anton Kirilov74234da2017-01-13 14:42:47 +000033
34using helpers::HasShifterOperand;
35
Scott Wakelingfe885462016-09-22 10:24:38 +010036namespace arm {
37namespace helpers {
38
39static_assert(vixl::aarch32::kSpCode == SP, "vixl::aarch32::kSpCode must equal ART's SP");
40
Scott Wakelinga7812ae2016-10-17 10:03:36 +010041inline vixl::aarch32::Register HighRegisterFrom(Location location) {
42 DCHECK(location.IsRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010043 return vixl::aarch32::Register(location.AsRegisterPairHigh<vixl::aarch32::Register>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010044}
45
46inline vixl::aarch32::DRegister HighDRegisterFrom(Location location) {
47 DCHECK(location.IsFpuRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010048 return vixl::aarch32::DRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::DRegister>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010049}
50
51inline vixl::aarch32::Register LowRegisterFrom(Location location) {
52 DCHECK(location.IsRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010053 return vixl::aarch32::Register(location.AsRegisterPairLow<vixl::aarch32::Register>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010054}
55
56inline vixl::aarch32::SRegister LowSRegisterFrom(Location location) {
57 DCHECK(location.IsFpuRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010058 return vixl::aarch32::SRegister(location.AsFpuRegisterPairLow<vixl::aarch32::SRegister>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010059}
60
xueliang.zhong53463ba2017-02-16 15:18:03 +000061inline vixl::aarch32::SRegister HighSRegisterFrom(Location location) {
62 DCHECK(location.IsFpuRegisterPair()) << location;
63 return vixl::aarch32::SRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::SRegister>());
64}
65
Scott Wakelingfe885462016-09-22 10:24:38 +010066inline vixl::aarch32::Register RegisterFrom(Location location) {
67 DCHECK(location.IsRegister()) << location;
68 return vixl::aarch32::Register(location.reg());
69}
70
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010071inline vixl::aarch32::Register RegisterFrom(Location location, DataType::Type type) {
72 DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +010073 return RegisterFrom(location);
74}
75
76inline vixl::aarch32::DRegister DRegisterFrom(Location location) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +010077 DCHECK(location.IsFpuRegisterPair()) << location;
78 int reg_code = location.low();
79 DCHECK_EQ(reg_code % 2, 0) << reg_code;
80 return vixl::aarch32::DRegister(reg_code / 2);
Scott Wakelingfe885462016-09-22 10:24:38 +010081}
82
83inline vixl::aarch32::SRegister SRegisterFrom(Location location) {
84 DCHECK(location.IsFpuRegister()) << location;
85 return vixl::aarch32::SRegister(location.reg());
86}
87
88inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010089 DataType::Type type = instr->GetType();
90 DCHECK_EQ(type, DataType::Type::kFloat32) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +010091 return SRegisterFrom(instr->GetLocations()->Out());
92}
93
94inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010095 DataType::Type type = instr->GetType();
96 DCHECK_EQ(type, DataType::Type::kFloat64) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +010097 return DRegisterFrom(instr->GetLocations()->Out());
98}
99
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100100inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100101 DataType::Type type = instr->GetType();
102 if (type == DataType::Type::kFloat32) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100103 return OutputSRegister(instr);
104 } else {
105 return OutputDRegister(instr);
106 }
107}
108
Scott Wakelingfe885462016-09-22 10:24:38 +0100109inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100110 DataType::Type type = instr->InputAt(input_index)->GetType();
111 DCHECK_EQ(type, DataType::Type::kFloat32) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +0100112 return SRegisterFrom(instr->GetLocations()->InAt(input_index));
113}
114
115inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100116 DataType::Type type = instr->InputAt(input_index)->GetType();
117 DCHECK_EQ(type, DataType::Type::kFloat64) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +0100118 return DRegisterFrom(instr->GetLocations()->InAt(input_index));
119}
120
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100121inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100122 DataType::Type type = instr->InputAt(input_index)->GetType();
123 if (type == DataType::Type::kFloat32) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100124 return InputSRegisterAt(instr, input_index);
125 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100126 DCHECK_EQ(type, DataType::Type::kFloat64);
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100127 return InputDRegisterAt(instr, input_index);
128 }
129}
130
Anton Kirilov644032c2016-12-06 17:51:43 +0000131inline vixl::aarch32::VRegister InputVRegister(HInstruction* instr) {
132 DCHECK_EQ(instr->InputCount(), 1u);
133 return InputVRegisterAt(instr, 0);
134}
135
Scott Wakelingfe885462016-09-22 10:24:38 +0100136inline vixl::aarch32::Register OutputRegister(HInstruction* instr) {
137 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
138}
139
140inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) {
141 return RegisterFrom(instr->GetLocations()->InAt(input_index),
142 instr->InputAt(input_index)->GetType());
143}
144
Scott Wakelingc34dba72016-10-03 10:14:44 +0100145inline vixl::aarch32::Register InputRegister(HInstruction* instr) {
146 DCHECK_EQ(instr->InputCount(), 1u);
147 return InputRegisterAt(instr, 0);
148}
149
xueliang.zhongc032e742016-03-28 16:44:32 +0100150inline vixl::aarch32::DRegister DRegisterFromS(vixl::aarch32::SRegister s) {
151 vixl::aarch32::DRegister d = vixl::aarch32::DRegister(s.GetCode() / 2);
152 DCHECK(s.Is(d.GetLane(0)) || s.Is(d.GetLane(1)));
153 return d;
154}
155
Anton Kirilov644032c2016-12-06 17:51:43 +0000156inline int32_t Int32ConstantFrom(HInstruction* instr) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100157 if (instr->IsIntConstant()) {
158 return instr->AsIntConstant()->GetValue();
Scott Wakelingb77051e2016-11-21 19:46:00 +0000159 } else if (instr->IsNullConstant()) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100160 return 0;
Scott Wakelingb77051e2016-11-21 19:46:00 +0000161 } else {
162 DCHECK(instr->IsLongConstant()) << instr->DebugName();
163 const int64_t ret = instr->AsLongConstant()->GetValue();
164 DCHECK_GE(ret, std::numeric_limits<int32_t>::min());
165 DCHECK_LE(ret, std::numeric_limits<int32_t>::max());
166 return ret;
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100167 }
168}
169
Anton Kirilov644032c2016-12-06 17:51:43 +0000170inline int32_t Int32ConstantFrom(Location location) {
171 return Int32ConstantFrom(location.GetConstant());
172}
173
Scott Wakelingfe885462016-09-22 10:24:38 +0100174inline int64_t Int64ConstantFrom(Location location) {
175 HConstant* instr = location.GetConstant();
176 if (instr->IsIntConstant()) {
177 return instr->AsIntConstant()->GetValue();
178 } else if (instr->IsNullConstant()) {
179 return 0;
180 } else {
181 DCHECK(instr->IsLongConstant()) << instr->DebugName();
182 return instr->AsLongConstant()->GetValue();
183 }
184}
185
Anton Kirilov644032c2016-12-06 17:51:43 +0000186inline uint64_t Uint64ConstantFrom(HInstruction* instr) {
187 DCHECK(instr->IsConstant()) << instr->DebugName();
188 return instr->AsConstant()->GetValueAsUint64();
189}
190
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100191inline vixl::aarch32::Operand OperandFrom(Location location, DataType::Type type) {
Scott Wakelingfe885462016-09-22 10:24:38 +0100192 if (location.IsRegister()) {
193 return vixl::aarch32::Operand(RegisterFrom(location, type));
194 } else {
Scott Wakelingb77051e2016-11-21 19:46:00 +0000195 return vixl::aarch32::Operand(Int32ConstantFrom(location));
Scott Wakelingfe885462016-09-22 10:24:38 +0100196 }
197}
198
199inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) {
200 return OperandFrom(instr->GetLocations()->InAt(input_index),
201 instr->InputAt(input_index)->GetType());
202}
203
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100204inline Location LocationFrom(const vixl::aarch32::Register& reg) {
205 return Location::RegisterLocation(reg.GetCode());
206}
207
208inline Location LocationFrom(const vixl::aarch32::SRegister& reg) {
209 return Location::FpuRegisterLocation(reg.GetCode());
210}
211
212inline Location LocationFrom(const vixl::aarch32::Register& low,
213 const vixl::aarch32::Register& high) {
214 return Location::RegisterPairLocation(low.GetCode(), high.GetCode());
215}
216
217inline Location LocationFrom(const vixl::aarch32::SRegister& low,
218 const vixl::aarch32::SRegister& high) {
219 return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode());
220}
221
Scott Wakelingfe885462016-09-22 10:24:38 +0100222} // namespace helpers
223} // namespace arm
224} // namespace art
225
226#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_