blob: 721f74eeee60bfbfb0b0529b780e64dc4f510dd9 [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
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010076inline vixl::aarch64::Register RegisterFrom(Location location, Primitive::Type type) {
Roland Levillain3a448e42016-04-01 18:37:46 +010077 DCHECK(type != Primitive::kPrimVoid && !Primitive::IsFloatingPointType(type)) << type;
Andreas Gampe878d58c2015-01-15 23:24:00 -080078 return type == Primitive::kPrimLong ? XRegisterFrom(location) : WRegisterFrom(location);
79}
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
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100110inline vixl::aarch64::FPRegister FPRegisterFrom(Location location, Primitive::Type type) {
Roland Levillain3a448e42016-04-01 18:37:46 +0100111 DCHECK(Primitive::IsFloatingPointType(type)) << type;
Andreas Gampe878d58c2015-01-15 23:24:00 -0800112 return type == Primitive::kPrimDouble ? DRegisterFrom(location) : SRegisterFrom(location);
113}
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
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100124inline vixl::aarch64::CPURegister CPURegisterFrom(Location location, Primitive::Type type) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100125 return Primitive::IsFloatingPointType(type)
126 ? 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) {
Alexandre Rames542361f2015-01-29 16:57:31 +0000131 return Primitive::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) {
Alexandre Rames542361f2015-01-29 16:57:31 +0000137 return Primitive::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);
145 Primitive::Type input_type = input->GetType();
146 if (input->IsConstant() && input->AsConstant()->IsZeroBitPattern()) {
147 return (Primitive::ComponentSize(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
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100166inline vixl::aarch64::Operand OperandFrom(Location location, Primitive::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) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800205 return HeapOperand(RegisterFrom(location, Primitive::kPrimNot), offset);
206}
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
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100237inline bool CanEncodeConstantAsImmediate(HConstant* constant, HInstruction* instr) {
Roland Levillain22c49222016-03-18 14:04:28 +0000238 DCHECK(constant->IsIntConstant() || constant->IsLongConstant() || constant->IsNullConstant())
239 << constant->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000240
241 // For single uses we let VIXL handle the constant generation since it will
242 // use registers that are not managed by the register allocator (wip0, wip1).
Vladimir Marko46817b82016-03-29 12:21:58 +0100243 if (constant->GetUses().HasExactlyOneElement()) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000244 return true;
245 }
246
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000247 // Our code generator ensures shift distances are within an encodable range.
248 if (instr->IsRor()) {
249 return true;
250 }
251
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000252 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
253
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100254 if (instr->IsAnd() || instr->IsOr() || instr->IsXor()) {
255 // Uses logical operations.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100256 return vixl::aarch64::Assembler::IsImmLogical(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100257 } else if (instr->IsNeg()) {
258 // Uses mov -immediate.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100259 return vixl::aarch64::Assembler::IsImmMovn(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100260 } else {
261 DCHECK(instr->IsAdd() ||
Artem Serov328429f2016-07-06 16:23:04 +0100262 instr->IsIntermediateAddress() ||
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100263 instr->IsBoundsCheck() ||
264 instr->IsCompare() ||
265 instr->IsCondition() ||
Roland Levillain22c49222016-03-18 14:04:28 +0000266 instr->IsSub())
267 << instr->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000268 // Uses aliases of ADD/SUB instructions.
Alexandre Ramesb69fbfb2015-10-16 09:08:46 +0100269 // If `value` does not fit but `-value` does, VIXL will automatically use
270 // the 'opposite' instruction.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100271 return vixl::aarch64::Assembler::IsImmAddSub(value)
272 || vixl::aarch64::Assembler::IsImmAddSub(-value);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000273 }
274}
275
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100276inline Location ARM64EncodableConstantOrRegister(HInstruction* constant,
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000277 HInstruction* instr) {
278 if (constant->IsConstant()
279 && CanEncodeConstantAsImmediate(constant->AsConstant(), instr)) {
280 return Location::ConstantLocation(constant->AsConstant());
281 }
282
283 return Location::RequiresRegister();
284}
285
Zheng Xuda403092015-04-24 17:35:39 +0800286// Check if registers in art register set have the same register code in vixl. If the register
287// codes are same, we can initialize vixl register list simply by the register masks. Currently,
288// only SP/WSP and ZXR/WZR codes are different between art and vixl.
289// Note: This function is only used for debug checks.
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100290inline bool ArtVixlRegCodeCoherentForRegSet(uint32_t art_core_registers,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100291 size_t num_core,
292 uint32_t art_fpu_registers,
293 size_t num_fpu) {
Zheng Xuda403092015-04-24 17:35:39 +0800294 // The register masks won't work if the number of register is larger than 32.
295 DCHECK_GE(sizeof(art_core_registers) * 8, num_core);
296 DCHECK_GE(sizeof(art_fpu_registers) * 8, num_fpu);
297 for (size_t art_reg_code = 0; art_reg_code < num_core; ++art_reg_code) {
298 if (RegisterSet::Contains(art_core_registers, art_reg_code)) {
299 if (art_reg_code != static_cast<size_t>(VIXLRegCodeFromART(art_reg_code))) {
300 return false;
301 }
302 }
303 }
304 // There is no register code translation for float registers.
305 return true;
306}
307
Anton Kirilov74234da2017-01-13 14:42:47 +0000308inline vixl::aarch64::Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000309 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000310 case HDataProcWithShifterOp::kASR: return vixl::aarch64::ASR;
311 case HDataProcWithShifterOp::kLSL: return vixl::aarch64::LSL;
312 case HDataProcWithShifterOp::kLSR: return vixl::aarch64::LSR;
Alexandre Rames8626b742015-11-25 16:28:08 +0000313 default:
314 LOG(FATAL) << "Unexpected op kind " << op_kind;
315 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100316 return vixl::aarch64::NO_SHIFT;
Alexandre Rames8626b742015-11-25 16:28:08 +0000317 }
318}
319
Anton Kirilov74234da2017-01-13 14:42:47 +0000320inline vixl::aarch64::Extend ExtendFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000321 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000322 case HDataProcWithShifterOp::kUXTB: return vixl::aarch64::UXTB;
323 case HDataProcWithShifterOp::kUXTH: return vixl::aarch64::UXTH;
324 case HDataProcWithShifterOp::kUXTW: return vixl::aarch64::UXTW;
325 case HDataProcWithShifterOp::kSXTB: return vixl::aarch64::SXTB;
326 case HDataProcWithShifterOp::kSXTH: return vixl::aarch64::SXTH;
327 case HDataProcWithShifterOp::kSXTW: return vixl::aarch64::SXTW;
Alexandre Rames8626b742015-11-25 16:28:08 +0000328 default:
329 LOG(FATAL) << "Unexpected op kind " << op_kind;
330 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100331 return vixl::aarch64::NO_EXTEND;
Alexandre Rames8626b742015-11-25 16:28:08 +0000332 }
333}
334
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100335inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000336 DCHECK(HasShifterOperand(instruction, kArm64));
Alexandre Rames8626b742015-11-25 16:28:08 +0000337 // Although the `neg` instruction is an alias of the `sub` instruction, `HNeg`
338 // does *not* support extension. This is because the `extended register` form
339 // of the `sub` instruction interprets the left register with code 31 as the
340 // stack pointer and not the zero register. (So does the `immediate` form.) In
341 // the other form `shifted register, the register with code 31 is interpreted
342 // as the zero register.
343 return instruction->IsAdd() || instruction->IsSub();
344}
345
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100346inline bool IsConstantZeroBitPattern(const HInstruction* instruction) {
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100347 return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern();
348}
349
Andreas Gampe878d58c2015-01-15 23:24:00 -0800350} // namespace helpers
351} // namespace arm64
352} // namespace art
353
354#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_