blob: 01304ac35b2589d718b2aad81d55733d5051fd32 [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
Anton Kirilov74234da2017-01-13 14:42:47 +000020#include "instruction_simplifier_shared.h"
Artem Serovd4cc5b22016-11-04 11:19:09 +000021#include "debug/dwarf/register.h"
22#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
32namespace art {
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
41inline dwarf::Reg DWARFReg(vixl::aarch32::Register reg) {
42 return dwarf::Reg::ArmCore(static_cast<int>(reg.GetCode()));
43}
44
45inline dwarf::Reg DWARFReg(vixl::aarch32::SRegister reg) {
46 return dwarf::Reg::ArmFp(static_cast<int>(reg.GetCode()));
47}
48
Scott Wakelinga7812ae2016-10-17 10:03:36 +010049inline vixl::aarch32::Register HighRegisterFrom(Location location) {
50 DCHECK(location.IsRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010051 return vixl::aarch32::Register(location.AsRegisterPairHigh<vixl::aarch32::Register>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010052}
53
54inline vixl::aarch32::DRegister HighDRegisterFrom(Location location) {
55 DCHECK(location.IsFpuRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010056 return vixl::aarch32::DRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::DRegister>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010057}
58
59inline vixl::aarch32::Register LowRegisterFrom(Location location) {
60 DCHECK(location.IsRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010061 return vixl::aarch32::Register(location.AsRegisterPairLow<vixl::aarch32::Register>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010062}
63
64inline vixl::aarch32::SRegister LowSRegisterFrom(Location location) {
65 DCHECK(location.IsFpuRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010066 return vixl::aarch32::SRegister(location.AsFpuRegisterPairLow<vixl::aarch32::SRegister>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010067}
68
xueliang.zhong53463ba2017-02-16 15:18:03 +000069inline vixl::aarch32::SRegister HighSRegisterFrom(Location location) {
70 DCHECK(location.IsFpuRegisterPair()) << location;
71 return vixl::aarch32::SRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::SRegister>());
72}
73
Scott Wakelingfe885462016-09-22 10:24:38 +010074inline vixl::aarch32::Register RegisterFrom(Location location) {
75 DCHECK(location.IsRegister()) << location;
76 return vixl::aarch32::Register(location.reg());
77}
78
79inline vixl::aarch32::Register RegisterFrom(Location location, Primitive::Type type) {
80 DCHECK(type != Primitive::kPrimVoid && !Primitive::IsFloatingPointType(type)) << type;
81 return RegisterFrom(location);
82}
83
84inline vixl::aarch32::DRegister DRegisterFrom(Location location) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +010085 DCHECK(location.IsFpuRegisterPair()) << location;
86 int reg_code = location.low();
87 DCHECK_EQ(reg_code % 2, 0) << reg_code;
88 return vixl::aarch32::DRegister(reg_code / 2);
Scott Wakelingfe885462016-09-22 10:24:38 +010089}
90
91inline vixl::aarch32::SRegister SRegisterFrom(Location location) {
92 DCHECK(location.IsFpuRegister()) << location;
93 return vixl::aarch32::SRegister(location.reg());
94}
95
96inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) {
97 Primitive::Type type = instr->GetType();
98 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
99 return SRegisterFrom(instr->GetLocations()->Out());
100}
101
102inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) {
103 Primitive::Type type = instr->GetType();
104 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
105 return DRegisterFrom(instr->GetLocations()->Out());
106}
107
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100108inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) {
109 Primitive::Type type = instr->GetType();
110 if (type == Primitive::kPrimFloat) {
111 return OutputSRegister(instr);
112 } else {
113 return OutputDRegister(instr);
114 }
115}
116
Scott Wakelingfe885462016-09-22 10:24:38 +0100117inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) {
118 Primitive::Type type = instr->InputAt(input_index)->GetType();
119 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
120 return SRegisterFrom(instr->GetLocations()->InAt(input_index));
121}
122
123inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) {
124 Primitive::Type type = instr->InputAt(input_index)->GetType();
125 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
126 return DRegisterFrom(instr->GetLocations()->InAt(input_index));
127}
128
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100129inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) {
130 Primitive::Type type = instr->InputAt(input_index)->GetType();
131 if (type == Primitive::kPrimFloat) {
132 return InputSRegisterAt(instr, input_index);
133 } else {
Anton Kirilov644032c2016-12-06 17:51:43 +0000134 DCHECK_EQ(type, Primitive::kPrimDouble);
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100135 return InputDRegisterAt(instr, input_index);
136 }
137}
138
Anton Kirilov644032c2016-12-06 17:51:43 +0000139inline vixl::aarch32::VRegister InputVRegister(HInstruction* instr) {
140 DCHECK_EQ(instr->InputCount(), 1u);
141 return InputVRegisterAt(instr, 0);
142}
143
Scott Wakelingfe885462016-09-22 10:24:38 +0100144inline vixl::aarch32::Register OutputRegister(HInstruction* instr) {
145 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
146}
147
148inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) {
149 return RegisterFrom(instr->GetLocations()->InAt(input_index),
150 instr->InputAt(input_index)->GetType());
151}
152
Scott Wakelingc34dba72016-10-03 10:14:44 +0100153inline vixl::aarch32::Register InputRegister(HInstruction* instr) {
154 DCHECK_EQ(instr->InputCount(), 1u);
155 return InputRegisterAt(instr, 0);
156}
157
xueliang.zhongc032e742016-03-28 16:44:32 +0100158inline vixl::aarch32::DRegister DRegisterFromS(vixl::aarch32::SRegister s) {
159 vixl::aarch32::DRegister d = vixl::aarch32::DRegister(s.GetCode() / 2);
160 DCHECK(s.Is(d.GetLane(0)) || s.Is(d.GetLane(1)));
161 return d;
162}
163
Anton Kirilov644032c2016-12-06 17:51:43 +0000164inline int32_t Int32ConstantFrom(HInstruction* instr) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100165 if (instr->IsIntConstant()) {
166 return instr->AsIntConstant()->GetValue();
Scott Wakelingb77051e2016-11-21 19:46:00 +0000167 } else if (instr->IsNullConstant()) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100168 return 0;
Scott Wakelingb77051e2016-11-21 19:46:00 +0000169 } else {
170 DCHECK(instr->IsLongConstant()) << instr->DebugName();
171 const int64_t ret = instr->AsLongConstant()->GetValue();
172 DCHECK_GE(ret, std::numeric_limits<int32_t>::min());
173 DCHECK_LE(ret, std::numeric_limits<int32_t>::max());
174 return ret;
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100175 }
176}
177
Anton Kirilov644032c2016-12-06 17:51:43 +0000178inline int32_t Int32ConstantFrom(Location location) {
179 return Int32ConstantFrom(location.GetConstant());
180}
181
Scott Wakelingfe885462016-09-22 10:24:38 +0100182inline int64_t Int64ConstantFrom(Location location) {
183 HConstant* instr = location.GetConstant();
184 if (instr->IsIntConstant()) {
185 return instr->AsIntConstant()->GetValue();
186 } else if (instr->IsNullConstant()) {
187 return 0;
188 } else {
189 DCHECK(instr->IsLongConstant()) << instr->DebugName();
190 return instr->AsLongConstant()->GetValue();
191 }
192}
193
Anton Kirilov644032c2016-12-06 17:51:43 +0000194inline uint64_t Uint64ConstantFrom(HInstruction* instr) {
195 DCHECK(instr->IsConstant()) << instr->DebugName();
196 return instr->AsConstant()->GetValueAsUint64();
197}
198
Scott Wakelingfe885462016-09-22 10:24:38 +0100199inline vixl::aarch32::Operand OperandFrom(Location location, Primitive::Type type) {
200 if (location.IsRegister()) {
201 return vixl::aarch32::Operand(RegisterFrom(location, type));
202 } else {
Scott Wakelingb77051e2016-11-21 19:46:00 +0000203 return vixl::aarch32::Operand(Int32ConstantFrom(location));
Scott Wakelingfe885462016-09-22 10:24:38 +0100204 }
205}
206
207inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) {
208 return OperandFrom(instr->GetLocations()->InAt(input_index),
209 instr->InputAt(input_index)->GetType());
210}
211
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100212inline Location LocationFrom(const vixl::aarch32::Register& reg) {
213 return Location::RegisterLocation(reg.GetCode());
214}
215
216inline Location LocationFrom(const vixl::aarch32::SRegister& reg) {
217 return Location::FpuRegisterLocation(reg.GetCode());
218}
219
220inline Location LocationFrom(const vixl::aarch32::Register& low,
221 const vixl::aarch32::Register& high) {
222 return Location::RegisterPairLocation(low.GetCode(), high.GetCode());
223}
224
225inline Location LocationFrom(const vixl::aarch32::SRegister& low,
226 const vixl::aarch32::SRegister& high) {
227 return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode());
228}
229
Anton Kirilov74234da2017-01-13 14:42:47 +0000230inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
231 DCHECK(HasShifterOperand(instruction, kArm));
232 // TODO: HAdd applied to the other integral types could make use of
233 // the SXTAB, SXTAH, UXTAB and UXTAH instructions.
234 return instruction->GetType() == Primitive::kPrimLong &&
235 (instruction->IsAdd() || instruction->IsSub());
236}
237
Scott Wakelingfe885462016-09-22 10:24:38 +0100238} // namespace helpers
239} // namespace arm
240} // namespace art
241
242#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_