1 //===--- AArch64Subtarget.h - Define Subtarget for the AArch64 -*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the AArch64 specific subclass of TargetSubtarget.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
15 #define LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
17 #include "AArch64FrameLowering.h"
18 #include "AArch64ISelLowering.h"
19 #include "AArch64InstrInfo.h"
20 #include "AArch64RegisterInfo.h"
21 #include "AArch64SelectionDAGInfo.h"
22 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
23 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
24 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
25 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
26 #include "llvm/CodeGen/TargetSubtargetInfo.h"
27 #include "llvm/IR/DataLayout.h"
30 #define GET_SUBTARGETINFO_HEADER
31 #include "AArch64GenSubtargetInfo.inc"
38 class AArch64Subtarget final : public AArch64GenSubtargetInfo {
40 enum ARMProcFamilyEnum : uint8_t {
64 /// ARMProcFamily - ARM processor family: Cortex-A53, Cortex-A57, and others.
65 ARMProcFamilyEnum ARMProcFamily = Others;
67 bool HasV8_1aOps = false;
68 bool HasV8_2aOps = false;
69 bool HasV8_3aOps = false;
70 bool HasV8_4aOps = false;
71 bool HasV8_5aOps = false;
73 bool HasFPARMv8 = false;
75 bool HasCrypto = false;
76 bool HasDotProd = false;
81 bool HasPerfMon = false;
82 bool HasFullFP16 = false;
83 bool HasFP16FML = false;
92 bool HasPsUAO = false;
93 bool HasPAN_RWV = false;
99 bool HasCCIDX = false;
100 bool HasComplxNum = false;
102 // ARMv8.4 extensions
104 bool HasRASv8_4 = false;
105 bool HasMPAM = false;
107 bool HasTRACEV8_4 = false;
109 bool HasSEL2 = false;
110 bool HasTLB_RMI = false;
112 bool HasRCPC_IMMO = false;
113 // ARMv8.4 Crypto extensions
120 bool HasLSLFast = false;
122 bool HasRCPC = false;
123 bool HasAggressiveFMA = false;
125 // Armv8.5-A Extensions
126 bool HasAlternativeNZCV = false;
127 bool HasFRInt3264 = false;
128 bool HasSpecRestrict = false;
129 bool HasSSBS = false;
131 bool HasPredRes = false;
132 bool HasCCDP = false;
134 bool HasRandGen = false;
137 // HasZeroCycleRegMove - Has zero-cycle register mov instructions.
138 bool HasZeroCycleRegMove = false;
140 // HasZeroCycleZeroing - Has zero-cycle zeroing instructions.
141 bool HasZeroCycleZeroing = false;
142 bool HasZeroCycleZeroingGP = false;
143 bool HasZeroCycleZeroingFP = false;
144 bool HasZeroCycleZeroingFPWorkaround = false;
146 // StrictAlign - Disallow unaligned memory accesses.
147 bool StrictAlign = false;
149 // NegativeImmediates - transform instructions with negative immediates
150 bool NegativeImmediates = true;
152 // Enable 64-bit vectorization in SLP.
153 unsigned MinVectorRegisterBitWidth = 64;
156 bool PredictableSelectIsExpensive = false;
157 bool BalanceFPOps = false;
158 bool CustomAsCheapAsMove = false;
159 bool ExynosAsCheapAsMove = false;
160 bool UsePostRAScheduler = false;
161 bool Misaligned128StoreIsSlow = false;
162 bool Paired128IsSlow = false;
163 bool STRQroIsSlow = false;
164 bool UseAlternateSExtLoadCVTF32Pattern = false;
165 bool HasArithmeticBccFusion = false;
166 bool HasArithmeticCbzFusion = false;
167 bool HasFuseAddress = false;
168 bool HasFuseAES = false;
169 bool HasFuseArithmeticLogic = false;
170 bool HasFuseCCSelect = false;
171 bool HasFuseCryptoEOR = false;
172 bool HasFuseLiterals = false;
173 bool DisableLatencySchedHeuristic = false;
174 bool UseRSqrt = false;
175 bool Force32BitJumpTables = false;
176 uint8_t MaxInterleaveFactor = 2;
177 uint8_t VectorInsertExtractBaseCost = 3;
178 uint16_t CacheLineSize = 0;
179 uint16_t PrefetchDistance = 0;
180 uint16_t MinPrefetchStride = 1;
181 unsigned MaxPrefetchIterationsAhead = UINT_MAX;
182 unsigned PrefFunctionAlignment = 0;
183 unsigned PrefLoopAlignment = 0;
184 unsigned MaxJumpTableSize = 0;
185 unsigned WideningBaseCost = 0;
187 // ReserveXRegister[i] - X#i is not available as a general purpose register.
188 BitVector ReserveXRegister;
190 // CustomCallUsedXRegister[i] - X#i call saved.
191 BitVector CustomCallSavedXRegs;
195 /// TargetTriple - What processor and OS we're targeting.
198 AArch64FrameLowering FrameLowering;
199 AArch64InstrInfo InstrInfo;
200 AArch64SelectionDAGInfo TSInfo;
201 AArch64TargetLowering TLInfo;
203 /// GlobalISel related APIs.
204 std::unique_ptr<CallLowering> CallLoweringInfo;
205 std::unique_ptr<InstructionSelector> InstSelector;
206 std::unique_ptr<LegalizerInfo> Legalizer;
207 std::unique_ptr<RegisterBankInfo> RegBankInfo;
210 /// initializeSubtargetDependencies - Initializes using CPUString and the
211 /// passed in feature string so that we can use initializer lists for
212 /// subtarget initialization.
213 AArch64Subtarget &initializeSubtargetDependencies(StringRef FS,
214 StringRef CPUString);
216 /// Initialize properties based on the selected processor family.
217 void initializeProperties();
220 /// This constructor initializes the data members to match that
221 /// of the specified triple.
222 AArch64Subtarget(const Triple &TT, const std::string &CPU,
223 const std::string &FS, const TargetMachine &TM,
226 const AArch64SelectionDAGInfo *getSelectionDAGInfo() const override {
229 const AArch64FrameLowering *getFrameLowering() const override {
230 return &FrameLowering;
232 const AArch64TargetLowering *getTargetLowering() const override {
235 const AArch64InstrInfo *getInstrInfo() const override { return &InstrInfo; }
236 const AArch64RegisterInfo *getRegisterInfo() const override {
237 return &getInstrInfo()->getRegisterInfo();
239 const CallLowering *getCallLowering() const override;
240 const InstructionSelector *getInstructionSelector() const override;
241 const LegalizerInfo *getLegalizerInfo() const override;
242 const RegisterBankInfo *getRegBankInfo() const override;
243 const Triple &getTargetTriple() const { return TargetTriple; }
244 bool enableMachineScheduler() const override { return true; }
245 bool enablePostRAScheduler() const override {
246 return UsePostRAScheduler;
249 /// Returns ARM processor family.
250 /// Avoid this function! CPU specifics should be kept local to this class
251 /// and preferably modeled with SubtargetFeatures or properties in
252 /// initializeProperties().
253 ARMProcFamilyEnum getProcFamily() const {
254 return ARMProcFamily;
257 bool hasV8_1aOps() const { return HasV8_1aOps; }
258 bool hasV8_2aOps() const { return HasV8_2aOps; }
259 bool hasV8_3aOps() const { return HasV8_3aOps; }
260 bool hasV8_4aOps() const { return HasV8_4aOps; }
261 bool hasV8_5aOps() const { return HasV8_5aOps; }
263 bool hasZeroCycleRegMove() const { return HasZeroCycleRegMove; }
265 bool hasZeroCycleZeroingGP() const { return HasZeroCycleZeroingGP; }
267 bool hasZeroCycleZeroingFP() const { return HasZeroCycleZeroingFP; }
269 bool hasZeroCycleZeroingFPWorkaround() const {
270 return HasZeroCycleZeroingFPWorkaround;
273 bool requiresStrictAlign() const { return StrictAlign; }
275 bool isXRaySupported() const override { return true; }
277 unsigned getMinVectorRegisterBitWidth() const {
278 return MinVectorRegisterBitWidth;
281 bool isXRegisterReserved(size_t i) const { return ReserveXRegister[i]; }
282 unsigned getNumXRegisterReserved() const { return ReserveXRegister.count(); }
283 bool isXRegCustomCalleeSaved(size_t i) const {
284 return CustomCallSavedXRegs[i];
286 bool hasCustomCallingConv() const { return CustomCallSavedXRegs.any(); }
287 bool hasFPARMv8() const { return HasFPARMv8; }
288 bool hasNEON() const { return HasNEON; }
289 bool hasCrypto() const { return HasCrypto; }
290 bool hasDotProd() const { return HasDotProd; }
291 bool hasCRC() const { return HasCRC; }
292 bool hasLSE() const { return HasLSE; }
293 bool hasRAS() const { return HasRAS; }
294 bool hasRDM() const { return HasRDM; }
295 bool hasSM4() const { return HasSM4; }
296 bool hasSHA3() const { return HasSHA3; }
297 bool hasSHA2() const { return HasSHA2; }
298 bool hasAES() const { return HasAES; }
299 bool balanceFPOps() const { return BalanceFPOps; }
300 bool predictableSelectIsExpensive() const {
301 return PredictableSelectIsExpensive;
303 bool hasCustomCheapAsMoveHandling() const { return CustomAsCheapAsMove; }
304 bool hasExynosCheapAsMoveHandling() const { return ExynosAsCheapAsMove; }
305 bool isMisaligned128StoreSlow() const { return Misaligned128StoreIsSlow; }
306 bool isPaired128Slow() const { return Paired128IsSlow; }
307 bool isSTRQroSlow() const { return STRQroIsSlow; }
308 bool useAlternateSExtLoadCVTF32Pattern() const {
309 return UseAlternateSExtLoadCVTF32Pattern;
311 bool hasArithmeticBccFusion() const { return HasArithmeticBccFusion; }
312 bool hasArithmeticCbzFusion() const { return HasArithmeticCbzFusion; }
313 bool hasFuseAddress() const { return HasFuseAddress; }
314 bool hasFuseAES() const { return HasFuseAES; }
315 bool hasFuseArithmeticLogic() const { return HasFuseArithmeticLogic; }
316 bool hasFuseCCSelect() const { return HasFuseCCSelect; }
317 bool hasFuseCryptoEOR() const { return HasFuseCryptoEOR; }
318 bool hasFuseLiterals() const { return HasFuseLiterals; }
320 /// Return true if the CPU supports any kind of instruction fusion.
321 bool hasFusion() const {
322 return hasArithmeticBccFusion() || hasArithmeticCbzFusion() ||
323 hasFuseAES() || hasFuseArithmeticLogic() ||
324 hasFuseCCSelect() || hasFuseLiterals();
327 bool useRSqrt() const { return UseRSqrt; }
328 bool force32BitJumpTables() const { return Force32BitJumpTables; }
329 unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; }
330 unsigned getVectorInsertExtractBaseCost() const {
331 return VectorInsertExtractBaseCost;
333 unsigned getCacheLineSize() const { return CacheLineSize; }
334 unsigned getPrefetchDistance() const { return PrefetchDistance; }
335 unsigned getMinPrefetchStride() const { return MinPrefetchStride; }
336 unsigned getMaxPrefetchIterationsAhead() const {
337 return MaxPrefetchIterationsAhead;
339 unsigned getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
340 unsigned getPrefLoopAlignment() const { return PrefLoopAlignment; }
342 unsigned getMaximumJumpTableSize() const { return MaxJumpTableSize; }
344 unsigned getWideningBaseCost() const { return WideningBaseCost; }
346 /// CPU has TBI (top byte of addresses is ignored during HW address
347 /// translation) and OS enables it.
348 bool supportsAddressTopByteIgnored() const;
350 bool hasPerfMon() const { return HasPerfMon; }
351 bool hasFullFP16() const { return HasFullFP16; }
352 bool hasFP16FML() const { return HasFP16FML; }
353 bool hasSPE() const { return HasSPE; }
354 bool hasLSLFast() const { return HasLSLFast; }
355 bool hasSVE() const { return HasSVE; }
356 bool hasRCPC() const { return HasRCPC; }
357 bool hasAggressiveFMA() const { return HasAggressiveFMA; }
358 bool hasAlternativeNZCV() const { return HasAlternativeNZCV; }
359 bool hasFRInt3264() const { return HasFRInt3264; }
360 bool hasSpecRestrict() const { return HasSpecRestrict; }
361 bool hasSSBS() const { return HasSSBS; }
362 bool hasSB() const { return HasSB; }
363 bool hasPredRes() const { return HasPredRes; }
364 bool hasCCDP() const { return HasCCDP; }
365 bool hasBTI() const { return HasBTI; }
366 bool hasRandGen() const { return HasRandGen; }
367 bool hasMTE() const { return HasMTE; }
369 bool isLittleEndian() const { return IsLittle; }
371 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); }
372 bool isTargetIOS() const { return TargetTriple.isiOS(); }
373 bool isTargetLinux() const { return TargetTriple.isOSLinux(); }
374 bool isTargetWindows() const { return TargetTriple.isOSWindows(); }
375 bool isTargetAndroid() const { return TargetTriple.isAndroid(); }
376 bool isTargetFuchsia() const { return TargetTriple.isOSFuchsia(); }
378 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
379 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
380 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); }
382 bool useAA() const override { return UseAA; }
384 bool hasVH() const { return HasVH; }
385 bool hasPAN() const { return HasPAN; }
386 bool hasLOR() const { return HasLOR; }
388 bool hasPsUAO() const { return HasPsUAO; }
389 bool hasPAN_RWV() const { return HasPAN_RWV; }
390 bool hasCCPP() const { return HasCCPP; }
392 bool hasPA() const { return HasPA; }
393 bool hasJS() const { return HasJS; }
394 bool hasCCIDX() const { return HasCCIDX; }
395 bool hasComplxNum() const { return HasComplxNum; }
397 bool hasNV() const { return HasNV; }
398 bool hasRASv8_4() const { return HasRASv8_4; }
399 bool hasMPAM() const { return HasMPAM; }
400 bool hasDIT() const { return HasDIT; }
401 bool hasTRACEV8_4() const { return HasTRACEV8_4; }
402 bool hasAM() const { return HasAM; }
403 bool hasSEL2() const { return HasSEL2; }
404 bool hasTLB_RMI() const { return HasTLB_RMI; }
405 bool hasFMI() const { return HasFMI; }
406 bool hasRCPC_IMMO() const { return HasRCPC_IMMO; }
408 bool useSmallAddressing() const {
409 switch (TLInfo.getTargetMachine().getCodeModel()) {
410 case CodeModel::Kernel:
411 // Kernel is currently allowed only for Fuchsia targets,
412 // where it is the same as Small for almost all purposes.
413 case CodeModel::Small:
420 /// ParseSubtargetFeatures - Parses features string setting specified
421 /// subtarget options. Definition of function is auto generated by tblgen.
422 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
424 /// ClassifyGlobalReference - Find the target operand flags that describe
425 /// how a global value should be referenced for the current subtarget.
426 unsigned char ClassifyGlobalReference(const GlobalValue *GV,
427 const TargetMachine &TM) const;
429 unsigned char classifyGlobalFunctionReference(const GlobalValue *GV,
430 const TargetMachine &TM) const;
432 void overrideSchedPolicy(MachineSchedPolicy &Policy,
433 unsigned NumRegionInstrs) const override;
435 bool enableEarlyIfConversion() const override;
437 std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const override;
439 bool isCallingConvWin64(CallingConv::ID CC) const {
442 case CallingConv::Fast:
443 case CallingConv::Swift:
444 return isTargetWindows();
445 case CallingConv::Win64:
452 void mirFileLoaded(MachineFunction &MF) const override;
454 } // End llvm namespace