blob: 5129dafca15b1416a678460905d09b77d5fb901e [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
20// TODO(VIXL): Make VIXL compile with -Wshadow.
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wshadow"
23#include "aarch32/macro-assembler-aarch32.h"
24#pragma GCC diagnostic pop
25
26namespace art {
27namespace arm {
28namespace helpers {
29
30static_assert(vixl::aarch32::kSpCode == SP, "vixl::aarch32::kSpCode must equal ART's SP");
31
32inline dwarf::Reg DWARFReg(vixl::aarch32::Register reg) {
33 return dwarf::Reg::ArmCore(static_cast<int>(reg.GetCode()));
34}
35
36inline dwarf::Reg DWARFReg(vixl::aarch32::SRegister reg) {
37 return dwarf::Reg::ArmFp(static_cast<int>(reg.GetCode()));
38}
39
Scott Wakelinga7812ae2016-10-17 10:03:36 +010040inline vixl::aarch32::Register HighRegisterFrom(Location location) {
41 DCHECK(location.IsRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010042 return vixl::aarch32::Register(location.AsRegisterPairHigh<vixl::aarch32::Register>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010043}
44
45inline vixl::aarch32::DRegister HighDRegisterFrom(Location location) {
46 DCHECK(location.IsFpuRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010047 return vixl::aarch32::DRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::DRegister>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010048}
49
50inline vixl::aarch32::Register LowRegisterFrom(Location location) {
51 DCHECK(location.IsRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010052 return vixl::aarch32::Register(location.AsRegisterPairLow<vixl::aarch32::Register>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010053}
54
55inline vixl::aarch32::SRegister LowSRegisterFrom(Location location) {
56 DCHECK(location.IsFpuRegisterPair()) << location;
Artem Serovcfbe9132016-10-14 15:58:56 +010057 return vixl::aarch32::SRegister(location.AsFpuRegisterPairLow<vixl::aarch32::SRegister>());
Scott Wakelinga7812ae2016-10-17 10:03:36 +010058}
59
Scott Wakelingfe885462016-09-22 10:24:38 +010060inline vixl::aarch32::Register RegisterFrom(Location location) {
61 DCHECK(location.IsRegister()) << location;
62 return vixl::aarch32::Register(location.reg());
63}
64
65inline vixl::aarch32::Register RegisterFrom(Location location, Primitive::Type type) {
66 DCHECK(type != Primitive::kPrimVoid && !Primitive::IsFloatingPointType(type)) << type;
67 return RegisterFrom(location);
68}
69
70inline vixl::aarch32::DRegister DRegisterFrom(Location location) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +010071 DCHECK(location.IsFpuRegisterPair()) << location;
72 int reg_code = location.low();
73 DCHECK_EQ(reg_code % 2, 0) << reg_code;
74 return vixl::aarch32::DRegister(reg_code / 2);
Scott Wakelingfe885462016-09-22 10:24:38 +010075}
76
77inline vixl::aarch32::SRegister SRegisterFrom(Location location) {
78 DCHECK(location.IsFpuRegister()) << location;
79 return vixl::aarch32::SRegister(location.reg());
80}
81
82inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) {
83 Primitive::Type type = instr->GetType();
84 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
85 return SRegisterFrom(instr->GetLocations()->Out());
86}
87
88inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) {
89 Primitive::Type type = instr->GetType();
90 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
91 return DRegisterFrom(instr->GetLocations()->Out());
92}
93
Scott Wakelinga7812ae2016-10-17 10:03:36 +010094inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) {
95 Primitive::Type type = instr->GetType();
96 if (type == Primitive::kPrimFloat) {
97 return OutputSRegister(instr);
98 } else {
99 return OutputDRegister(instr);
100 }
101}
102
Scott Wakelingfe885462016-09-22 10:24:38 +0100103inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) {
104 Primitive::Type type = instr->InputAt(input_index)->GetType();
105 DCHECK_EQ(type, Primitive::kPrimFloat) << type;
106 return SRegisterFrom(instr->GetLocations()->InAt(input_index));
107}
108
109inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) {
110 Primitive::Type type = instr->InputAt(input_index)->GetType();
111 DCHECK_EQ(type, Primitive::kPrimDouble) << type;
112 return DRegisterFrom(instr->GetLocations()->InAt(input_index));
113}
114
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100115inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) {
116 Primitive::Type type = instr->InputAt(input_index)->GetType();
117 if (type == Primitive::kPrimFloat) {
118 return InputSRegisterAt(instr, input_index);
119 } else {
120 return InputDRegisterAt(instr, input_index);
121 }
122}
123
Scott Wakelingfe885462016-09-22 10:24:38 +0100124inline vixl::aarch32::Register OutputRegister(HInstruction* instr) {
125 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
126}
127
128inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) {
129 return RegisterFrom(instr->GetLocations()->InAt(input_index),
130 instr->InputAt(input_index)->GetType());
131}
132
Scott Wakelingc34dba72016-10-03 10:14:44 +0100133inline vixl::aarch32::Register InputRegister(HInstruction* instr) {
134 DCHECK_EQ(instr->InputCount(), 1u);
135 return InputRegisterAt(instr, 0);
136}
137
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100138inline int32_t Int32ConstantFrom(Location location) {
139 HConstant* instr = location.GetConstant();
140 if (instr->IsIntConstant()) {
141 return instr->AsIntConstant()->GetValue();
142 } else {
143 DCHECK(instr->IsNullConstant()) << instr->DebugName();
144 return 0;
145 }
146}
147
Scott Wakelingfe885462016-09-22 10:24:38 +0100148inline int64_t Int64ConstantFrom(Location location) {
149 HConstant* instr = location.GetConstant();
150 if (instr->IsIntConstant()) {
151 return instr->AsIntConstant()->GetValue();
152 } else if (instr->IsNullConstant()) {
153 return 0;
154 } else {
155 DCHECK(instr->IsLongConstant()) << instr->DebugName();
156 return instr->AsLongConstant()->GetValue();
157 }
158}
159
160inline vixl::aarch32::Operand OperandFrom(Location location, Primitive::Type type) {
161 if (location.IsRegister()) {
162 return vixl::aarch32::Operand(RegisterFrom(location, type));
163 } else {
164 return vixl::aarch32::Operand(Int64ConstantFrom(location));
165 }
166}
167
168inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) {
169 return OperandFrom(instr->GetLocations()->InAt(input_index),
170 instr->InputAt(input_index)->GetType());
171}
172
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100173inline Location LocationFrom(const vixl::aarch32::Register& reg) {
174 return Location::RegisterLocation(reg.GetCode());
175}
176
177inline Location LocationFrom(const vixl::aarch32::SRegister& reg) {
178 return Location::FpuRegisterLocation(reg.GetCode());
179}
180
181inline Location LocationFrom(const vixl::aarch32::Register& low,
182 const vixl::aarch32::Register& high) {
183 return Location::RegisterPairLocation(low.GetCode(), high.GetCode());
184}
185
186inline Location LocationFrom(const vixl::aarch32::SRegister& low,
187 const vixl::aarch32::SRegister& high) {
188 return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode());
189}
190
Scott Wakelingfe885462016-09-22 10:24:38 +0100191} // namespace helpers
192} // namespace arm
193} // namespace art
194
195#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_