blob: e1847455206e47547c76ddbb071c152edecc045d [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
Scott Wakelingfe885462016-09-22 10:24:38 +010069inline vixl::aarch32::Register RegisterFrom(Location location) {
70 DCHECK(location.IsRegister()) << location;
71 return vixl::aarch32::Register(location.reg());
72}
73
74inline vixl::aarch32::Register RegisterFrom(Location location, Primitive::Type type) {
75 DCHECK(type != Primitive::kPrimVoid && !Primitive::IsFloatingPointType(type)) << type;
76 return RegisterFrom(location);
77}
78
79inline vixl::aarch32::DRegister DRegisterFrom(Location location) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +010080 DCHECK(location.IsFpuRegisterPair()) << location;
81 int reg_code = location.low();
82 DCHECK_EQ(reg_code % 2, 0) << reg_code;
83 return vixl::aarch32::DRegister(reg_code / 2);
Scott Wakelingfe885462016-09-22 10:24:38 +010084}
85
86inline vixl::aarch32::SRegister SRegisterFrom(Location location) {
87 DCHECK(location.IsFpuRegister()) << location;
88 return vixl::aarch32::SRegister(location.reg());
89}
90
91inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) {
92 Primitive::Type type = instr->GetType();
93 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
94 return SRegisterFrom(instr->GetLocations()->Out());
95}
96
97inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) {
98 Primitive::Type type = instr->GetType();
99 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
100 return DRegisterFrom(instr->GetLocations()->Out());
101}
102
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100103inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) {
104 Primitive::Type type = instr->GetType();
105 if (type == Primitive::kPrimFloat) {
106 return OutputSRegister(instr);
107 } else {
108 return OutputDRegister(instr);
109 }
110}
111
Scott Wakelingfe885462016-09-22 10:24:38 +0100112inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) {
113 Primitive::Type type = instr->InputAt(input_index)->GetType();
114 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
115 return SRegisterFrom(instr->GetLocations()->InAt(input_index));
116}
117
118inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) {
119 Primitive::Type type = instr->InputAt(input_index)->GetType();
120 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
121 return DRegisterFrom(instr->GetLocations()->InAt(input_index));
122}
123
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100124inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) {
125 Primitive::Type type = instr->InputAt(input_index)->GetType();
126 if (type == Primitive::kPrimFloat) {
127 return InputSRegisterAt(instr, input_index);
128 } else {
Anton Kirilov644032c2016-12-06 17:51:43 +0000129 DCHECK_EQ(type, Primitive::kPrimDouble);
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100130 return InputDRegisterAt(instr, input_index);
131 }
132}
133
Anton Kirilov644032c2016-12-06 17:51:43 +0000134inline vixl::aarch32::VRegister InputVRegister(HInstruction* instr) {
135 DCHECK_EQ(instr->InputCount(), 1u);
136 return InputVRegisterAt(instr, 0);
137}
138
Scott Wakelingfe885462016-09-22 10:24:38 +0100139inline vixl::aarch32::Register OutputRegister(HInstruction* instr) {
140 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
141}
142
143inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) {
144 return RegisterFrom(instr->GetLocations()->InAt(input_index),
145 instr->InputAt(input_index)->GetType());
146}
147
Scott Wakelingc34dba72016-10-03 10:14:44 +0100148inline vixl::aarch32::Register InputRegister(HInstruction* instr) {
149 DCHECK_EQ(instr->InputCount(), 1u);
150 return InputRegisterAt(instr, 0);
151}
152
xueliang.zhongc032e742016-03-28 16:44:32 +0100153inline vixl::aarch32::DRegister DRegisterFromS(vixl::aarch32::SRegister s) {
154 vixl::aarch32::DRegister d = vixl::aarch32::DRegister(s.GetCode() / 2);
155 DCHECK(s.Is(d.GetLane(0)) || s.Is(d.GetLane(1)));
156 return d;
157}
158
Anton Kirilov644032c2016-12-06 17:51:43 +0000159inline int32_t Int32ConstantFrom(HInstruction* instr) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100160 if (instr->IsIntConstant()) {
161 return instr->AsIntConstant()->GetValue();
Scott Wakelingb77051e2016-11-21 19:46:00 +0000162 } else if (instr->IsNullConstant()) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100163 return 0;
Scott Wakelingb77051e2016-11-21 19:46:00 +0000164 } else {
165 DCHECK(instr->IsLongConstant()) << instr->DebugName();
166 const int64_t ret = instr->AsLongConstant()->GetValue();
167 DCHECK_GE(ret, std::numeric_limits<int32_t>::min());
168 DCHECK_LE(ret, std::numeric_limits<int32_t>::max());
169 return ret;
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100170 }
171}
172
Anton Kirilov644032c2016-12-06 17:51:43 +0000173inline int32_t Int32ConstantFrom(Location location) {
174 return Int32ConstantFrom(location.GetConstant());
175}
176
Scott Wakelingfe885462016-09-22 10:24:38 +0100177inline int64_t Int64ConstantFrom(Location location) {
178 HConstant* instr = location.GetConstant();
179 if (instr->IsIntConstant()) {
180 return instr->AsIntConstant()->GetValue();
181 } else if (instr->IsNullConstant()) {
182 return 0;
183 } else {
184 DCHECK(instr->IsLongConstant()) << instr->DebugName();
185 return instr->AsLongConstant()->GetValue();
186 }
187}
188
Anton Kirilov644032c2016-12-06 17:51:43 +0000189inline uint64_t Uint64ConstantFrom(HInstruction* instr) {
190 DCHECK(instr->IsConstant()) << instr->DebugName();
191 return instr->AsConstant()->GetValueAsUint64();
192}
193
Scott Wakelingfe885462016-09-22 10:24:38 +0100194inline vixl::aarch32::Operand OperandFrom(Location location, Primitive::Type type) {
195 if (location.IsRegister()) {
196 return vixl::aarch32::Operand(RegisterFrom(location, type));
197 } else {
Scott Wakelingb77051e2016-11-21 19:46:00 +0000198 return vixl::aarch32::Operand(Int32ConstantFrom(location));
Scott Wakelingfe885462016-09-22 10:24:38 +0100199 }
200}
201
202inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) {
203 return OperandFrom(instr->GetLocations()->InAt(input_index),
204 instr->InputAt(input_index)->GetType());
205}
206
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100207inline Location LocationFrom(const vixl::aarch32::Register& reg) {
208 return Location::RegisterLocation(reg.GetCode());
209}
210
211inline Location LocationFrom(const vixl::aarch32::SRegister& reg) {
212 return Location::FpuRegisterLocation(reg.GetCode());
213}
214
215inline Location LocationFrom(const vixl::aarch32::Register& low,
216 const vixl::aarch32::Register& high) {
217 return Location::RegisterPairLocation(low.GetCode(), high.GetCode());
218}
219
220inline Location LocationFrom(const vixl::aarch32::SRegister& low,
221 const vixl::aarch32::SRegister& high) {
222 return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode());
223}
224
Anton Kirilov74234da2017-01-13 14:42:47 +0000225inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
226 DCHECK(HasShifterOperand(instruction, kArm));
227 // TODO: HAdd applied to the other integral types could make use of
228 // the SXTAB, SXTAH, UXTAB and UXTAH instructions.
229 return instruction->GetType() == Primitive::kPrimLong &&
230 (instruction->IsAdd() || instruction->IsSub());
231}
232
Scott Wakelingfe885462016-09-22 10:24:38 +0100233} // namespace helpers
234} // namespace arm
235} // namespace art
236
237#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_