blob: 320915ee57eee1ff81e2f9a18886652f2b1cb3a4 [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
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070020#include "instruction_simplifier_shared.h"
Artem Serovd4cc5b22016-11-04 11:19:09 +000021#include "locations.h"
22#include "nodes.h"
23#include "utils/arm/constants_arm.h"
24
Scott Wakelingfe885462016-09-22 10:24:38 +010025// TODO(VIXL): Make VIXL compile with -Wshadow.
26#pragma GCC diagnostic push
27#pragma GCC diagnostic ignored "-Wshadow"
28#include "aarch32/macro-assembler-aarch32.h"
29#pragma GCC diagnostic pop
30
Vladimir Marko0a516052019-10-14 13:00:44 +000031namespace art {
Anton Kirilov74234da2017-01-13 14:42:47 +000032
33using helpers::HasShifterOperand;
34
Scott Wakelingfe885462016-09-22 10:24:38 +010035namespace arm {
36namespace helpers {
37
38static_assert(vixl::aarch32::kSpCode == SP, "vixl::aarch32::kSpCode must equal ART's SP");
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
xueliang.zhong53463ba2017-02-16 15:18:03 +000060inline vixl::aarch32::SRegister HighSRegisterFrom(Location location) {
61 DCHECK(location.IsFpuRegisterPair()) << location;
62 return vixl::aarch32::SRegister(location.AsFpuRegisterPairHigh<vixl::aarch32::SRegister>());
63}
64
Scott Wakelingfe885462016-09-22 10:24:38 +010065inline vixl::aarch32::Register RegisterFrom(Location location) {
66 DCHECK(location.IsRegister()) << location;
67 return vixl::aarch32::Register(location.reg());
68}
69
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010070inline vixl::aarch32::Register RegisterFrom(Location location, DataType::Type type) {
71 DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +010072 return RegisterFrom(location);
73}
74
75inline vixl::aarch32::DRegister DRegisterFrom(Location location) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +010076 DCHECK(location.IsFpuRegisterPair()) << location;
77 int reg_code = location.low();
78 DCHECK_EQ(reg_code % 2, 0) << reg_code;
79 return vixl::aarch32::DRegister(reg_code / 2);
Scott Wakelingfe885462016-09-22 10:24:38 +010080}
81
82inline vixl::aarch32::SRegister SRegisterFrom(Location location) {
83 DCHECK(location.IsFpuRegister()) << location;
84 return vixl::aarch32::SRegister(location.reg());
85}
86
87inline vixl::aarch32::SRegister OutputSRegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010088 DataType::Type type = instr->GetType();
89 DCHECK_EQ(type, DataType::Type::kFloat32) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +010090 return SRegisterFrom(instr->GetLocations()->Out());
91}
92
93inline vixl::aarch32::DRegister OutputDRegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010094 DataType::Type type = instr->GetType();
95 DCHECK_EQ(type, DataType::Type::kFloat64) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +010096 return DRegisterFrom(instr->GetLocations()->Out());
97}
98
Scott Wakelinga7812ae2016-10-17 10:03:36 +010099inline vixl::aarch32::VRegister OutputVRegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100100 DataType::Type type = instr->GetType();
101 if (type == DataType::Type::kFloat32) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100102 return OutputSRegister(instr);
103 } else {
104 return OutputDRegister(instr);
105 }
106}
107
Scott Wakelingfe885462016-09-22 10:24:38 +0100108inline vixl::aarch32::SRegister InputSRegisterAt(HInstruction* instr, int input_index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100109 DataType::Type type = instr->InputAt(input_index)->GetType();
110 DCHECK_EQ(type, DataType::Type::kFloat32) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +0100111 return SRegisterFrom(instr->GetLocations()->InAt(input_index));
112}
113
114inline vixl::aarch32::DRegister InputDRegisterAt(HInstruction* instr, int input_index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100115 DataType::Type type = instr->InputAt(input_index)->GetType();
116 DCHECK_EQ(type, DataType::Type::kFloat64) << type;
Scott Wakelingfe885462016-09-22 10:24:38 +0100117 return DRegisterFrom(instr->GetLocations()->InAt(input_index));
118}
119
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100120inline vixl::aarch32::VRegister InputVRegisterAt(HInstruction* instr, int input_index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100121 DataType::Type type = instr->InputAt(input_index)->GetType();
122 if (type == DataType::Type::kFloat32) {
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100123 return InputSRegisterAt(instr, input_index);
124 } else {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100125 DCHECK_EQ(type, DataType::Type::kFloat64);
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100126 return InputDRegisterAt(instr, input_index);
127 }
128}
129
Anton Kirilov644032c2016-12-06 17:51:43 +0000130inline vixl::aarch32::VRegister InputVRegister(HInstruction* instr) {
131 DCHECK_EQ(instr->InputCount(), 1u);
132 return InputVRegisterAt(instr, 0);
133}
134
Scott Wakelingfe885462016-09-22 10:24:38 +0100135inline vixl::aarch32::Register OutputRegister(HInstruction* instr) {
136 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
137}
138
139inline vixl::aarch32::Register InputRegisterAt(HInstruction* instr, int input_index) {
140 return RegisterFrom(instr->GetLocations()->InAt(input_index),
141 instr->InputAt(input_index)->GetType());
142}
143
Scott Wakelingc34dba72016-10-03 10:14:44 +0100144inline vixl::aarch32::Register InputRegister(HInstruction* instr) {
145 DCHECK_EQ(instr->InputCount(), 1u);
146 return InputRegisterAt(instr, 0);
147}
148
xueliang.zhongc032e742016-03-28 16:44:32 +0100149inline vixl::aarch32::DRegister DRegisterFromS(vixl::aarch32::SRegister s) {
150 vixl::aarch32::DRegister d = vixl::aarch32::DRegister(s.GetCode() / 2);
151 DCHECK(s.Is(d.GetLane(0)) || s.Is(d.GetLane(1)));
152 return d;
153}
154
Anton Kirilov644032c2016-12-06 17:51:43 +0000155inline int32_t Int32ConstantFrom(HInstruction* instr) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100156 if (instr->IsIntConstant()) {
157 return instr->AsIntConstant()->GetValue();
Scott Wakelingb77051e2016-11-21 19:46:00 +0000158 } else if (instr->IsNullConstant()) {
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100159 return 0;
Scott Wakelingb77051e2016-11-21 19:46:00 +0000160 } else {
161 DCHECK(instr->IsLongConstant()) << instr->DebugName();
162 const int64_t ret = instr->AsLongConstant()->GetValue();
163 DCHECK_GE(ret, std::numeric_limits<int32_t>::min());
164 DCHECK_LE(ret, std::numeric_limits<int32_t>::max());
165 return ret;
Anton Kirilove28d9ae2016-10-25 18:17:23 +0100166 }
167}
168
Anton Kirilov644032c2016-12-06 17:51:43 +0000169inline int32_t Int32ConstantFrom(Location location) {
170 return Int32ConstantFrom(location.GetConstant());
171}
172
Scott Wakelingfe885462016-09-22 10:24:38 +0100173inline int64_t Int64ConstantFrom(Location location) {
174 HConstant* instr = location.GetConstant();
175 if (instr->IsIntConstant()) {
176 return instr->AsIntConstant()->GetValue();
177 } else if (instr->IsNullConstant()) {
178 return 0;
179 } else {
180 DCHECK(instr->IsLongConstant()) << instr->DebugName();
181 return instr->AsLongConstant()->GetValue();
182 }
183}
184
Anton Kirilov644032c2016-12-06 17:51:43 +0000185inline uint64_t Uint64ConstantFrom(HInstruction* instr) {
186 DCHECK(instr->IsConstant()) << instr->DebugName();
187 return instr->AsConstant()->GetValueAsUint64();
188}
189
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100190inline vixl::aarch32::Operand OperandFrom(Location location, DataType::Type type) {
Scott Wakelingfe885462016-09-22 10:24:38 +0100191 if (location.IsRegister()) {
192 return vixl::aarch32::Operand(RegisterFrom(location, type));
193 } else {
Scott Wakelingb77051e2016-11-21 19:46:00 +0000194 return vixl::aarch32::Operand(Int32ConstantFrom(location));
Scott Wakelingfe885462016-09-22 10:24:38 +0100195 }
196}
197
198inline vixl::aarch32::Operand InputOperandAt(HInstruction* instr, int input_index) {
199 return OperandFrom(instr->GetLocations()->InAt(input_index),
200 instr->InputAt(input_index)->GetType());
201}
202
Scott Wakelinga7812ae2016-10-17 10:03:36 +0100203inline Location LocationFrom(const vixl::aarch32::Register& reg) {
204 return Location::RegisterLocation(reg.GetCode());
205}
206
207inline Location LocationFrom(const vixl::aarch32::SRegister& reg) {
208 return Location::FpuRegisterLocation(reg.GetCode());
209}
210
211inline Location LocationFrom(const vixl::aarch32::Register& low,
212 const vixl::aarch32::Register& high) {
213 return Location::RegisterPairLocation(low.GetCode(), high.GetCode());
214}
215
216inline Location LocationFrom(const vixl::aarch32::SRegister& low,
217 const vixl::aarch32::SRegister& high) {
218 return Location::FpuRegisterPairLocation(low.GetCode(), high.GetCode());
219}
220
Scott Wakelingfe885462016-09-22 10:24:38 +0100221} // namespace helpers
222} // namespace arm
223} // namespace art
224
225#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM_H_