blob: 5372b97247c8daef66883683bd5b8f0eb478465a [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
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100100inline vixl::aarch64::FPRegister SRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +0100101 DCHECK(location.IsFpuRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +0100102 return vixl::aarch64::FPRegister::GetSRegFromCode(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800103}
104
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100105inline vixl::aarch64::FPRegister FPRegisterFrom(Location location, Primitive::Type type) {
Roland Levillain3a448e42016-04-01 18:37:46 +0100106 DCHECK(Primitive::IsFloatingPointType(type)) << type;
Andreas Gampe878d58c2015-01-15 23:24:00 -0800107 return type == Primitive::kPrimDouble ? DRegisterFrom(location) : SRegisterFrom(location);
108}
109
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100110inline vixl::aarch64::FPRegister OutputFPRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800111 return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType());
112}
113
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100114inline vixl::aarch64::FPRegister InputFPRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800115 return FPRegisterFrom(instr->GetLocations()->InAt(input_index),
116 instr->InputAt(input_index)->GetType());
117}
118
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100119inline vixl::aarch64::CPURegister CPURegisterFrom(Location location, Primitive::Type type) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100120 return Primitive::IsFloatingPointType(type)
121 ? vixl::aarch64::CPURegister(FPRegisterFrom(location, type))
122 : vixl::aarch64::CPURegister(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800123}
124
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100125inline vixl::aarch64::CPURegister OutputCPURegister(HInstruction* instr) {
Alexandre Rames542361f2015-01-29 16:57:31 +0000126 return Primitive::IsFloatingPointType(instr->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100127 ? static_cast<vixl::aarch64::CPURegister>(OutputFPRegister(instr))
128 : static_cast<vixl::aarch64::CPURegister>(OutputRegister(instr));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800129}
130
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100131inline vixl::aarch64::CPURegister InputCPURegisterAt(HInstruction* instr, int index) {
Alexandre Rames542361f2015-01-29 16:57:31 +0000132 return Primitive::IsFloatingPointType(instr->InputAt(index)->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100133 ? static_cast<vixl::aarch64::CPURegister>(InputFPRegisterAt(instr, index))
134 : static_cast<vixl::aarch64::CPURegister>(InputRegisterAt(instr, index));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800135}
136
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100137inline vixl::aarch64::CPURegister InputCPURegisterOrZeroRegAt(HInstruction* instr,
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100138 int index) {
139 HInstruction* input = instr->InputAt(index);
140 Primitive::Type input_type = input->GetType();
141 if (input->IsConstant() && input->AsConstant()->IsZeroBitPattern()) {
142 return (Primitive::ComponentSize(input_type) >= vixl::aarch64::kXRegSizeInBytes)
Scott Wakeling79db9972017-01-19 14:08:42 +0000143 ? vixl::aarch64::Register(vixl::aarch64::xzr)
144 : vixl::aarch64::Register(vixl::aarch64::wzr);
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100145 }
146 return InputCPURegisterAt(instr, index);
147}
148
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100149inline int64_t Int64ConstantFrom(Location location) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800150 HConstant* instr = location.GetConstant();
Nicolas Geoffrayde0eb6f2015-03-04 10:28:04 +0000151 if (instr->IsIntConstant()) {
152 return instr->AsIntConstant()->GetValue();
153 } else if (instr->IsNullConstant()) {
154 return 0;
155 } else {
Roland Levillain3a448e42016-04-01 18:37:46 +0100156 DCHECK(instr->IsLongConstant()) << instr->DebugName();
Nicolas Geoffrayde0eb6f2015-03-04 10:28:04 +0000157 return instr->AsLongConstant()->GetValue();
158 }
Andreas Gampe878d58c2015-01-15 23:24:00 -0800159}
160
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100161inline vixl::aarch64::Operand OperandFrom(Location location, Primitive::Type type) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800162 if (location.IsRegister()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100163 return vixl::aarch64::Operand(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800164 } else {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100165 return vixl::aarch64::Operand(Int64ConstantFrom(location));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800166 }
167}
168
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100169inline vixl::aarch64::Operand InputOperandAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800170 return OperandFrom(instr->GetLocations()->InAt(input_index),
171 instr->InputAt(input_index)->GetType());
172}
173
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100174inline vixl::aarch64::MemOperand StackOperandFrom(Location location) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100175 return vixl::aarch64::MemOperand(vixl::aarch64::sp, location.GetStackIndex());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800176}
177
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100178inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100179 size_t offset = 0) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800180 // A heap reference must be 32bit, so fit in a W register.
181 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100182 return vixl::aarch64::MemOperand(base.X(), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800183}
184
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100185inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100186 const vixl::aarch64::Register& regoffset,
187 vixl::aarch64::Shift shift = vixl::aarch64::LSL,
188 unsigned shift_amount = 0) {
Alexandre Rames82000b02015-07-07 11:34:16 +0100189 // A heap reference must be 32bit, so fit in a W register.
190 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100191 return vixl::aarch64::MemOperand(base.X(), regoffset, shift, shift_amount);
Alexandre Rames82000b02015-07-07 11:34:16 +0100192}
193
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100194inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100195 Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800196 return HeapOperand(base, offset.SizeValue());
197}
198
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100199inline vixl::aarch64::MemOperand HeapOperandFrom(Location location, Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800200 return HeapOperand(RegisterFrom(location, Primitive::kPrimNot), offset);
201}
202
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100203inline Location LocationFrom(const vixl::aarch64::Register& reg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100204 return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.GetCode()));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800205}
206
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100207inline Location LocationFrom(const vixl::aarch64::FPRegister& fpreg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100208 return Location::FpuRegisterLocation(fpreg.GetCode());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800209}
210
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100211inline vixl::aarch64::Operand OperandFromMemOperand(
Scott Wakeling97c72b72016-06-24 16:19:36 +0100212 const vixl::aarch64::MemOperand& mem_op) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800213 if (mem_op.IsImmediateOffset()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100214 return vixl::aarch64::Operand(mem_op.GetOffset());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800215 } else {
216 DCHECK(mem_op.IsRegisterOffset());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100217 if (mem_op.GetExtend() != vixl::aarch64::NO_EXTEND) {
218 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
219 mem_op.GetExtend(),
220 mem_op.GetShiftAmount());
221 } else if (mem_op.GetShift() != vixl::aarch64::NO_SHIFT) {
222 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
223 mem_op.GetShift(),
224 mem_op.GetShiftAmount());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800225 } else {
226 LOG(FATAL) << "Should not reach here";
227 UNREACHABLE();
228 }
229 }
230}
231
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100232inline bool CanEncodeConstantAsImmediate(HConstant* constant, HInstruction* instr) {
Roland Levillain22c49222016-03-18 14:04:28 +0000233 DCHECK(constant->IsIntConstant() || constant->IsLongConstant() || constant->IsNullConstant())
234 << constant->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000235
236 // For single uses we let VIXL handle the constant generation since it will
237 // use registers that are not managed by the register allocator (wip0, wip1).
Vladimir Marko46817b82016-03-29 12:21:58 +0100238 if (constant->GetUses().HasExactlyOneElement()) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000239 return true;
240 }
241
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000242 // Our code generator ensures shift distances are within an encodable range.
243 if (instr->IsRor()) {
244 return true;
245 }
246
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000247 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
248
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100249 if (instr->IsAnd() || instr->IsOr() || instr->IsXor()) {
250 // Uses logical operations.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100251 return vixl::aarch64::Assembler::IsImmLogical(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100252 } else if (instr->IsNeg()) {
253 // Uses mov -immediate.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100254 return vixl::aarch64::Assembler::IsImmMovn(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100255 } else {
256 DCHECK(instr->IsAdd() ||
Artem Serov328429f2016-07-06 16:23:04 +0100257 instr->IsIntermediateAddress() ||
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100258 instr->IsBoundsCheck() ||
259 instr->IsCompare() ||
260 instr->IsCondition() ||
Roland Levillain22c49222016-03-18 14:04:28 +0000261 instr->IsSub())
262 << instr->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000263 // Uses aliases of ADD/SUB instructions.
Alexandre Ramesb69fbfb2015-10-16 09:08:46 +0100264 // If `value` does not fit but `-value` does, VIXL will automatically use
265 // the 'opposite' instruction.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100266 return vixl::aarch64::Assembler::IsImmAddSub(value)
267 || vixl::aarch64::Assembler::IsImmAddSub(-value);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000268 }
269}
270
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100271inline Location ARM64EncodableConstantOrRegister(HInstruction* constant,
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000272 HInstruction* instr) {
273 if (constant->IsConstant()
274 && CanEncodeConstantAsImmediate(constant->AsConstant(), instr)) {
275 return Location::ConstantLocation(constant->AsConstant());
276 }
277
278 return Location::RequiresRegister();
279}
280
Zheng Xuda403092015-04-24 17:35:39 +0800281// Check if registers in art register set have the same register code in vixl. If the register
282// codes are same, we can initialize vixl register list simply by the register masks. Currently,
283// only SP/WSP and ZXR/WZR codes are different between art and vixl.
284// Note: This function is only used for debug checks.
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100285inline bool ArtVixlRegCodeCoherentForRegSet(uint32_t art_core_registers,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100286 size_t num_core,
287 uint32_t art_fpu_registers,
288 size_t num_fpu) {
Zheng Xuda403092015-04-24 17:35:39 +0800289 // The register masks won't work if the number of register is larger than 32.
290 DCHECK_GE(sizeof(art_core_registers) * 8, num_core);
291 DCHECK_GE(sizeof(art_fpu_registers) * 8, num_fpu);
292 for (size_t art_reg_code = 0; art_reg_code < num_core; ++art_reg_code) {
293 if (RegisterSet::Contains(art_core_registers, art_reg_code)) {
294 if (art_reg_code != static_cast<size_t>(VIXLRegCodeFromART(art_reg_code))) {
295 return false;
296 }
297 }
298 }
299 // There is no register code translation for float registers.
300 return true;
301}
302
Anton Kirilov74234da2017-01-13 14:42:47 +0000303inline vixl::aarch64::Shift ShiftFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000304 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000305 case HDataProcWithShifterOp::kASR: return vixl::aarch64::ASR;
306 case HDataProcWithShifterOp::kLSL: return vixl::aarch64::LSL;
307 case HDataProcWithShifterOp::kLSR: return vixl::aarch64::LSR;
Alexandre Rames8626b742015-11-25 16:28:08 +0000308 default:
309 LOG(FATAL) << "Unexpected op kind " << op_kind;
310 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100311 return vixl::aarch64::NO_SHIFT;
Alexandre Rames8626b742015-11-25 16:28:08 +0000312 }
313}
314
Anton Kirilov74234da2017-01-13 14:42:47 +0000315inline vixl::aarch64::Extend ExtendFromOpKind(HDataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000316 switch (op_kind) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000317 case HDataProcWithShifterOp::kUXTB: return vixl::aarch64::UXTB;
318 case HDataProcWithShifterOp::kUXTH: return vixl::aarch64::UXTH;
319 case HDataProcWithShifterOp::kUXTW: return vixl::aarch64::UXTW;
320 case HDataProcWithShifterOp::kSXTB: return vixl::aarch64::SXTB;
321 case HDataProcWithShifterOp::kSXTH: return vixl::aarch64::SXTH;
322 case HDataProcWithShifterOp::kSXTW: return vixl::aarch64::SXTW;
Alexandre Rames8626b742015-11-25 16:28:08 +0000323 default:
324 LOG(FATAL) << "Unexpected op kind " << op_kind;
325 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100326 return vixl::aarch64::NO_EXTEND;
Alexandre Rames8626b742015-11-25 16:28:08 +0000327 }
328}
329
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100330inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
Anton Kirilov74234da2017-01-13 14:42:47 +0000331 DCHECK(HasShifterOperand(instruction, kArm64));
Alexandre Rames8626b742015-11-25 16:28:08 +0000332 // Although the `neg` instruction is an alias of the `sub` instruction, `HNeg`
333 // does *not* support extension. This is because the `extended register` form
334 // of the `sub` instruction interprets the left register with code 31 as the
335 // stack pointer and not the zero register. (So does the `immediate` form.) In
336 // the other form `shifted register, the register with code 31 is interpreted
337 // as the zero register.
338 return instruction->IsAdd() || instruction->IsSub();
339}
340
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100341inline bool IsConstantZeroBitPattern(const HInstruction* instruction) {
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100342 return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern();
343}
344
Andreas Gampe878d58c2015-01-15 23:24:00 -0800345} // namespace helpers
346} // namespace arm64
347} // namespace art
348
349#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_