blob: 776a483d431da2af3bcb2577aa8fb6778af26840 [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"
Andreas Gampe878d58c2015-01-15 23:24:00 -080021#include "locations.h"
22#include "nodes.h"
23#include "utils/arm64/assembler_arm64.h"
Scott Wakeling97c72b72016-06-24 16:19:36 +010024
Artem Serovaf4e42a2016-08-08 15:11:24 +010025// TODO(VIXL): Make VIXL compile with -Wshadow.
26#pragma GCC diagnostic push
27#pragma GCC diagnostic ignored "-Wshadow"
28#include "aarch64/disasm-aarch64.h"
29#include "aarch64/macro-assembler-aarch64.h"
30#include "aarch64/simulator-aarch64.h"
31#pragma GCC diagnostic pop
Andreas Gampe878d58c2015-01-15 23:24:00 -080032
33namespace art {
34namespace arm64 {
35namespace helpers {
36
Andreas Gampe878d58c2015-01-15 23:24:00 -080037// Convenience helpers to ease conversion to and from VIXL operands.
38static_assert((SP == 31) && (WSP == 31) && (XZR == 32) && (WZR == 32),
39 "Unexpected values for register codes.");
40
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010041inline int VIXLRegCodeFromART(int code) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080042 if (code == SP) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010043 return vixl::aarch64::kSPRegInternalCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080044 }
45 if (code == XZR) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010046 return vixl::aarch64::kZeroRegCode;
Andreas Gampe878d58c2015-01-15 23:24:00 -080047 }
48 return code;
49}
50
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010051inline int ARTRegCodeFromVIXL(int code) {
Scott Wakeling97c72b72016-06-24 16:19:36 +010052 if (code == vixl::aarch64::kSPRegInternalCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080053 return SP;
54 }
Scott Wakeling97c72b72016-06-24 16:19:36 +010055 if (code == vixl::aarch64::kZeroRegCode) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080056 return XZR;
57 }
58 return code;
59}
60
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010061inline vixl::aarch64::Register XRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010062 DCHECK(location.IsRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010063 return vixl::aarch64::Register::GetXRegFromCode(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080064}
65
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010066inline vixl::aarch64::Register WRegisterFrom(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::GetWRegFromCode(VIXLRegCodeFromART(location.reg()));
Andreas Gampe878d58c2015-01-15 23:24:00 -080069}
70
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010071inline vixl::aarch64::Register RegisterFrom(Location location, Primitive::Type type) {
Roland Levillain3a448e42016-04-01 18:37:46 +010072 DCHECK(type != Primitive::kPrimVoid && !Primitive::IsFloatingPointType(type)) << type;
Andreas Gampe878d58c2015-01-15 23:24:00 -080073 return type == Primitive::kPrimLong ? XRegisterFrom(location) : WRegisterFrom(location);
74}
75
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010076inline vixl::aarch64::Register OutputRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080077 return RegisterFrom(instr->GetLocations()->Out(), instr->GetType());
78}
79
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010080inline vixl::aarch64::Register InputRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -080081 return RegisterFrom(instr->GetLocations()->InAt(input_index),
82 instr->InputAt(input_index)->GetType());
83}
84
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010085inline vixl::aarch64::FPRegister DRegisterFrom(Location location) {
Roland Levillain3a448e42016-04-01 18:37:46 +010086 DCHECK(location.IsFpuRegister()) << location;
Scott Wakeling97c72b72016-06-24 16:19:36 +010087 return vixl::aarch64::FPRegister::GetDRegFromCode(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -080088}
89
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010090inline vixl::aarch64::FPRegister SRegisterFrom(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::GetSRegFromCode(location.reg());
Andreas Gampe878d58c2015-01-15 23:24:00 -080093}
94
Alexandre Ramesbadf2b22016-08-24 17:08:49 +010095inline vixl::aarch64::FPRegister FPRegisterFrom(Location location, Primitive::Type type) {
Roland Levillain3a448e42016-04-01 18:37:46 +010096 DCHECK(Primitive::IsFloatingPointType(type)) << type;
Andreas Gampe878d58c2015-01-15 23:24:00 -080097 return type == Primitive::kPrimDouble ? DRegisterFrom(location) : SRegisterFrom(location);
98}
99
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100100inline vixl::aarch64::FPRegister OutputFPRegister(HInstruction* instr) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800101 return FPRegisterFrom(instr->GetLocations()->Out(), instr->GetType());
102}
103
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100104inline vixl::aarch64::FPRegister InputFPRegisterAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800105 return FPRegisterFrom(instr->GetLocations()->InAt(input_index),
106 instr->InputAt(input_index)->GetType());
107}
108
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100109inline vixl::aarch64::CPURegister CPURegisterFrom(Location location, Primitive::Type type) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100110 return Primitive::IsFloatingPointType(type)
111 ? vixl::aarch64::CPURegister(FPRegisterFrom(location, type))
112 : vixl::aarch64::CPURegister(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800113}
114
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100115inline vixl::aarch64::CPURegister OutputCPURegister(HInstruction* instr) {
Alexandre Rames542361f2015-01-29 16:57:31 +0000116 return Primitive::IsFloatingPointType(instr->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100117 ? static_cast<vixl::aarch64::CPURegister>(OutputFPRegister(instr))
118 : static_cast<vixl::aarch64::CPURegister>(OutputRegister(instr));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800119}
120
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100121inline vixl::aarch64::CPURegister InputCPURegisterAt(HInstruction* instr, int index) {
Alexandre Rames542361f2015-01-29 16:57:31 +0000122 return Primitive::IsFloatingPointType(instr->InputAt(index)->GetType())
Scott Wakeling97c72b72016-06-24 16:19:36 +0100123 ? static_cast<vixl::aarch64::CPURegister>(InputFPRegisterAt(instr, index))
124 : static_cast<vixl::aarch64::CPURegister>(InputRegisterAt(instr, index));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800125}
126
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100127inline vixl::aarch64::CPURegister InputCPURegisterOrZeroRegAt(HInstruction* instr,
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100128 int index) {
129 HInstruction* input = instr->InputAt(index);
130 Primitive::Type input_type = input->GetType();
131 if (input->IsConstant() && input->AsConstant()->IsZeroBitPattern()) {
132 return (Primitive::ComponentSize(input_type) >= vixl::aarch64::kXRegSizeInBytes)
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100133 ? vixl::aarch64::xzr
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100134 : vixl::aarch64::wzr;
135 }
136 return InputCPURegisterAt(instr, index);
137}
138
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100139inline int64_t Int64ConstantFrom(Location location) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800140 HConstant* instr = location.GetConstant();
Nicolas Geoffrayde0eb6f2015-03-04 10:28:04 +0000141 if (instr->IsIntConstant()) {
142 return instr->AsIntConstant()->GetValue();
143 } else if (instr->IsNullConstant()) {
144 return 0;
145 } else {
Roland Levillain3a448e42016-04-01 18:37:46 +0100146 DCHECK(instr->IsLongConstant()) << instr->DebugName();
Nicolas Geoffrayde0eb6f2015-03-04 10:28:04 +0000147 return instr->AsLongConstant()->GetValue();
148 }
Andreas Gampe878d58c2015-01-15 23:24:00 -0800149}
150
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100151inline vixl::aarch64::Operand OperandFrom(Location location, Primitive::Type type) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800152 if (location.IsRegister()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100153 return vixl::aarch64::Operand(RegisterFrom(location, type));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800154 } else {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100155 return vixl::aarch64::Operand(Int64ConstantFrom(location));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800156 }
157}
158
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100159inline vixl::aarch64::Operand InputOperandAt(HInstruction* instr, int input_index) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800160 return OperandFrom(instr->GetLocations()->InAt(input_index),
161 instr->InputAt(input_index)->GetType());
162}
163
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100164inline vixl::aarch64::MemOperand StackOperandFrom(Location location) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100165 return vixl::aarch64::MemOperand(vixl::aarch64::sp, location.GetStackIndex());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800166}
167
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100168inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100169 size_t offset = 0) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800170 // A heap reference must be 32bit, so fit in a W register.
171 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100172 return vixl::aarch64::MemOperand(base.X(), offset);
Andreas Gampe878d58c2015-01-15 23:24:00 -0800173}
174
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100175inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100176 const vixl::aarch64::Register& regoffset,
177 vixl::aarch64::Shift shift = vixl::aarch64::LSL,
178 unsigned shift_amount = 0) {
Alexandre Rames82000b02015-07-07 11:34:16 +0100179 // A heap reference must be 32bit, so fit in a W register.
180 DCHECK(base.IsW());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100181 return vixl::aarch64::MemOperand(base.X(), regoffset, shift, shift_amount);
Alexandre Rames82000b02015-07-07 11:34:16 +0100182}
183
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100184inline vixl::aarch64::MemOperand HeapOperand(const vixl::aarch64::Register& base,
Scott Wakeling97c72b72016-06-24 16:19:36 +0100185 Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800186 return HeapOperand(base, offset.SizeValue());
187}
188
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100189inline vixl::aarch64::MemOperand HeapOperandFrom(Location location, Offset offset) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800190 return HeapOperand(RegisterFrom(location, Primitive::kPrimNot), offset);
191}
192
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100193inline Location LocationFrom(const vixl::aarch64::Register& reg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100194 return Location::RegisterLocation(ARTRegCodeFromVIXL(reg.GetCode()));
Andreas Gampe878d58c2015-01-15 23:24:00 -0800195}
196
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100197inline Location LocationFrom(const vixl::aarch64::FPRegister& fpreg) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100198 return Location::FpuRegisterLocation(fpreg.GetCode());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800199}
200
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100201inline vixl::aarch64::Operand OperandFromMemOperand(
Scott Wakeling97c72b72016-06-24 16:19:36 +0100202 const vixl::aarch64::MemOperand& mem_op) {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800203 if (mem_op.IsImmediateOffset()) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100204 return vixl::aarch64::Operand(mem_op.GetOffset());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800205 } else {
206 DCHECK(mem_op.IsRegisterOffset());
Scott Wakeling97c72b72016-06-24 16:19:36 +0100207 if (mem_op.GetExtend() != vixl::aarch64::NO_EXTEND) {
208 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
209 mem_op.GetExtend(),
210 mem_op.GetShiftAmount());
211 } else if (mem_op.GetShift() != vixl::aarch64::NO_SHIFT) {
212 return vixl::aarch64::Operand(mem_op.GetRegisterOffset(),
213 mem_op.GetShift(),
214 mem_op.GetShiftAmount());
Andreas Gampe878d58c2015-01-15 23:24:00 -0800215 } else {
216 LOG(FATAL) << "Should not reach here";
217 UNREACHABLE();
218 }
219 }
220}
221
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100222inline bool CanEncodeConstantAsImmediate(HConstant* constant, HInstruction* instr) {
Roland Levillain22c49222016-03-18 14:04:28 +0000223 DCHECK(constant->IsIntConstant() || constant->IsLongConstant() || constant->IsNullConstant())
224 << constant->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000225
226 // For single uses we let VIXL handle the constant generation since it will
227 // use registers that are not managed by the register allocator (wip0, wip1).
Vladimir Marko46817b82016-03-29 12:21:58 +0100228 if (constant->GetUses().HasExactlyOneElement()) {
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000229 return true;
230 }
231
Scott Wakeling40a04bf2015-12-11 09:50:36 +0000232 // Our code generator ensures shift distances are within an encodable range.
233 if (instr->IsRor()) {
234 return true;
235 }
236
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000237 int64_t value = CodeGenerator::GetInt64ValueOf(constant);
238
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100239 if (instr->IsAnd() || instr->IsOr() || instr->IsXor()) {
240 // Uses logical operations.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100241 return vixl::aarch64::Assembler::IsImmLogical(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100242 } else if (instr->IsNeg()) {
243 // Uses mov -immediate.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100244 return vixl::aarch64::Assembler::IsImmMovn(value, vixl::aarch64::kXRegSize);
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100245 } else {
246 DCHECK(instr->IsAdd() ||
Artem Serov328429f2016-07-06 16:23:04 +0100247 instr->IsIntermediateAddress() ||
Alexandre Ramese6dbf482015-10-19 10:10:41 +0100248 instr->IsBoundsCheck() ||
249 instr->IsCompare() ||
250 instr->IsCondition() ||
Roland Levillain22c49222016-03-18 14:04:28 +0000251 instr->IsSub())
252 << instr->DebugName();
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000253 // Uses aliases of ADD/SUB instructions.
Alexandre Ramesb69fbfb2015-10-16 09:08:46 +0100254 // If `value` does not fit but `-value` does, VIXL will automatically use
255 // the 'opposite' instruction.
Scott Wakeling97c72b72016-06-24 16:19:36 +0100256 return vixl::aarch64::Assembler::IsImmAddSub(value)
257 || vixl::aarch64::Assembler::IsImmAddSub(-value);
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000258 }
259}
260
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100261inline Location ARM64EncodableConstantOrRegister(HInstruction* constant,
Serban Constantinescu2d35d9d2015-02-22 22:08:01 +0000262 HInstruction* instr) {
263 if (constant->IsConstant()
264 && CanEncodeConstantAsImmediate(constant->AsConstant(), instr)) {
265 return Location::ConstantLocation(constant->AsConstant());
266 }
267
268 return Location::RequiresRegister();
269}
270
Zheng Xuda403092015-04-24 17:35:39 +0800271// Check if registers in art register set have the same register code in vixl. If the register
272// codes are same, we can initialize vixl register list simply by the register masks. Currently,
273// only SP/WSP and ZXR/WZR codes are different between art and vixl.
274// Note: This function is only used for debug checks.
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100275inline bool ArtVixlRegCodeCoherentForRegSet(uint32_t art_core_registers,
Vladimir Marko804b03f2016-09-14 16:26:36 +0100276 size_t num_core,
277 uint32_t art_fpu_registers,
278 size_t num_fpu) {
Zheng Xuda403092015-04-24 17:35:39 +0800279 // The register masks won't work if the number of register is larger than 32.
280 DCHECK_GE(sizeof(art_core_registers) * 8, num_core);
281 DCHECK_GE(sizeof(art_fpu_registers) * 8, num_fpu);
282 for (size_t art_reg_code = 0; art_reg_code < num_core; ++art_reg_code) {
283 if (RegisterSet::Contains(art_core_registers, art_reg_code)) {
284 if (art_reg_code != static_cast<size_t>(VIXLRegCodeFromART(art_reg_code))) {
285 return false;
286 }
287 }
288 }
289 // There is no register code translation for float registers.
290 return true;
291}
292
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100293inline vixl::aarch64::Shift ShiftFromOpKind(HArm64DataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000294 switch (op_kind) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100295 case HArm64DataProcWithShifterOp::kASR: return vixl::aarch64::ASR;
296 case HArm64DataProcWithShifterOp::kLSL: return vixl::aarch64::LSL;
297 case HArm64DataProcWithShifterOp::kLSR: return vixl::aarch64::LSR;
Alexandre Rames8626b742015-11-25 16:28:08 +0000298 default:
299 LOG(FATAL) << "Unexpected op kind " << op_kind;
300 UNREACHABLE();
Scott Wakeling97c72b72016-06-24 16:19:36 +0100301 return vixl::aarch64::NO_SHIFT;
Alexandre Rames8626b742015-11-25 16:28:08 +0000302 }
303}
304
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100305inline vixl::aarch64::Extend ExtendFromOpKind(HArm64DataProcWithShifterOp::OpKind op_kind) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000306 switch (op_kind) {
Scott Wakeling97c72b72016-06-24 16:19:36 +0100307 case HArm64DataProcWithShifterOp::kUXTB: return vixl::aarch64::UXTB;
308 case HArm64DataProcWithShifterOp::kUXTH: return vixl::aarch64::UXTH;
309 case HArm64DataProcWithShifterOp::kUXTW: return vixl::aarch64::UXTW;
310 case HArm64DataProcWithShifterOp::kSXTB: return vixl::aarch64::SXTB;
311 case HArm64DataProcWithShifterOp::kSXTH: return vixl::aarch64::SXTH;
312 case HArm64DataProcWithShifterOp::kSXTW: return vixl::aarch64::SXTW;
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_EXTEND;
Alexandre Rames8626b742015-11-25 16:28:08 +0000317 }
318}
319
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100320inline bool CanFitInShifterOperand(HInstruction* instruction) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000321 if (instruction->IsTypeConversion()) {
322 HTypeConversion* conversion = instruction->AsTypeConversion();
323 Primitive::Type result_type = conversion->GetResultType();
324 Primitive::Type input_type = conversion->GetInputType();
325 // We don't expect to see the same type as input and result.
326 return Primitive::IsIntegralType(result_type) && Primitive::IsIntegralType(input_type) &&
327 (result_type != input_type);
328 } else {
329 return (instruction->IsShl() && instruction->AsShl()->InputAt(1)->IsIntConstant()) ||
330 (instruction->IsShr() && instruction->AsShr()->InputAt(1)->IsIntConstant()) ||
331 (instruction->IsUShr() && instruction->AsUShr()->InputAt(1)->IsIntConstant());
332 }
333}
334
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100335inline bool HasShifterOperand(HInstruction* instr) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000336 // `neg` instructions are an alias of `sub` using the zero register as the
337 // first register input.
338 bool res = instr->IsAdd() || instr->IsAnd() || instr->IsNeg() ||
339 instr->IsOr() || instr->IsSub() || instr->IsXor();
340 return res;
341}
342
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100343inline bool ShifterOperandSupportsExtension(HInstruction* instruction) {
Alexandre Rames8626b742015-11-25 16:28:08 +0000344 DCHECK(HasShifterOperand(instruction));
345 // Although the `neg` instruction is an alias of the `sub` instruction, `HNeg`
346 // does *not* support extension. This is because the `extended register` form
347 // of the `sub` instruction interprets the left register with code 31 as the
348 // stack pointer and not the zero register. (So does the `immediate` form.) In
349 // the other form `shifted register, the register with code 31 is interpreted
350 // as the zero register.
351 return instruction->IsAdd() || instruction->IsSub();
352}
353
Alexandre Ramesbadf2b22016-08-24 17:08:49 +0100354inline bool IsConstantZeroBitPattern(const HInstruction* instruction) {
Alexandre Ramesbe919d92016-08-23 18:33:36 +0100355 return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern();
356}
357
Andreas Gampe878d58c2015-01-15 23:24:00 -0800358} // namespace helpers
359} // namespace arm64
360} // namespace art
361
362#endif // ART_COMPILER_OPTIMIZING_COMMON_ARM64_H_