blob: 102acb3423d1f68afee58d7d5e23aee12b3de5e4 [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
Alexandre Rames8626b742015-11-25 16:28:08 +000020#include "code_generator.h"
Anton Kirilov74234da2017-01-13 14:42:47 +000021#include "instruction_simplifier_shared.h"
Andreas Gampe878d58c2015-01-15 23:24:00 -080022#include "locations.h"
23#include "nodes.h"
24#include "utils/arm64/assembler_arm64.h"
Scott Wakeling97c72b72016-06-24 16:19:36 +010025
Artem Serovaf4e42a2016-08-08 15:11:24 +010026// TODO(VIXL): Make VIXL compile with -Wshadow.
27#pragma GCC diagnostic push
28#pragma GCC diagnostic ignored "-Wshadow"
29#include "aarch64/disasm-aarch64.h"
30#include "aarch64/macro-assembler-aarch64.h"
31#include "aarch64/simulator-aarch64.h"
32#pragma GCC diagnostic pop
Andreas Gampe878d58c2015-01-15 23:24:00 -080033
34namespace art {
Anton Kirilov74234da2017-01-13 14:42:47 +000035
36using helpers::CanFitInShifterOperand;
37using helpers::HasShifterOperand;
38
Andreas Gampe878d58c2015-01-15 23:24:00 -080039namespace arm64 {
40namespace helpers {
41
Andreas Gampe878d58c2015-01-15 23:24:00 -080042// Convenience helpers to ease conversion to and from VIXL operands.
43static_assert((SP == 31) && (WSP == 31) && (XZR == 32) && (WZR == 32),
44 "Unexpected values for register codes.");
45
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010046inline int VIXLRegCodeFromART(int code) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080047 if (code == SP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010048 return vixl::aarch64::kSPRegInternalCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080049 }
50 if (code == XZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010051 return vixl::aarch64::kZeroRegCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080052 }
53 return code;
54}
55
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010056inline int ARTRegCodeFromVIXL(int code) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010057 if (code == vixl::aarch64::kSPRegInternalCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080058 return SP;
59 }
Scott Wakeling97c72b72016-06-24 16:19:36 +010060 if (code == vixl::aarch64::kZeroRegCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080061 return XZR;
62 }
63 return code;
64}
65
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010066inline vixl::aarch64::Register XRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010067 DCHECK(location.IsRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010068 return vixl::aarch64::Register::GetXRegFromCode(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080069}
70
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010071inline vixl::aarch64::Register WRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010072 DCHECK(location.IsRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010073 return vixl::aarch64::Register::GetWRegFromCode(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080074}
75
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010076inline vixl::aarch64::Register RegisterFrom(Location location, DataType::Type type) {
77 DCHECK(type != DataType::Type::kVoid && !DataType::IsFloatingPointType(type)) << type;
78 return type == DataType::Type::kInt64 ? XRegisterFrom(location) : WRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -080079}
80
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010081inline vixl::aarch64::Register OutputRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080082 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
83}
84
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010085inline vixl::aarch64::Register InputRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080086 return RegisterFrom(instr->GetLocations()->InAt(input_index),
87 instr->InputAt(input_index)->GetType());
88}
89
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010090inline vixl::aarch64::FPRegister DRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010091 DCHECK(location.IsFpuRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010092 return vixl::aarch64::FPRegister::GetDRegFromCode(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -080093}
94
Artem Serovd4bccf12017-04-03 18:47:32 +010095inline vixl::aarch64::FPRegister QRegisterFrom(Location location) {
96 DCHECK(location.IsFpuRegister()) << location;
97 return vixl::aarch64::FPRegister::GetQRegFromCode(location.reg());
98}
99
Artem Serovb31f91f2017-04-05 11:31:19 +0100100inline vixl::aarch64::FPRegister VRegisterFrom(Location location) {
101 DCHECK(location.IsFpuRegister()) << location;
102 return vixl::aarch64::FPRegister::GetVRegFromCode(location.reg());
103}
104
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100105inline vixl::aarch64::FPRegister SRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +0100106 DCHECK(location.IsFpuRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +0100107 return vixl::aarch64::FPRegister::GetSRegFromCode(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800108}
109
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100110inline vixl::aarch64::FPRegister FPRegisterFrom(Location location, DataType::Type type) {
111 DCHECK(DataType::IsFloatingPointType(type)) << type;
112 return type == DataType::Type::kFloat64 ? DRegisterFrom(location) : SRegisterFrom(location);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800113}
114
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100115inline vixl::aarch64::FPRegister OutputFPRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800116 return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType());
117}
118
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100119inline vixl::aarch64::FPRegister InputFPRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800120 return FPRegisterFrom(instr->GetLocations()->InAt(input_index),
121 instr->InputAt(input_index)->GetType());
122}
123
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100124inline vixl::aarch64::CPURegister CPURegisterFrom(Location location, DataType::Type type) {
125 return DataType::IsFloatingPointType(type)
Scott Wakeling97c72b72016-06-24 16:19:36 +0100126 ? vixl::aarch64::CPURegister(FPRegisterFrom(location, type))
127 : vixl::aarch64::CPURegister(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800128}
129
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100130inline vixl::aarch64::CPURegister OutputCPURegister(HInstruction* instr) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100131 return DataType::IsFloatingPointType(instr->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100132 ? static_cast<vixl::aarch64::CPURegister>(OutputFPRegister(instr))
133 : static_cast<vixl::aarch64::CPURegister>(OutputRegister(instr));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800134}
135
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100136inline vixl::aarch64::CPURegister InputCPURegisterAt(HInstruction* instr, int index) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100137 return DataType::IsFloatingPointType(instr->InputAt(index)->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100138 ? static_cast<vixl::aarch64::CPURegister>(InputFPRegisterAt(instr, index))
139 : static_cast<vixl::aarch64::CPURegister>(InputRegisterAt(instr, index));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800140}
141
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100142inline vixl::aarch64::CPURegister InputCPURegisterOrZeroRegAt(HInstruction* instr,
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100143 int index) {
144 HInstruction* input = instr->InputAt(index);
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100145 DataType::Type input_type = input->GetType();
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100146 if (input->IsConstant() && input->AsConstant()->IsZeroBitPattern()) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100147 return (DataType::Size(input_type) >= vixl::aarch64::kXRegSizeInBytes)
Scott Wakeling79db9972017-01-19 14:08:42 +0000148 ? vixl::aarch64::Register(vixl::aarch64::xzr)
149 : vixl::aarch64::Register(vixl::aarch64::wzr);
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100150 }
151 return InputCPURegisterAt(instr, index);
152}
153
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100154inline int64_t Int64ConstantFrom(Location location) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800155 HConstant* instr = location.GetConstant();
Nicolas Geoffrayde0eb6f2015-03-04 10:28:04 +0000156 if (instr->IsIntConstant()) {
157 return instr->AsIntConstant()->GetValue();
158 } else if (instr->IsNullConstant()) {
159 return 0;
160 } else {
Roland Levillain3a448e42016-04-01 18:37:46 +0100161 DCHECK(instr->IsLongConstant()) << instr->DebugName();
Nicolas Geoffrayde0eb6f2015-03-04 10:28:04 +0000162 return instr->AsLongConstant()->GetValue();
163 }
Andreas Gampe878d58c2015-01-15 23:24:00 -0800164}
165
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100166inline vixl::aarch64::Operand OperandFrom(Location location, DataType::Type type) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800167 if (location.IsRegister()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100168 return vixl::aarch64::Operand(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800169 } else {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100170 return vixl::aarch64::Operand(Int64ConstantFrom(location));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800171 }
172}
173
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100174inline vixl::aarch64::Operand InputOperandAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800175 return OperandFrom(instr->GetLocations()->InAt(input_index),
176 instr->InputAt(input_index)->GetType());
177}
178
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100179inline vixl::aarch64::MemOperand StackOperandFrom(Location location) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100180 return vixl::aarch64::MemOperand(vixl::aarch64::sp, location.GetStackIndex());
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 size_t offset = 0) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800185 // A heap reference must be 32bit, so fit in a W register.
186 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100187 return vixl::aarch64::MemOperand(base.X(), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800188}
189
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100190inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100191 const vixl::aarch64::Register& regoffset,
192 vixl::aarch64::Shift shift = vixl::aarch64::LSL,
193 unsigned shift_amount = 0) {
Alexandre Rames82000b02015-07-07 11:34:16 +0100194 // A heap reference must be 32bit, so fit in a W register.
195 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100196 return vixl::aarch64::MemOperand(base.X(), regoffset, shift, shift_amount);
Alexandre Rames82000b02015-07-07 11:34:16 +0100197}
198
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100199inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100200 Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800201 return HeapOperand(base, offset.SizeValue());
202}
203
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100204inline vixl::aarch64::MemOperand HeapOperandFrom(Location location, Offset offset) {
Vladimir Marko0ebe0d82017-09-21 22:50:39 +0100205 return HeapOperand(RegisterFrom(location, DataType::Type::kReference), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800206}
207
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100208inline Location LocationFrom(const vixl::aarch64::Register& reg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100209 return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.GetCode()));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800210}
211
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100212inline Location LocationFrom(const vixl::aarch64::FPRegister& fpreg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100213 return Location::FpuRegisterLocation(fpreg.GetCode());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800214}
215
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100216inline vixl::aarch64::Operand OperandFromMemOperand(
Scott Wakeling97c72b72016-06-24 16:19:36 +0100217 const vixl::aarch64::MemOperand& mem_op) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800218 if (mem_op.IsImmediateOffset()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100219 return vixl::aarch64::Operand(mem_op.GetOffset());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800220 } else {
221 DCHECK(mem_op.IsRegisterOffset());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100222 if (mem_op.GetExtend() != vixl::aarch64::NO_EXTEND) {
223 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
224 mem_op.GetExtend(),
225 mem_op.GetShiftAmount());
226 } else if (mem_op.GetShift() != vixl::aarch64::NO_SHIFT) {
227 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
228 mem_op.GetShift(),
229 mem_op.GetShiftAmount());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800230 } else {
231 LOG(FATAL) << "Should not reach here";
232 UNREACHABLE();
233 }
234 }
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
252 // For single uses we let VIXL handle the constant generation since it will
253 // use registers that are not managed by the register allocator (wip0, wip1).
Vladimir Marko46817b82016-03-29 12:21:58 +0100254 if (constant->GetUses().HasExactlyOneElement()) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000255 return true;
256 }
257
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000258 // Our code generator ensures shift distances are within an encodable range.
259 if (instr->IsRor()) {
260 return true;
261 }
262
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100263 if (instr->IsAnd() || instr->IsOr() || instr->IsXor()) {
264 // Uses logical operations.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100265 return vixl::aarch64::Assembler::IsImmLogical(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100266 } else if (instr->IsNeg()) {
267 // Uses mov -immediate.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100268 return vixl::aarch64::Assembler::IsImmMovn(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100269 } else {
270 DCHECK(instr->IsAdd() ||
Artem Serov328429f2016-07-06 16:23:04 +0100271 instr->IsIntermediateAddress() ||
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100272 instr->IsBoundsCheck() ||
273 instr->IsCompare() ||
274 instr->IsCondition() ||
Roland Levillain22c49222016-03-18 14:04:28 +0000275 instr->IsSub())
276 << instr->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000277 // Uses aliases of ADD/SUB instructions.
Alexandre Ramesb69fbfb2015-10-16 09:08:46 +0100278 // If `value` does not fit but `-value` does, VIXL will automatically use
279 // the 'opposite' instruction.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100280 return vixl::aarch64::Assembler::IsImmAddSub(value)
281 || vixl::aarch64::Assembler::IsImmAddSub(-value);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000282 }
283}
284
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100285inline Location ARM64EncodableConstantOrRegister(HInstruction* constant,
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000286 HInstruction* instr) {
287 if (constant->IsConstant()
Artem Serov8dfe7462017-06-01 14:28:48 +0100288 && Arm64CanEncodeConstantAsImmediate(constant->AsConstant(), instr)) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000289 return Location::ConstantLocation(constant->AsConstant());
290 }
291
292 return Location::RequiresRegister();
293}
294
Zheng Xuda403092015-04-24 17:35:39 +0800295// Check if registers in art register set have the same register code in vixl. If the register
296// codes are same, we can initialize vixl register list simply by the register masks. Currently,
297// only SP/WSP and ZXR/WZR codes are different between art and vixl.
298// Note: This function is only used for debug checks.
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100299inline bool ArtVixlRegCodeCoherentForRegSet(uint32_t art_core_registers,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100300 size_t num_core,
301 uint32_t art_fpu_registers,
302 size_t num_fpu) {
Zheng Xuda403092015-04-24 17:35:39 +0800303 // The register masks won't work if the number of register is larger than 32.
304 DCHECK_GE(sizeof(art_core_registers) * 8, num_core);
305 DCHECK_GE(sizeof(art_fpu_registers) * 8, num_fpu);
306 for (size_t art_reg_code = 0; art_reg_code < num_core; ++art_reg_code) {
307 if (RegisterSet::Contains(art_core_registers, art_reg_code)) {
308 if (art_reg_code != static_cast<size_t>(VIXLRegCodeFromART(art_reg_code))) {
309 return false;
310 }
311 }
312 }
313 // There is no register code translation for float registers.
314 return true;
315}
316
Anton Kirilov74234da2017-01-13 14:42:47 +0000317inline vixl::aarch64::Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000318 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000319 case HDataProcWithShifterOp::kASR: return vixl::aarch64::ASR;
320 case HDataProcWithShifterOp::kLSL: return vixl::aarch64::LSL;
321 case HDataProcWithShifterOp::kLSR: return vixl::aarch64::LSR;
Alexandre Rames8626b742015-11-25 16:28:08 +0000322 default:
323 LOG(FATAL) << "Unexpected op kind " << op_kind;
324 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100325 return vixl::aarch64::NO_SHIFT;
Alexandre Rames8626b742015-11-25 16:28:08 +0000326 }
327}
328
Anton Kirilov74234da2017-01-13 14:42:47 +0000329inline vixl::aarch64::Extend ExtendFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000330 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000331 case HDataProcWithShifterOp::kUXTB: return vixl::aarch64::UXTB;
332 case HDataProcWithShifterOp::kUXTH: return vixl::aarch64::UXTH;
333 case HDataProcWithShifterOp::kUXTW: return vixl::aarch64::UXTW;
334 case HDataProcWithShifterOp::kSXTB: return vixl::aarch64::SXTB;
335 case HDataProcWithShifterOp::kSXTH: return vixl::aarch64::SXTH;
336 case HDataProcWithShifterOp::kSXTW: return vixl::aarch64::SXTW;
Alexandre Rames8626b742015-11-25 16:28:08 +0000337 default:
338 LOG(FATAL) << "Unexpected op kind " << op_kind;
339 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100340 return vixl::aarch64::NO_EXTEND;
Alexandre Rames8626b742015-11-25 16:28:08 +0000341 }
342}
343
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100344inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000345 DCHECK(HasShifterOperand(instruction, kArm64));
Alexandre Rames8626b742015-11-25 16:28:08 +0000346 // Although the `neg` instruction is an alias of the `sub` instruction, `HNeg`
347 // does *not* support extension. This is because the `extended register` form
348 // of the `sub` instruction interprets the left register with code 31 as the
349 // stack pointer and not the zero register. (So does the `immediate` form.) In
350 // the other form `shifted register, the register with code 31 is interpreted
351 // as the zero register.
352 return instruction->IsAdd() || instruction->IsSub();
353}
354
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100355inline bool IsConstantZeroBitPattern(const HInstruction* instruction) {
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100356 return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern();
357}
358
Andreas Gampe878d58c2015-01-15 23:24:00 -0800359} // namespace helpers
360} // namespace arm64
361} // namespace art
362
363#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_