blob: e29353db9c436aa3c3ae23665bc768ca686db884 [file] [log] [blame]
Andreas Gampe878d58c2015-01-15 23:24:00 -08001/*
2 * Copyright (C) 2015 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_ARM64_H_
18#define ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_
19
Vladimir Markoe2727152019-10-10 10:46:42 +010020#include "base/macros.h"
Alexandre Rames8626b742015-11-25 16:28:08 +000021#include "code_generator.h"
Anton Kirilov74234da2017-01-13 14:42:47 +000022#include "instruction_simplifier_shared.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080023#include "locations.h"
24#include "nodes.h"
25#include "utils/arm64/assembler_arm64.h"
Scott Wakeling97c72b72016-06-24 16:19:36 +010026
Artem Serovaf4e42a2016-08-08 15:11:24 +010027// TODO(VIXL): Make VIXL compile with -Wshadow.
28#pragma GCC diagnostic push
29#pragma GCC diagnostic ignored "-Wshadow"
30#include "aarch64/disasm-aarch64.h"
31#include "aarch64/macro-assembler-aarch64.h"
32#include "aarch64/simulator-aarch64.h"
33#pragma GCC diagnostic pop
Andreas Gampe878d58c2015-01-15 23:24:00 -080034
Vladimir Markoe2727152019-10-10 10:46:42 +010035namespace art HIDDEN {
Anton Kirilov74234da2017-01-13 14:42:47 +000036
37using helpers::CanFitInShifterOperand;
38using helpers::HasShifterOperand;
39
Andreas Gampe878d58c2015-01-15 23:24:00 -080040namespace arm64 {
41namespace helpers {
42
Andreas Gampe878d58c2015-01-15 23:24:00 -080043// Convenience helpers to ease conversion to and from VIXL operands.
44static_assert((SP == 31) && (WSP == 31) && (XZR == 32) && (WZR == 32),
45 "Unexpected values for register codes.");
46
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010047inline int VIXLRegCodeFromART(int code) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080048 if (code == SP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010049 return vixl::aarch64::kSPRegInternalCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080050 }
51 if (code == XZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010052 return vixl::aarch64::kZeroRegCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080053 }
54 return code;
55}
56
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010057inline int ARTRegCodeFromVIXL(int code) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010058 if (code == vixl::aarch64::kSPRegInternalCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080059 return SP;
60 }
Scott Wakeling97c72b72016-06-24 16:19:36 +010061 if (code == vixl::aarch64::kZeroRegCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080062 return XZR;
63 }
64 return code;
65}
66
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010067inline vixl::aarch64::Register XRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010068 DCHECK(location.IsRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010069 return vixl::aarch64::Register::GetXRegFromCode(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080070}
71
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010072inline vixl::aarch64::Register WRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010073 DCHECK(location.IsRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010074 return vixl::aarch64::Register::GetWRegFromCode(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080075}
76
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010077inline vixl::aarch64::Register RegisterFrom(Location location, DataType::Type type) {
78 DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type;
79 return type == DataType::Type::kInt64 ? XRegisterFrom(location) : WRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -080080}
81
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010082inline vixl::aarch64::Register OutputRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080083 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
84}
85
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010086inline vixl::aarch64::Register InputRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080087 return RegisterFrom(instr->GetLocations()->InAt(input_index),
88 instr->InputAt(input_index)->GetType());
89}
90
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010091inline vixl::aarch64::FPRegister DRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010092 DCHECK(location.IsFpuRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010093 return vixl::aarch64::FPRegister::GetDRegFromCode(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -080094}
95
Artem Serovd4bccf12017-04-03 18:47:32 +010096inline vixl::aarch64::FPRegister QRegisterFrom(Location location) {
97 DCHECK(location.IsFpuRegister()) << location;
98 return vixl::aarch64::FPRegister::GetQRegFromCode(location.reg());
99}
100
Artem Serovb31f91f2017-04-05 11:31:19 +0100101inline vixl::aarch64::FPRegister VRegisterFrom(Location location) {
102 DCHECK(location.IsFpuRegister()) << location;
103 return vixl::aarch64::FPRegister::GetVRegFromCode(location.reg());
104}
105
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100106inline vixl::aarch64::FPRegister SRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +0100107 DCHECK(location.IsFpuRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +0100108 return vixl::aarch64::FPRegister::GetSRegFromCode(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800109}
110
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100111inline vixl::aarch64::FPRegister FPRegisterFrom(Location location, DataType::Type type) {
112 DCHECK(DataType::IsFloatingPointType(type)) << type;
113 return type == DataType::Type::kFloat64 ? DRegisterFrom(location) : SRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800114}
115
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100116inline vixl::aarch64::FPRegister OutputFPRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800117 return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType());
118}
119
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100120inline vixl::aarch64::FPRegister InputFPRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800121 return FPRegisterFrom(instr->GetLocations()->InAt(input_index),
122 instr->InputAt(input_index)->GetType());
123}
124
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100125inline vixl::aarch64::CPURegister CPURegisterFrom(Location location, DataType::Type type) {
126 return DataType::IsFloatingPointType(type)
Scott Wakeling97c72b72016-06-24 16:19:36 +0100127 ? vixl::aarch64::CPURegister(FPRegisterFrom(location, type))
128 : vixl::aarch64::CPURegister(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800129}
130
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100131inline vixl::aarch64::CPURegister OutputCPURegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100132 return DataType::IsFloatingPointType(instr->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100133 ? static_cast<vixl::aarch64::CPURegister>(OutputFPRegister(instr))
134 : static_cast<vixl::aarch64::CPURegister>(OutputRegister(instr));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800135}
136
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100137inline vixl::aarch64::CPURegister InputCPURegisterAt(HInstruction* instr, int index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100138 return DataType::IsFloatingPointType(instr->InputAt(index)->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100139 ? static_cast<vixl::aarch64::CPURegister>(InputFPRegisterAt(instr, index))
140 : static_cast<vixl::aarch64::CPURegister>(InputRegisterAt(instr, index));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800141}
142
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100143inline vixl::aarch64::CPURegister InputCPURegisterOrZeroRegAt(HInstruction* instr,
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100144 int index) {
145 HInstruction* input = instr->InputAt(index);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100146 DataType::Type input_type = input->GetType();
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100147 if (input->IsConstant() && input->AsConstant()->IsZeroBitPattern()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100148 return (DataType::Size(input_type) >= vixl::aarch64::kXRegSizeInBytes)
Scott Wakeling79db9972017-01-19 14:08:42 +0000149 ? vixl::aarch64::Register(vixl::aarch64::xzr)
150 : vixl::aarch64::Register(vixl::aarch64::wzr);
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100151 }
152 return InputCPURegisterAt(instr, index);
153}
154
Evgeny Astigeevichf9e90542018-06-25 13:43:53 +0100155inline int64_t Int64FromLocation(Location location) {
156 return Int64FromConstant(location.GetConstant());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800157}
158
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100159inline vixl::aarch64::Operand OperandFrom(Location location, DataType::Type type) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800160 if (location.IsRegister()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100161 return vixl::aarch64::Operand(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800162 } else {
Evgeny Astigeevichf9e90542018-06-25 13:43:53 +0100163 return vixl::aarch64::Operand(Int64FromLocation(location));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800164 }
165}
166
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100167inline vixl::aarch64::Operand InputOperandAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800168 return OperandFrom(instr->GetLocations()->InAt(input_index),
169 instr->InputAt(input_index)->GetType());
170}
171
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100172inline vixl::aarch64::MemOperand StackOperandFrom(Location location) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100173 return vixl::aarch64::MemOperand(vixl::aarch64::sp, location.GetStackIndex());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800174}
175
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100176inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100177 size_t offset = 0) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800178 // A heap reference must be 32bit, so fit in a W register.
179 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100180 return vixl::aarch64::MemOperand(base.X(), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800181}
182
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100183inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100184 const vixl::aarch64::Register& regoffset,
185 vixl::aarch64::Shift shift = vixl::aarch64::LSL,
186 unsigned shift_amount = 0) {
Alexandre Rames82000b02015-07-07 11:34:16 +0100187 // A heap reference must be 32bit, so fit in a W register.
188 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100189 return vixl::aarch64::MemOperand(base.X(), regoffset, shift, shift_amount);
Alexandre Rames82000b02015-07-07 11:34:16 +0100190}
191
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100192inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100193 Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800194 return HeapOperand(base, offset.SizeValue());
195}
196
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100197inline vixl::aarch64::MemOperand HeapOperandFrom(Location location, Offset offset) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100198 return HeapOperand(RegisterFrom(location, DataType::Type::kReference), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800199}
200
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100201inline Location LocationFrom(const vixl::aarch64::Register& reg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100202 return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.GetCode()));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800203}
204
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100205inline Location LocationFrom(const vixl::aarch64::FPRegister& fpreg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100206 return Location::FpuRegisterLocation(fpreg.GetCode());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800207}
208
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100209inline vixl::aarch64::Operand OperandFromMemOperand(
Scott Wakeling97c72b72016-06-24 16:19:36 +0100210 const vixl::aarch64::MemOperand& mem_op) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800211 if (mem_op.IsImmediateOffset()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100212 return vixl::aarch64::Operand(mem_op.GetOffset());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800213 } else {
214 DCHECK(mem_op.IsRegisterOffset());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100215 if (mem_op.GetExtend() != vixl::aarch64::NO_EXTEND) {
216 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
217 mem_op.GetExtend(),
218 mem_op.GetShiftAmount());
219 } else if (mem_op.GetShift() != vixl::aarch64::NO_SHIFT) {
220 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
221 mem_op.GetShift(),
222 mem_op.GetShiftAmount());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800223 } else {
224 LOG(FATAL) << "Should not reach here";
225 UNREACHABLE();
226 }
227 }
228}
229
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100230inline bool AddSubCanEncodeAsImmediate(int64_t value) {
231 // If `value` does not fit but `-value` does, VIXL will automatically use
232 // the 'opposite' instruction.
233 return vixl::aarch64::Assembler::IsImmAddSub(value)
234 || vixl::aarch64::Assembler::IsImmAddSub(-value);
235}
236
Artem Serov8dfe7462017-06-01 14:28:48 +0100237inline bool Arm64CanEncodeConstantAsImmediate(HConstant* constant, HInstruction* instr) {
238 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
239
240 // TODO: Improve this when IsSIMDConstantEncodable method is implemented in VIXL.
241 if (instr->IsVecReplicateScalar()) {
242 if (constant->IsLongConstant()) {
243 return false;
244 } else if (constant->IsFloatConstant()) {
245 return vixl::aarch64::Assembler::IsImmFP32(constant->AsFloatConstant()->GetValue());
246 } else if (constant->IsDoubleConstant()) {
247 return vixl::aarch64::Assembler::IsImmFP64(constant->AsDoubleConstant()->GetValue());
248 }
249 return IsUint<8>(value);
250 }
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000251
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100252 // Code generation for Min/Max:
253 // Cmp left_op, right_op
254 // Csel dst, left_op, right_op, cond
255 if (instr->IsMin() || instr->IsMax()) {
256 if (constant->GetUses().HasExactlyOneElement()) {
257 // If value can be encoded as immediate for the Cmp, then let VIXL handle
258 // the constant generation for the Csel.
259 return AddSubCanEncodeAsImmediate(value);
260 }
261 // These values are encodable as immediates for Cmp and VIXL will use csinc and csinv
262 // with the zr register as right_op, hence no constant generation is required.
263 return constant->IsZeroBitPattern() || constant->IsOne() || constant->IsMinusOne();
264 }
265
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000266 // For single uses we let VIXL handle the constant generation since it will
267 // use registers that are not managed by the register allocator (wip0, wip1).
Vladimir Marko46817b82016-03-29 12:21:58 +0100268 if (constant->GetUses().HasExactlyOneElement()) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000269 return true;
270 }
271
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000272 // Our code generator ensures shift distances are within an encodable range.
273 if (instr->IsRor()) {
274 return true;
275 }
276
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100277 if (instr->IsAnd() || instr->IsOr() || instr->IsXor()) {
278 // Uses logical operations.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100279 return vixl::aarch64::Assembler::IsImmLogical(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100280 } else if (instr->IsNeg()) {
281 // Uses mov -immediate.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100282 return vixl::aarch64::Assembler::IsImmMovn(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100283 } else {
284 DCHECK(instr->IsAdd() ||
Artem Serov328429f2016-07-06 16:23:04 +0100285 instr->IsIntermediateAddress() ||
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100286 instr->IsBoundsCheck() ||
287 instr->IsCompare() ||
288 instr->IsCondition() ||
Roland Levillain22c49222016-03-18 14:04:28 +0000289 instr->IsSub())
290 << instr->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000291 // Uses aliases of ADD/SUB instructions.
Petre-Ionut Tudor2227fe42018-04-20 17:12:05 +0100292 return AddSubCanEncodeAsImmediate(value);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000293 }
294}
295
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100296inline Location ARM64EncodableConstantOrRegister(HInstruction* constant,
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000297 HInstruction* instr) {
298 if (constant->IsConstant()
Artem Serov8dfe7462017-06-01 14:28:48 +0100299 && Arm64CanEncodeConstantAsImmediate(constant->AsConstant(), instr)) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000300 return Location::ConstantLocation(constant->AsConstant());
301 }
302
303 return Location::RequiresRegister();
304}
305
Zheng Xuda403092015-04-24 17:35:39 +0800306// Check if registers in art register set have the same register code in vixl. If the register
307// codes are same, we can initialize vixl register list simply by the register masks. Currently,
308// only SP/WSP and ZXR/WZR codes are different between art and vixl.
309// Note: This function is only used for debug checks.
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100310inline bool ArtVixlRegCodeCoherentForRegSet(uint32_t art_core_registers,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100311 size_t num_core,
312 uint32_t art_fpu_registers,
313 size_t num_fpu) {
Zheng Xuda403092015-04-24 17:35:39 +0800314 // The register masks won't work if the number of register is larger than 32.
315 DCHECK_GE(sizeof(art_core_registers) * 8, num_core);
316 DCHECK_GE(sizeof(art_fpu_registers) * 8, num_fpu);
317 for (size_t art_reg_code = 0; art_reg_code < num_core; ++art_reg_code) {
318 if (RegisterSet::Contains(art_core_registers, art_reg_code)) {
319 if (art_reg_code != static_cast<size_t>(VIXLRegCodeFromART(art_reg_code))) {
320 return false;
321 }
322 }
323 }
324 // There is no register code translation for float registers.
325 return true;
326}
327
Anton Kirilov74234da2017-01-13 14:42:47 +0000328inline vixl::aarch64::Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000329 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000330 case HDataProcWithShifterOp::kASR: return vixl::aarch64::ASR;
331 case HDataProcWithShifterOp::kLSL: return vixl::aarch64::LSL;
332 case HDataProcWithShifterOp::kLSR: return vixl::aarch64::LSR;
Alexandre Rames8626b742015-11-25 16:28:08 +0000333 default:
334 LOG(FATAL) << "Unexpected op kind " << op_kind;
335 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100336 return vixl::aarch64::NO_SHIFT;
Alexandre Rames8626b742015-11-25 16:28:08 +0000337 }
338}
339
Anton Kirilov74234da2017-01-13 14:42:47 +0000340inline vixl::aarch64::Extend ExtendFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000341 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000342 case HDataProcWithShifterOp::kUXTB: return vixl::aarch64::UXTB;
343 case HDataProcWithShifterOp::kUXTH: return vixl::aarch64::UXTH;
344 case HDataProcWithShifterOp::kUXTW: return vixl::aarch64::UXTW;
345 case HDataProcWithShifterOp::kSXTB: return vixl::aarch64::SXTB;
346 case HDataProcWithShifterOp::kSXTH: return vixl::aarch64::SXTH;
347 case HDataProcWithShifterOp::kSXTW: return vixl::aarch64::SXTW;
Alexandre Rames8626b742015-11-25 16:28:08 +0000348 default:
349 LOG(FATAL) << "Unexpected op kind " << op_kind;
350 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100351 return vixl::aarch64::NO_EXTEND;
Alexandre Rames8626b742015-11-25 16:28:08 +0000352 }
353}
354
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100355inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
Vladimir Marko33bff252017-11-01 14:35:42 +0000356 DCHECK(HasShifterOperand(instruction, InstructionSet::kArm64));
Alexandre Rames8626b742015-11-25 16:28:08 +0000357 // Although the `neg` instruction is an alias of the `sub` instruction, `HNeg`
358 // does *not* support extension. This is because the `extended register` form
359 // of the `sub` instruction interprets the left register with code 31 as the
360 // stack pointer and not the zero register. (So does the `immediate` form.) In
361 // the other form `shifted register, the register with code 31 is interpreted
362 // as the zero register.
363 return instruction->IsAdd() || instruction->IsSub();
364}
365
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100366inline bool IsConstantZeroBitPattern(const HInstruction* instruction) {
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100367 return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern();
368}
369
Andreas Gampe878d58c2015-01-15 23:24:00 -0800370} // namespace helpers
371} // namespace arm64
372} // namespace art
373
374#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_