1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #ifndef ART_COMPILER_OPTIMIZING_COMMON_ARM_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_COMPILER_OPTIMIZING_COMMON_ARM_H_
19*795d594fSAndroid Build Coastguard Worker
20*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
21*795d594fSAndroid Build Coastguard Worker #include "instruction_simplifier_shared.h"
22*795d594fSAndroid Build Coastguard Worker #include "locations.h"
23*795d594fSAndroid Build Coastguard Worker #include "nodes.h"
24*795d594fSAndroid Build Coastguard Worker #include "utils/arm/constants_arm.h"
25*795d594fSAndroid Build Coastguard Worker
26*795d594fSAndroid Build Coastguard Worker // TODO(VIXL): Make VIXL compile cleanly with -Wshadow, -Wdeprecated-declarations.
27*795d594fSAndroid Build Coastguard Worker #pragma GCC diagnostic push
28*795d594fSAndroid Build Coastguard Worker #pragma GCC diagnostic ignored "-Wshadow"
29*795d594fSAndroid Build Coastguard Worker #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
30*795d594fSAndroid Build Coastguard Worker #include "aarch32/macro-assembler-aarch32.h"
31*795d594fSAndroid Build Coastguard Worker #pragma GCC diagnostic pop
32*795d594fSAndroid Build Coastguard Worker
33*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
34*795d594fSAndroid Build Coastguard Worker
35*795d594fSAndroid Build Coastguard Worker using helpers::HasShifterOperand;
36*795d594fSAndroid Build Coastguard Worker
37*795d594fSAndroid Build Coastguard Worker namespace arm {
38*795d594fSAndroid Build Coastguard Worker namespace helpers {
39*795d594fSAndroid Build Coastguard Worker
40*795d594fSAndroid Build Coastguard Worker static_assert(vixl::aarch32::kSpCode == SP, "vixl::aarch32::kSpCode must equal ART's SP");
41*795d594fSAndroid Build Coastguard Worker
HighRegisterFrom(Location location)42*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Register HighRegisterFrom(Location location) {
43*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsRegisterPair()) << location;
44*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::Register(location.AsRegisterPairHigh<vixl::aarch32::Register>());
45*795d594fSAndroid Build Coastguard Worker }
46*795d594fSAndroid Build Coastguard Worker
HighDRegisterFrom(Location location)47*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::DRegister HighDRegisterFrom(Location location) {
48*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsFpuRegisterPair()) << location;
49*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::DRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::DRegister>());
50*795d594fSAndroid Build Coastguard Worker }
51*795d594fSAndroid Build Coastguard Worker
LowRegisterFrom(Location location)52*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Register LowRegisterFrom(Location location) {
53*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsRegisterPair()) << location;
54*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::Register(location.AsRegisterPairLow<vixl::aarch32::Register>());
55*795d594fSAndroid Build Coastguard Worker }
56*795d594fSAndroid Build Coastguard Worker
LowSRegisterFrom(Location location)57*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::SRegister LowSRegisterFrom(Location location) {
58*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsFpuRegisterPair()) << location;
59*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::SRegister(location.AsFpuRegisterPairLow<vixl::aarch32::SRegister>());
60*795d594fSAndroid Build Coastguard Worker }
61*795d594fSAndroid Build Coastguard Worker
HighSRegisterFrom(Location location)62*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::SRegister HighSRegisterFrom(Location location) {
63*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsFpuRegisterPair()) << location;
64*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::SRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::SRegister>());
65*795d594fSAndroid Build Coastguard Worker }
66*795d594fSAndroid Build Coastguard Worker
RegisterFrom(Location location)67*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Register RegisterFrom(Location location) {
68*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsRegister()) << location;
69*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::Register(location.reg());
70*795d594fSAndroid Build Coastguard Worker }
71*795d594fSAndroid Build Coastguard Worker
RegisterFrom(Location location,DataType::Type type)72*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Register RegisterFrom(Location location, DataType::Type type) {
73*795d594fSAndroid Build Coastguard Worker DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type;
74*795d594fSAndroid Build Coastguard Worker return RegisterFrom(location);
75*795d594fSAndroid Build Coastguard Worker }
76*795d594fSAndroid Build Coastguard Worker
DRegisterFrom(Location location)77*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::DRegister DRegisterFrom(Location location) {
78*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsFpuRegisterPair()) << location;
79*795d594fSAndroid Build Coastguard Worker int reg_code = location.low();
80*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(reg_code % 2, 0) << reg_code;
81*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::DRegister(reg_code / 2);
82*795d594fSAndroid Build Coastguard Worker }
83*795d594fSAndroid Build Coastguard Worker
SRegisterFrom(Location location)84*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::SRegister SRegisterFrom(Location location) {
85*795d594fSAndroid Build Coastguard Worker DCHECK(location.IsFpuRegister()) << location;
86*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::SRegister(location.reg());
87*795d594fSAndroid Build Coastguard Worker }
88*795d594fSAndroid Build Coastguard Worker
OutputSRegister(HInstruction * instr)89*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) {
90*795d594fSAndroid Build Coastguard Worker DataType::Type type = instr->GetType();
91*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(type, DataType::Type::kFloat32) << type;
92*795d594fSAndroid Build Coastguard Worker return SRegisterFrom(instr->GetLocations()->Out());
93*795d594fSAndroid Build Coastguard Worker }
94*795d594fSAndroid Build Coastguard Worker
OutputDRegister(HInstruction * instr)95*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) {
96*795d594fSAndroid Build Coastguard Worker DataType::Type type = instr->GetType();
97*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(type, DataType::Type::kFloat64) << type;
98*795d594fSAndroid Build Coastguard Worker return DRegisterFrom(instr->GetLocations()->Out());
99*795d594fSAndroid Build Coastguard Worker }
100*795d594fSAndroid Build Coastguard Worker
OutputVRegister(HInstruction * instr)101*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) {
102*795d594fSAndroid Build Coastguard Worker DataType::Type type = instr->GetType();
103*795d594fSAndroid Build Coastguard Worker if (type == DataType::Type::kFloat32) {
104*795d594fSAndroid Build Coastguard Worker return OutputSRegister(instr);
105*795d594fSAndroid Build Coastguard Worker } else {
106*795d594fSAndroid Build Coastguard Worker return OutputDRegister(instr);
107*795d594fSAndroid Build Coastguard Worker }
108*795d594fSAndroid Build Coastguard Worker }
109*795d594fSAndroid Build Coastguard Worker
InputSRegisterAt(HInstruction * instr,int input_index)110*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) {
111*795d594fSAndroid Build Coastguard Worker DataType::Type type = instr->InputAt(input_index)->GetType();
112*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(type, DataType::Type::kFloat32) << type;
113*795d594fSAndroid Build Coastguard Worker return SRegisterFrom(instr->GetLocations()->InAt(input_index));
114*795d594fSAndroid Build Coastguard Worker }
115*795d594fSAndroid Build Coastguard Worker
InputDRegisterAt(HInstruction * instr,int input_index)116*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) {
117*795d594fSAndroid Build Coastguard Worker DataType::Type type = instr->InputAt(input_index)->GetType();
118*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(type, DataType::Type::kFloat64) << type;
119*795d594fSAndroid Build Coastguard Worker return DRegisterFrom(instr->GetLocations()->InAt(input_index));
120*795d594fSAndroid Build Coastguard Worker }
121*795d594fSAndroid Build Coastguard Worker
InputVRegisterAt(HInstruction * instr,int input_index)122*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) {
123*795d594fSAndroid Build Coastguard Worker DataType::Type type = instr->InputAt(input_index)->GetType();
124*795d594fSAndroid Build Coastguard Worker if (type == DataType::Type::kFloat32) {
125*795d594fSAndroid Build Coastguard Worker return InputSRegisterAt(instr, input_index);
126*795d594fSAndroid Build Coastguard Worker } else {
127*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(type, DataType::Type::kFloat64);
128*795d594fSAndroid Build Coastguard Worker return InputDRegisterAt(instr, input_index);
129*795d594fSAndroid Build Coastguard Worker }
130*795d594fSAndroid Build Coastguard Worker }
131*795d594fSAndroid Build Coastguard Worker
InputVRegister(HInstruction * instr)132*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::VRegister InputVRegister(HInstruction* instr) {
133*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(instr->InputCount(), 1u);
134*795d594fSAndroid Build Coastguard Worker return InputVRegisterAt(instr, 0);
135*795d594fSAndroid Build Coastguard Worker }
136*795d594fSAndroid Build Coastguard Worker
OutputRegister(HInstruction * instr)137*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Register OutputRegister(HInstruction* instr) {
138*795d594fSAndroid Build Coastguard Worker return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
139*795d594fSAndroid Build Coastguard Worker }
140*795d594fSAndroid Build Coastguard Worker
InputRegisterAt(HInstruction * instr,int input_index)141*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) {
142*795d594fSAndroid Build Coastguard Worker return RegisterFrom(instr->GetLocations()->InAt(input_index),
143*795d594fSAndroid Build Coastguard Worker instr->InputAt(input_index)->GetType());
144*795d594fSAndroid Build Coastguard Worker }
145*795d594fSAndroid Build Coastguard Worker
InputRegister(HInstruction * instr)146*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Register InputRegister(HInstruction* instr) {
147*795d594fSAndroid Build Coastguard Worker DCHECK_EQ(instr->InputCount(), 1u);
148*795d594fSAndroid Build Coastguard Worker return InputRegisterAt(instr, 0);
149*795d594fSAndroid Build Coastguard Worker }
150*795d594fSAndroid Build Coastguard Worker
DRegisterFromS(vixl::aarch32::SRegister s)151*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::DRegister DRegisterFromS(vixl::aarch32::SRegister s) {
152*795d594fSAndroid Build Coastguard Worker vixl::aarch32::DRegister d = vixl::aarch32::DRegister(s.GetCode() / 2);
153*795d594fSAndroid Build Coastguard Worker DCHECK(s.Is(d.GetLane(0)) || s.Is(d.GetLane(1)));
154*795d594fSAndroid Build Coastguard Worker return d;
155*795d594fSAndroid Build Coastguard Worker }
156*795d594fSAndroid Build Coastguard Worker
Int32ConstantFrom(HInstruction * instr)157*795d594fSAndroid Build Coastguard Worker inline int32_t Int32ConstantFrom(HInstruction* instr) {
158*795d594fSAndroid Build Coastguard Worker if (instr->IsIntConstant()) {
159*795d594fSAndroid Build Coastguard Worker return instr->AsIntConstant()->GetValue();
160*795d594fSAndroid Build Coastguard Worker } else if (instr->IsNullConstant()) {
161*795d594fSAndroid Build Coastguard Worker return 0;
162*795d594fSAndroid Build Coastguard Worker } else {
163*795d594fSAndroid Build Coastguard Worker DCHECK(instr->IsLongConstant()) << instr->DebugName();
164*795d594fSAndroid Build Coastguard Worker const int64_t ret = instr->AsLongConstant()->GetValue();
165*795d594fSAndroid Build Coastguard Worker DCHECK_GE(ret, std::numeric_limits<int32_t>::min());
166*795d594fSAndroid Build Coastguard Worker DCHECK_LE(ret, std::numeric_limits<int32_t>::max());
167*795d594fSAndroid Build Coastguard Worker return ret;
168*795d594fSAndroid Build Coastguard Worker }
169*795d594fSAndroid Build Coastguard Worker }
170*795d594fSAndroid Build Coastguard Worker
Int32ConstantFrom(Location location)171*795d594fSAndroid Build Coastguard Worker inline int32_t Int32ConstantFrom(Location location) {
172*795d594fSAndroid Build Coastguard Worker return Int32ConstantFrom(location.GetConstant());
173*795d594fSAndroid Build Coastguard Worker }
174*795d594fSAndroid Build Coastguard Worker
Int64ConstantFrom(Location location)175*795d594fSAndroid Build Coastguard Worker inline int64_t Int64ConstantFrom(Location location) {
176*795d594fSAndroid Build Coastguard Worker HConstant* instr = location.GetConstant();
177*795d594fSAndroid Build Coastguard Worker if (instr->IsIntConstant()) {
178*795d594fSAndroid Build Coastguard Worker return instr->AsIntConstant()->GetValue();
179*795d594fSAndroid Build Coastguard Worker } else if (instr->IsNullConstant()) {
180*795d594fSAndroid Build Coastguard Worker return 0;
181*795d594fSAndroid Build Coastguard Worker } else {
182*795d594fSAndroid Build Coastguard Worker DCHECK(instr->IsLongConstant()) << instr->DebugName();
183*795d594fSAndroid Build Coastguard Worker return instr->AsLongConstant()->GetValue();
184*795d594fSAndroid Build Coastguard Worker }
185*795d594fSAndroid Build Coastguard Worker }
186*795d594fSAndroid Build Coastguard Worker
Uint64ConstantFrom(HInstruction * instr)187*795d594fSAndroid Build Coastguard Worker inline uint64_t Uint64ConstantFrom(HInstruction* instr) {
188*795d594fSAndroid Build Coastguard Worker DCHECK(instr->IsConstant()) << instr->DebugName();
189*795d594fSAndroid Build Coastguard Worker return instr->AsConstant()->GetValueAsUint64();
190*795d594fSAndroid Build Coastguard Worker }
191*795d594fSAndroid Build Coastguard Worker
OperandFrom(Location location,DataType::Type type)192*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Operand OperandFrom(Location location, DataType::Type type) {
193*795d594fSAndroid Build Coastguard Worker if (location.IsRegister()) {
194*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::Operand(RegisterFrom(location, type));
195*795d594fSAndroid Build Coastguard Worker } else {
196*795d594fSAndroid Build Coastguard Worker return vixl::aarch32::Operand(Int32ConstantFrom(location));
197*795d594fSAndroid Build Coastguard Worker }
198*795d594fSAndroid Build Coastguard Worker }
199*795d594fSAndroid Build Coastguard Worker
InputOperandAt(HInstruction * instr,int input_index)200*795d594fSAndroid Build Coastguard Worker inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) {
201*795d594fSAndroid Build Coastguard Worker return OperandFrom(instr->GetLocations()->InAt(input_index),
202*795d594fSAndroid Build Coastguard Worker instr->InputAt(input_index)->GetType());
203*795d594fSAndroid Build Coastguard Worker }
204*795d594fSAndroid Build Coastguard Worker
LocationFrom(const vixl::aarch32::Register & reg)205*795d594fSAndroid Build Coastguard Worker inline Location LocationFrom(const vixl::aarch32::Register& reg) {
206*795d594fSAndroid Build Coastguard Worker return Location::RegisterLocation(reg.GetCode());
207*795d594fSAndroid Build Coastguard Worker }
208*795d594fSAndroid Build Coastguard Worker
LocationFrom(const vixl::aarch32::SRegister & reg)209*795d594fSAndroid Build Coastguard Worker inline Location LocationFrom(const vixl::aarch32::SRegister& reg) {
210*795d594fSAndroid Build Coastguard Worker return Location::FpuRegisterLocation(reg.GetCode());
211*795d594fSAndroid Build Coastguard Worker }
212*795d594fSAndroid Build Coastguard Worker
LocationFrom(const vixl::aarch32::Register & low,const vixl::aarch32::Register & high)213*795d594fSAndroid Build Coastguard Worker inline Location LocationFrom(const vixl::aarch32::Register& low,
214*795d594fSAndroid Build Coastguard Worker const vixl::aarch32::Register& high) {
215*795d594fSAndroid Build Coastguard Worker return Location::RegisterPairLocation(low.GetCode(), high.GetCode());
216*795d594fSAndroid Build Coastguard Worker }
217*795d594fSAndroid Build Coastguard Worker
LocationFrom(const vixl::aarch32::SRegister & low,const vixl::aarch32::SRegister & high)218*795d594fSAndroid Build Coastguard Worker inline Location LocationFrom(const vixl::aarch32::SRegister& low,
219*795d594fSAndroid Build Coastguard Worker const vixl::aarch32::SRegister& high) {
220*795d594fSAndroid Build Coastguard Worker return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode());
221*795d594fSAndroid Build Coastguard Worker }
222*795d594fSAndroid Build Coastguard Worker
223*795d594fSAndroid Build Coastguard Worker } // namespace helpers
224*795d594fSAndroid Build Coastguard Worker } // namespace arm
225*795d594fSAndroid Build Coastguard Worker } // namespace art
226*795d594fSAndroid Build Coastguard Worker
227*795d594fSAndroid Build Coastguard Worker #endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_
228