1 //===--- AArch64Subtarget.h - Define Subtarget for the AArch64 -*- C++ -*--===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares the AArch64 specific subclass of TargetSubtarget.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
14 #define LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
16 #include "AArch64FrameLowering.h"
17 #include "AArch64ISelLowering.h"
18 #include "AArch64InstrInfo.h"
19 #include "AArch64RegisterInfo.h"
20 #include "AArch64SelectionDAGInfo.h"
21 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
22 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
23 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
24 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
25 #include "llvm/CodeGen/TargetSubtargetInfo.h"
26 #include "llvm/IR/DataLayout.h"
29 #define GET_SUBTARGETINFO_HEADER
30 #include "AArch64GenSubtargetInfo.inc"
37 class AArch64Subtarget final
: public AArch64GenSubtargetInfo
{
39 enum ARMProcFamilyEnum
: uint8_t {
67 /// ARMProcFamily - ARM processor family: Cortex-A53, Cortex-A57, and others.
68 ARMProcFamilyEnum ARMProcFamily
= Others
;
70 bool HasV8_1aOps
= false;
71 bool HasV8_2aOps
= false;
72 bool HasV8_3aOps
= false;
73 bool HasV8_4aOps
= false;
74 bool HasV8_5aOps
= false;
76 bool HasFPARMv8
= false;
78 bool HasCrypto
= false;
79 bool HasDotProd
= false;
84 bool HasPerfMon
= false;
85 bool HasFullFP16
= false;
86 bool HasFP16FML
= false;
95 bool HasPsUAO
= false;
96 bool HasPAN_RWV
= false;
99 // Armv8.2 Crypto extensions
101 bool HasSHA3
= false;
102 bool HasSHA2
= false;
105 // ARMv8.3 extensions
108 bool HasCCIDX
= false;
109 bool HasComplxNum
= false;
111 // ARMv8.4 extensions
113 bool HasRASv8_4
= false;
114 bool HasMPAM
= false;
116 bool HasTRACEV8_4
= false;
118 bool HasSEL2
= false;
120 bool HasTLB_RMI
= false;
122 bool HasRCPC_IMMO
= false;
124 bool HasLSLFast
= false;
126 bool HasSVE2
= false;
127 bool HasRCPC
= false;
128 bool HasAggressiveFMA
= false;
130 // Armv8.5-A Extensions
131 bool HasAlternativeNZCV
= false;
132 bool HasFRInt3264
= false;
133 bool HasSpecRestrict
= false;
134 bool HasSSBS
= false;
136 bool HasPredRes
= false;
137 bool HasCCDP
= false;
139 bool HasRandGen
= false;
143 // Arm SVE2 extensions
144 bool HasSVE2AES
= false;
145 bool HasSVE2SM4
= false;
146 bool HasSVE2SHA3
= false;
147 bool HasSVE2BitPerm
= false;
149 // Future architecture extensions.
151 bool HasTRBE
= false;
153 // HasZeroCycleRegMove - Has zero-cycle register mov instructions.
154 bool HasZeroCycleRegMove
= false;
156 // HasZeroCycleZeroing - Has zero-cycle zeroing instructions.
157 bool HasZeroCycleZeroing
= false;
158 bool HasZeroCycleZeroingGP
= false;
159 bool HasZeroCycleZeroingFP
= false;
160 bool HasZeroCycleZeroingFPWorkaround
= false;
162 // StrictAlign - Disallow unaligned memory accesses.
163 bool StrictAlign
= false;
165 // NegativeImmediates - transform instructions with negative immediates
166 bool NegativeImmediates
= true;
168 // Enable 64-bit vectorization in SLP.
169 unsigned MinVectorRegisterBitWidth
= 64;
172 bool PredictableSelectIsExpensive
= false;
173 bool BalanceFPOps
= false;
174 bool CustomAsCheapAsMove
= false;
175 bool ExynosAsCheapAsMove
= false;
176 bool UsePostRAScheduler
= false;
177 bool Misaligned128StoreIsSlow
= false;
178 bool Paired128IsSlow
= false;
179 bool STRQroIsSlow
= false;
180 bool UseAlternateSExtLoadCVTF32Pattern
= false;
181 bool HasArithmeticBccFusion
= false;
182 bool HasArithmeticCbzFusion
= false;
183 bool HasFuseAddress
= false;
184 bool HasFuseAES
= false;
185 bool HasFuseArithmeticLogic
= false;
186 bool HasFuseCCSelect
= false;
187 bool HasFuseCryptoEOR
= false;
188 bool HasFuseLiterals
= false;
189 bool DisableLatencySchedHeuristic
= false;
190 bool UseRSqrt
= false;
191 bool Force32BitJumpTables
= false;
192 bool UseEL1ForTP
= false;
193 bool UseEL2ForTP
= false;
194 bool UseEL3ForTP
= false;
195 bool AllowTaggedGlobals
= false;
196 uint8_t MaxInterleaveFactor
= 2;
197 uint8_t VectorInsertExtractBaseCost
= 3;
198 uint16_t CacheLineSize
= 0;
199 uint16_t PrefetchDistance
= 0;
200 uint16_t MinPrefetchStride
= 1;
201 unsigned MaxPrefetchIterationsAhead
= UINT_MAX
;
202 unsigned PrefFunctionLogAlignment
= 0;
203 unsigned PrefLoopLogAlignment
= 0;
204 unsigned MaxJumpTableSize
= 0;
205 unsigned WideningBaseCost
= 0;
207 // ReserveXRegister[i] - X#i is not available as a general purpose register.
208 BitVector ReserveXRegister
;
210 // CustomCallUsedXRegister[i] - X#i call saved.
211 BitVector CustomCallSavedXRegs
;
215 /// TargetTriple - What processor and OS we're targeting.
218 AArch64FrameLowering FrameLowering
;
219 AArch64InstrInfo InstrInfo
;
220 AArch64SelectionDAGInfo TSInfo
;
221 AArch64TargetLowering TLInfo
;
223 /// GlobalISel related APIs.
224 std::unique_ptr
<CallLowering
> CallLoweringInfo
;
225 std::unique_ptr
<InstructionSelector
> InstSelector
;
226 std::unique_ptr
<LegalizerInfo
> Legalizer
;
227 std::unique_ptr
<RegisterBankInfo
> RegBankInfo
;
230 /// initializeSubtargetDependencies - Initializes using CPUString and the
231 /// passed in feature string so that we can use initializer lists for
232 /// subtarget initialization.
233 AArch64Subtarget
&initializeSubtargetDependencies(StringRef FS
,
234 StringRef CPUString
);
236 /// Initialize properties based on the selected processor family.
237 void initializeProperties();
240 /// This constructor initializes the data members to match that
241 /// of the specified triple.
242 AArch64Subtarget(const Triple
&TT
, const std::string
&CPU
,
243 const std::string
&FS
, const TargetMachine
&TM
,
246 const AArch64SelectionDAGInfo
*getSelectionDAGInfo() const override
{
249 const AArch64FrameLowering
*getFrameLowering() const override
{
250 return &FrameLowering
;
252 const AArch64TargetLowering
*getTargetLowering() const override
{
255 const AArch64InstrInfo
*getInstrInfo() const override
{ return &InstrInfo
; }
256 const AArch64RegisterInfo
*getRegisterInfo() const override
{
257 return &getInstrInfo()->getRegisterInfo();
259 const CallLowering
*getCallLowering() const override
;
260 InstructionSelector
*getInstructionSelector() const override
;
261 const LegalizerInfo
*getLegalizerInfo() const override
;
262 const RegisterBankInfo
*getRegBankInfo() const override
;
263 const Triple
&getTargetTriple() const { return TargetTriple
; }
264 bool enableMachineScheduler() const override
{ return true; }
265 bool enablePostRAScheduler() const override
{
266 return UsePostRAScheduler
;
269 /// Returns ARM processor family.
270 /// Avoid this function! CPU specifics should be kept local to this class
271 /// and preferably modeled with SubtargetFeatures or properties in
272 /// initializeProperties().
273 ARMProcFamilyEnum
getProcFamily() const {
274 return ARMProcFamily
;
277 bool hasV8_1aOps() const { return HasV8_1aOps
; }
278 bool hasV8_2aOps() const { return HasV8_2aOps
; }
279 bool hasV8_3aOps() const { return HasV8_3aOps
; }
280 bool hasV8_4aOps() const { return HasV8_4aOps
; }
281 bool hasV8_5aOps() const { return HasV8_5aOps
; }
283 bool hasZeroCycleRegMove() const { return HasZeroCycleRegMove
; }
285 bool hasZeroCycleZeroingGP() const { return HasZeroCycleZeroingGP
; }
287 bool hasZeroCycleZeroingFP() const { return HasZeroCycleZeroingFP
; }
289 bool hasZeroCycleZeroingFPWorkaround() const {
290 return HasZeroCycleZeroingFPWorkaround
;
293 bool requiresStrictAlign() const { return StrictAlign
; }
295 bool isXRaySupported() const override
{ return true; }
297 unsigned getMinVectorRegisterBitWidth() const {
298 return MinVectorRegisterBitWidth
;
301 bool isXRegisterReserved(size_t i
) const { return ReserveXRegister
[i
]; }
302 unsigned getNumXRegisterReserved() const { return ReserveXRegister
.count(); }
303 bool isXRegCustomCalleeSaved(size_t i
) const {
304 return CustomCallSavedXRegs
[i
];
306 bool hasCustomCallingConv() const { return CustomCallSavedXRegs
.any(); }
307 bool hasFPARMv8() const { return HasFPARMv8
; }
308 bool hasNEON() const { return HasNEON
; }
309 bool hasCrypto() const { return HasCrypto
; }
310 bool hasDotProd() const { return HasDotProd
; }
311 bool hasCRC() const { return HasCRC
; }
312 bool hasLSE() const { return HasLSE
; }
313 bool hasRAS() const { return HasRAS
; }
314 bool hasRDM() const { return HasRDM
; }
315 bool hasSM4() const { return HasSM4
; }
316 bool hasSHA3() const { return HasSHA3
; }
317 bool hasSHA2() const { return HasSHA2
; }
318 bool hasAES() const { return HasAES
; }
319 bool balanceFPOps() const { return BalanceFPOps
; }
320 bool predictableSelectIsExpensive() const {
321 return PredictableSelectIsExpensive
;
323 bool hasCustomCheapAsMoveHandling() const { return CustomAsCheapAsMove
; }
324 bool hasExynosCheapAsMoveHandling() const { return ExynosAsCheapAsMove
; }
325 bool isMisaligned128StoreSlow() const { return Misaligned128StoreIsSlow
; }
326 bool isPaired128Slow() const { return Paired128IsSlow
; }
327 bool isSTRQroSlow() const { return STRQroIsSlow
; }
328 bool useAlternateSExtLoadCVTF32Pattern() const {
329 return UseAlternateSExtLoadCVTF32Pattern
;
331 bool hasArithmeticBccFusion() const { return HasArithmeticBccFusion
; }
332 bool hasArithmeticCbzFusion() const { return HasArithmeticCbzFusion
; }
333 bool hasFuseAddress() const { return HasFuseAddress
; }
334 bool hasFuseAES() const { return HasFuseAES
; }
335 bool hasFuseArithmeticLogic() const { return HasFuseArithmeticLogic
; }
336 bool hasFuseCCSelect() const { return HasFuseCCSelect
; }
337 bool hasFuseCryptoEOR() const { return HasFuseCryptoEOR
; }
338 bool hasFuseLiterals() const { return HasFuseLiterals
; }
340 /// Return true if the CPU supports any kind of instruction fusion.
341 bool hasFusion() const {
342 return hasArithmeticBccFusion() || hasArithmeticCbzFusion() ||
343 hasFuseAES() || hasFuseArithmeticLogic() ||
344 hasFuseCCSelect() || hasFuseLiterals();
347 bool useEL1ForTP() const { return UseEL1ForTP
; }
348 bool useEL2ForTP() const { return UseEL2ForTP
; }
349 bool useEL3ForTP() const { return UseEL3ForTP
; }
351 bool useRSqrt() const { return UseRSqrt
; }
352 bool force32BitJumpTables() const { return Force32BitJumpTables
; }
353 unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor
; }
354 unsigned getVectorInsertExtractBaseCost() const {
355 return VectorInsertExtractBaseCost
;
357 unsigned getCacheLineSize() const override
{ return CacheLineSize
; }
358 unsigned getPrefetchDistance() const override
{ return PrefetchDistance
; }
359 unsigned getMinPrefetchStride() const override
{ return MinPrefetchStride
; }
360 unsigned getMaxPrefetchIterationsAhead() const override
{
361 return MaxPrefetchIterationsAhead
;
363 unsigned getPrefFunctionLogAlignment() const {
364 return PrefFunctionLogAlignment
;
366 unsigned getPrefLoopLogAlignment() const { return PrefLoopLogAlignment
; }
368 unsigned getMaximumJumpTableSize() const { return MaxJumpTableSize
; }
370 unsigned getWideningBaseCost() const { return WideningBaseCost
; }
372 /// CPU has TBI (top byte of addresses is ignored during HW address
373 /// translation) and OS enables it.
374 bool supportsAddressTopByteIgnored() const;
376 bool hasPerfMon() const { return HasPerfMon
; }
377 bool hasFullFP16() const { return HasFullFP16
; }
378 bool hasFP16FML() const { return HasFP16FML
; }
379 bool hasSPE() const { return HasSPE
; }
380 bool hasLSLFast() const { return HasLSLFast
; }
381 bool hasSVE() const { return HasSVE
; }
382 bool hasSVE2() const { return HasSVE2
; }
383 bool hasRCPC() const { return HasRCPC
; }
384 bool hasAggressiveFMA() const { return HasAggressiveFMA
; }
385 bool hasAlternativeNZCV() const { return HasAlternativeNZCV
; }
386 bool hasFRInt3264() const { return HasFRInt3264
; }
387 bool hasSpecRestrict() const { return HasSpecRestrict
; }
388 bool hasSSBS() const { return HasSSBS
; }
389 bool hasSB() const { return HasSB
; }
390 bool hasPredRes() const { return HasPredRes
; }
391 bool hasCCDP() const { return HasCCDP
; }
392 bool hasBTI() const { return HasBTI
; }
393 bool hasRandGen() const { return HasRandGen
; }
394 bool hasMTE() const { return HasMTE
; }
395 bool hasTME() const { return HasTME
; }
396 // Arm SVE2 extensions
397 bool hasSVE2AES() const { return HasSVE2AES
; }
398 bool hasSVE2SM4() const { return HasSVE2SM4
; }
399 bool hasSVE2SHA3() const { return HasSVE2SHA3
; }
400 bool hasSVE2BitPerm() const { return HasSVE2BitPerm
; }
402 bool isLittleEndian() const { return IsLittle
; }
404 bool isTargetDarwin() const { return TargetTriple
.isOSDarwin(); }
405 bool isTargetIOS() const { return TargetTriple
.isiOS(); }
406 bool isTargetLinux() const { return TargetTriple
.isOSLinux(); }
407 bool isTargetWindows() const { return TargetTriple
.isOSWindows(); }
408 bool isTargetAndroid() const { return TargetTriple
.isAndroid(); }
409 bool isTargetFuchsia() const { return TargetTriple
.isOSFuchsia(); }
411 bool isTargetCOFF() const { return TargetTriple
.isOSBinFormatCOFF(); }
412 bool isTargetELF() const { return TargetTriple
.isOSBinFormatELF(); }
413 bool isTargetMachO() const { return TargetTriple
.isOSBinFormatMachO(); }
415 bool isTargetILP32() const { return TargetTriple
.isArch32Bit(); }
417 bool useAA() const override
{ return UseAA
; }
419 bool hasVH() const { return HasVH
; }
420 bool hasPAN() const { return HasPAN
; }
421 bool hasLOR() const { return HasLOR
; }
423 bool hasPsUAO() const { return HasPsUAO
; }
424 bool hasPAN_RWV() const { return HasPAN_RWV
; }
425 bool hasCCPP() const { return HasCCPP
; }
427 bool hasPA() const { return HasPA
; }
428 bool hasJS() const { return HasJS
; }
429 bool hasCCIDX() const { return HasCCIDX
; }
430 bool hasComplxNum() const { return HasComplxNum
; }
432 bool hasNV() const { return HasNV
; }
433 bool hasRASv8_4() const { return HasRASv8_4
; }
434 bool hasMPAM() const { return HasMPAM
; }
435 bool hasDIT() const { return HasDIT
; }
436 bool hasTRACEV8_4() const { return HasTRACEV8_4
; }
437 bool hasAM() const { return HasAM
; }
438 bool hasSEL2() const { return HasSEL2
; }
439 bool hasPMU() const { return HasPMU
; }
440 bool hasTLB_RMI() const { return HasTLB_RMI
; }
441 bool hasFMI() const { return HasFMI
; }
442 bool hasRCPC_IMMO() const { return HasRCPC_IMMO
; }
444 bool addrSinkUsingGEPs() const override
{
445 // Keeping GEPs inbounds is important for exploiting AArch64
446 // addressing-modes in ILP32 mode.
447 return useAA() || isTargetILP32();
450 bool useSmallAddressing() const {
451 switch (TLInfo
.getTargetMachine().getCodeModel()) {
452 case CodeModel::Kernel
:
453 // Kernel is currently allowed only for Fuchsia targets,
454 // where it is the same as Small for almost all purposes.
455 case CodeModel::Small
:
462 /// ParseSubtargetFeatures - Parses features string setting specified
463 /// subtarget options. Definition of function is auto generated by tblgen.
464 void ParseSubtargetFeatures(StringRef CPU
, StringRef FS
);
466 /// ClassifyGlobalReference - Find the target operand flags that describe
467 /// how a global value should be referenced for the current subtarget.
468 unsigned ClassifyGlobalReference(const GlobalValue
*GV
,
469 const TargetMachine
&TM
) const;
471 unsigned classifyGlobalFunctionReference(const GlobalValue
*GV
,
472 const TargetMachine
&TM
) const;
474 void overrideSchedPolicy(MachineSchedPolicy
&Policy
,
475 unsigned NumRegionInstrs
) const override
;
477 bool enableEarlyIfConversion() const override
;
479 std::unique_ptr
<PBQPRAConstraint
> getCustomPBQPConstraints() const override
;
481 bool isCallingConvWin64(CallingConv::ID CC
) const {
484 case CallingConv::Fast
:
485 case CallingConv::Swift
:
486 return isTargetWindows();
487 case CallingConv::Win64
:
494 void mirFileLoaded(MachineFunction
&MF
) const override
;
496 } // End llvm namespace