1 //===--- AArch64Subtarget.h - Define Subtarget for the AArch64 -*- C++ -*--===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file declares the AArch64 specific subclass of TargetSubtarget. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H 14 #define LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H 15 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/InlineAsmLowering.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" 28 #include <string> 29 30 #define GET_SUBTARGETINFO_HEADER 31 #include "AArch64GenSubtargetInfo.inc" 32 33 namespace llvm { 34 class GlobalValue; 35 class StringRef; 36 class Triple; 37 38 class AArch64Subtarget final : public AArch64GenSubtargetInfo { 39 public: 40 enum ARMProcFamilyEnum : uint8_t { 41 Others, 42 A64FX, 43 AppleA7, 44 AppleA10, 45 AppleA11, 46 AppleA12, 47 AppleA13, 48 CortexA35, 49 CortexA53, 50 CortexA55, 51 CortexA57, 52 CortexA65, 53 CortexA72, 54 CortexA73, 55 CortexA75, 56 CortexA76, 57 ExynosM3, 58 Falkor, 59 Kryo, 60 NeoverseE1, 61 NeoverseN1, 62 Saphira, 63 ThunderX2T99, 64 ThunderX, 65 ThunderXT81, 66 ThunderXT83, 67 ThunderXT88, 68 TSV110 69 }; 70 71 protected: 72 /// ARMProcFamily - ARM processor family: Cortex-A53, Cortex-A57, and others. 73 ARMProcFamilyEnum ARMProcFamily = Others; 74 75 bool HasV8_1aOps = false; 76 bool HasV8_2aOps = false; 77 bool HasV8_3aOps = false; 78 bool HasV8_4aOps = false; 79 bool HasV8_5aOps = false; 80 bool HasV8_6aOps = false; 81 82 bool HasFPARMv8 = false; 83 bool HasNEON = false; 84 bool HasCrypto = false; 85 bool HasDotProd = false; 86 bool HasCRC = false; 87 bool HasLSE = false; 88 bool HasRAS = false; 89 bool HasRDM = false; 90 bool HasPerfMon = false; 91 bool HasFullFP16 = false; 92 bool HasFP16FML = false; 93 bool HasSPE = false; 94 95 // ARMv8.1 extensions 96 bool HasVH = false; 97 bool HasPAN = false; 98 bool HasLOR = false; 99 100 // ARMv8.2 extensions 101 bool HasPsUAO = false; 102 bool HasPAN_RWV = false; 103 bool HasCCPP = false; 104 105 // Armv8.2 Crypto extensions 106 bool HasSM4 = false; 107 bool HasSHA3 = false; 108 bool HasSHA2 = false; 109 bool HasAES = false; 110 111 // ARMv8.3 extensions 112 bool HasPA = false; 113 bool HasJS = false; 114 bool HasCCIDX = false; 115 bool HasComplxNum = false; 116 117 // ARMv8.4 extensions 118 bool HasNV = false; 119 bool HasRASv8_4 = false; 120 bool HasMPAM = false; 121 bool HasDIT = false; 122 bool HasTRACEV8_4 = false; 123 bool HasAM = false; 124 bool HasSEL2 = false; 125 bool HasPMU = false; 126 bool HasTLB_RMI = false; 127 bool HasFMI = false; 128 bool HasRCPC_IMMO = false; 129 130 bool HasLSLFast = false; 131 bool HasSVE = false; 132 bool HasSVE2 = false; 133 bool HasRCPC = false; 134 bool HasAggressiveFMA = false; 135 136 // Armv8.5-A Extensions 137 bool HasAlternativeNZCV = false; 138 bool HasFRInt3264 = false; 139 bool HasSpecRestrict = false; 140 bool HasSSBS = false; 141 bool HasSB = false; 142 bool HasPredRes = false; 143 bool HasCCDP = false; 144 bool HasBTI = false; 145 bool HasRandGen = false; 146 bool HasMTE = false; 147 bool HasTME = false; 148 149 // Armv8.6-A Extensions 150 bool HasBF16 = false; 151 bool HasMatMulInt8 = false; 152 bool HasMatMulFP32 = false; 153 bool HasMatMulFP64 = false; 154 bool HasAMVS = false; 155 bool HasFineGrainedTraps = false; 156 bool HasEnhancedCounterVirtualization = false; 157 158 // Arm SVE2 extensions 159 bool HasSVE2AES = false; 160 bool HasSVE2SM4 = false; 161 bool HasSVE2SHA3 = false; 162 bool HasSVE2BitPerm = false; 163 164 // Future architecture extensions. 165 bool HasETE = false; 166 bool HasTRBE = false; 167 168 // HasZeroCycleRegMove - Has zero-cycle register mov instructions. 169 bool HasZeroCycleRegMove = false; 170 171 // HasZeroCycleZeroing - Has zero-cycle zeroing instructions. 172 bool HasZeroCycleZeroing = false; 173 bool HasZeroCycleZeroingGP = false; 174 bool HasZeroCycleZeroingFP = false; 175 bool HasZeroCycleZeroingFPWorkaround = false; 176 177 // StrictAlign - Disallow unaligned memory accesses. 178 bool StrictAlign = false; 179 180 // NegativeImmediates - transform instructions with negative immediates 181 bool NegativeImmediates = true; 182 183 // Enable 64-bit vectorization in SLP. 184 unsigned MinVectorRegisterBitWidth = 64; 185 186 bool UseAA = false; 187 bool PredictableSelectIsExpensive = false; 188 bool BalanceFPOps = false; 189 bool CustomAsCheapAsMove = false; 190 bool ExynosAsCheapAsMove = false; 191 bool UsePostRAScheduler = false; 192 bool Misaligned128StoreIsSlow = false; 193 bool Paired128IsSlow = false; 194 bool STRQroIsSlow = false; 195 bool UseAlternateSExtLoadCVTF32Pattern = false; 196 bool HasArithmeticBccFusion = false; 197 bool HasArithmeticCbzFusion = false; 198 bool HasFuseAddress = false; 199 bool HasFuseAES = false; 200 bool HasFuseArithmeticLogic = false; 201 bool HasFuseCCSelect = false; 202 bool HasFuseCryptoEOR = false; 203 bool HasFuseLiterals = false; 204 bool DisableLatencySchedHeuristic = false; 205 bool UseRSqrt = false; 206 bool Force32BitJumpTables = false; 207 bool UseEL1ForTP = false; 208 bool UseEL2ForTP = false; 209 bool UseEL3ForTP = false; 210 bool AllowTaggedGlobals = false; 211 uint8_t MaxInterleaveFactor = 2; 212 uint8_t VectorInsertExtractBaseCost = 3; 213 uint16_t CacheLineSize = 0; 214 uint16_t PrefetchDistance = 0; 215 uint16_t MinPrefetchStride = 1; 216 unsigned MaxPrefetchIterationsAhead = UINT_MAX; 217 unsigned PrefFunctionLogAlignment = 0; 218 unsigned PrefLoopLogAlignment = 0; 219 unsigned MaxJumpTableSize = 0; 220 unsigned WideningBaseCost = 0; 221 222 // ReserveXRegister[i] - X#i is not available as a general purpose register. 223 BitVector ReserveXRegister; 224 225 // CustomCallUsedXRegister[i] - X#i call saved. 226 BitVector CustomCallSavedXRegs; 227 228 bool IsLittle; 229 230 /// TargetTriple - What processor and OS we're targeting. 231 Triple TargetTriple; 232 233 AArch64FrameLowering FrameLowering; 234 AArch64InstrInfo InstrInfo; 235 AArch64SelectionDAGInfo TSInfo; 236 AArch64TargetLowering TLInfo; 237 238 /// GlobalISel related APIs. 239 std::unique_ptr<CallLowering> CallLoweringInfo; 240 std::unique_ptr<InlineAsmLowering> InlineAsmLoweringInfo; 241 std::unique_ptr<InstructionSelector> InstSelector; 242 std::unique_ptr<LegalizerInfo> Legalizer; 243 std::unique_ptr<RegisterBankInfo> RegBankInfo; 244 245 private: 246 /// initializeSubtargetDependencies - Initializes using CPUString and the 247 /// passed in feature string so that we can use initializer lists for 248 /// subtarget initialization. 249 AArch64Subtarget &initializeSubtargetDependencies(StringRef FS, 250 StringRef CPUString); 251 252 /// Initialize properties based on the selected processor family. 253 void initializeProperties(); 254 255 public: 256 /// This constructor initializes the data members to match that 257 /// of the specified triple. 258 AArch64Subtarget(const Triple &TT, const std::string &CPU, 259 const std::string &FS, const TargetMachine &TM, 260 bool LittleEndian); 261 262 const AArch64SelectionDAGInfo *getSelectionDAGInfo() const override { 263 return &TSInfo; 264 } 265 const AArch64FrameLowering *getFrameLowering() const override { 266 return &FrameLowering; 267 } 268 const AArch64TargetLowering *getTargetLowering() const override { 269 return &TLInfo; 270 } 271 const AArch64InstrInfo *getInstrInfo() const override { return &InstrInfo; } 272 const AArch64RegisterInfo *getRegisterInfo() const override { 273 return &getInstrInfo()->getRegisterInfo(); 274 } 275 const CallLowering *getCallLowering() const override; 276 const InlineAsmLowering *getInlineAsmLowering() const override; 277 InstructionSelector *getInstructionSelector() const override; 278 const LegalizerInfo *getLegalizerInfo() const override; 279 const RegisterBankInfo *getRegBankInfo() const override; 280 const Triple &getTargetTriple() const { return TargetTriple; } 281 bool enableMachineScheduler() const override { return true; } 282 bool enablePostRAScheduler() const override { 283 return UsePostRAScheduler; 284 } 285 286 /// Returns ARM processor family. 287 /// Avoid this function! CPU specifics should be kept local to this class 288 /// and preferably modeled with SubtargetFeatures or properties in 289 /// initializeProperties(). 290 ARMProcFamilyEnum getProcFamily() const { 291 return ARMProcFamily; 292 } 293 294 bool hasV8_1aOps() const { return HasV8_1aOps; } 295 bool hasV8_2aOps() const { return HasV8_2aOps; } 296 bool hasV8_3aOps() const { return HasV8_3aOps; } 297 bool hasV8_4aOps() const { return HasV8_4aOps; } 298 bool hasV8_5aOps() const { return HasV8_5aOps; } 299 300 bool hasZeroCycleRegMove() const { return HasZeroCycleRegMove; } 301 302 bool hasZeroCycleZeroingGP() const { return HasZeroCycleZeroingGP; } 303 304 bool hasZeroCycleZeroingFP() const { return HasZeroCycleZeroingFP; } 305 306 bool hasZeroCycleZeroingFPWorkaround() const { 307 return HasZeroCycleZeroingFPWorkaround; 308 } 309 310 bool requiresStrictAlign() const { return StrictAlign; } 311 312 bool isXRaySupported() const override { return true; } 313 314 unsigned getMinVectorRegisterBitWidth() const { 315 return MinVectorRegisterBitWidth; 316 } 317 318 bool isXRegisterReserved(size_t i) const { return ReserveXRegister[i]; } 319 unsigned getNumXRegisterReserved() const { return ReserveXRegister.count(); } 320 bool isXRegCustomCalleeSaved(size_t i) const { 321 return CustomCallSavedXRegs[i]; 322 } 323 bool hasCustomCallingConv() const { return CustomCallSavedXRegs.any(); } 324 bool hasFPARMv8() const { return HasFPARMv8; } 325 bool hasNEON() const { return HasNEON; } 326 bool hasCrypto() const { return HasCrypto; } 327 bool hasDotProd() const { return HasDotProd; } 328 bool hasCRC() const { return HasCRC; } 329 bool hasLSE() const { return HasLSE; } 330 bool hasRAS() const { return HasRAS; } 331 bool hasRDM() const { return HasRDM; } 332 bool hasSM4() const { return HasSM4; } 333 bool hasSHA3() const { return HasSHA3; } 334 bool hasSHA2() const { return HasSHA2; } 335 bool hasAES() const { return HasAES; } 336 bool balanceFPOps() const { return BalanceFPOps; } 337 bool predictableSelectIsExpensive() const { 338 return PredictableSelectIsExpensive; 339 } 340 bool hasCustomCheapAsMoveHandling() const { return CustomAsCheapAsMove; } 341 bool hasExynosCheapAsMoveHandling() const { return ExynosAsCheapAsMove; } 342 bool isMisaligned128StoreSlow() const { return Misaligned128StoreIsSlow; } 343 bool isPaired128Slow() const { return Paired128IsSlow; } 344 bool isSTRQroSlow() const { return STRQroIsSlow; } 345 bool useAlternateSExtLoadCVTF32Pattern() const { 346 return UseAlternateSExtLoadCVTF32Pattern; 347 } 348 bool hasArithmeticBccFusion() const { return HasArithmeticBccFusion; } 349 bool hasArithmeticCbzFusion() const { return HasArithmeticCbzFusion; } 350 bool hasFuseAddress() const { return HasFuseAddress; } 351 bool hasFuseAES() const { return HasFuseAES; } 352 bool hasFuseArithmeticLogic() const { return HasFuseArithmeticLogic; } 353 bool hasFuseCCSelect() const { return HasFuseCCSelect; } 354 bool hasFuseCryptoEOR() const { return HasFuseCryptoEOR; } 355 bool hasFuseLiterals() const { return HasFuseLiterals; } 356 357 /// Return true if the CPU supports any kind of instruction fusion. 358 bool hasFusion() const { 359 return hasArithmeticBccFusion() || hasArithmeticCbzFusion() || 360 hasFuseAES() || hasFuseArithmeticLogic() || 361 hasFuseCCSelect() || hasFuseLiterals(); 362 } 363 364 bool useEL1ForTP() const { return UseEL1ForTP; } 365 bool useEL2ForTP() const { return UseEL2ForTP; } 366 bool useEL3ForTP() const { return UseEL3ForTP; } 367 368 bool useRSqrt() const { return UseRSqrt; } 369 bool force32BitJumpTables() const { return Force32BitJumpTables; } 370 unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; } 371 unsigned getVectorInsertExtractBaseCost() const { 372 return VectorInsertExtractBaseCost; 373 } 374 unsigned getCacheLineSize() const override { return CacheLineSize; } 375 unsigned getPrefetchDistance() const override { return PrefetchDistance; } 376 unsigned getMinPrefetchStride(unsigned NumMemAccesses, 377 unsigned NumStridedMemAccesses, 378 unsigned NumPrefetches, 379 bool HasCall) const override { 380 return MinPrefetchStride; 381 } 382 unsigned getMaxPrefetchIterationsAhead() const override { 383 return MaxPrefetchIterationsAhead; 384 } 385 unsigned getPrefFunctionLogAlignment() const { 386 return PrefFunctionLogAlignment; 387 } 388 unsigned getPrefLoopLogAlignment() const { return PrefLoopLogAlignment; } 389 390 unsigned getMaximumJumpTableSize() const { return MaxJumpTableSize; } 391 392 unsigned getWideningBaseCost() const { return WideningBaseCost; } 393 394 /// CPU has TBI (top byte of addresses is ignored during HW address 395 /// translation) and OS enables it. 396 bool supportsAddressTopByteIgnored() const; 397 398 bool hasPerfMon() const { return HasPerfMon; } 399 bool hasFullFP16() const { return HasFullFP16; } 400 bool hasFP16FML() const { return HasFP16FML; } 401 bool hasSPE() const { return HasSPE; } 402 bool hasLSLFast() const { return HasLSLFast; } 403 bool hasSVE() const { return HasSVE; } 404 bool hasSVE2() const { return HasSVE2; } 405 bool hasRCPC() const { return HasRCPC; } 406 bool hasAggressiveFMA() const { return HasAggressiveFMA; } 407 bool hasAlternativeNZCV() const { return HasAlternativeNZCV; } 408 bool hasFRInt3264() const { return HasFRInt3264; } 409 bool hasSpecRestrict() const { return HasSpecRestrict; } 410 bool hasSSBS() const { return HasSSBS; } 411 bool hasSB() const { return HasSB; } 412 bool hasPredRes() const { return HasPredRes; } 413 bool hasCCDP() const { return HasCCDP; } 414 bool hasBTI() const { return HasBTI; } 415 bool hasRandGen() const { return HasRandGen; } 416 bool hasMTE() const { return HasMTE; } 417 bool hasTME() const { return HasTME; } 418 // Arm SVE2 extensions 419 bool hasSVE2AES() const { return HasSVE2AES; } 420 bool hasSVE2SM4() const { return HasSVE2SM4; } 421 bool hasSVE2SHA3() const { return HasSVE2SHA3; } 422 bool hasSVE2BitPerm() const { return HasSVE2BitPerm; } 423 bool hasMatMulInt8() const { return HasMatMulInt8; } 424 bool hasMatMulFP32() const { return HasMatMulFP32; } 425 bool hasMatMulFP64() const { return HasMatMulFP64; } 426 427 // Armv8.6-A Extensions 428 bool hasBF16() const { return HasBF16; } 429 bool hasFineGrainedTraps() const { return HasFineGrainedTraps; } 430 bool hasEnhancedCounterVirtualization() const { 431 return HasEnhancedCounterVirtualization; 432 } 433 434 bool isLittleEndian() const { return IsLittle; } 435 436 bool isTargetDarwin() const { return TargetTriple.isOSDarwin(); } 437 bool isTargetIOS() const { return TargetTriple.isiOS(); } 438 bool isTargetLinux() const { return TargetTriple.isOSLinux(); } 439 bool isTargetWindows() const { return TargetTriple.isOSWindows(); } 440 bool isTargetAndroid() const { return TargetTriple.isAndroid(); } 441 bool isTargetFuchsia() const { return TargetTriple.isOSFuchsia(); } 442 443 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); } 444 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); } 445 bool isTargetMachO() const { return TargetTriple.isOSBinFormatMachO(); } 446 447 bool isTargetILP32() const { return TargetTriple.isArch32Bit(); } 448 449 bool useAA() const override { return UseAA; } 450 451 bool hasVH() const { return HasVH; } 452 bool hasPAN() const { return HasPAN; } 453 bool hasLOR() const { return HasLOR; } 454 455 bool hasPsUAO() const { return HasPsUAO; } 456 bool hasPAN_RWV() const { return HasPAN_RWV; } 457 bool hasCCPP() const { return HasCCPP; } 458 459 bool hasPA() const { return HasPA; } 460 bool hasJS() const { return HasJS; } 461 bool hasCCIDX() const { return HasCCIDX; } 462 bool hasComplxNum() const { return HasComplxNum; } 463 464 bool hasNV() const { return HasNV; } 465 bool hasRASv8_4() const { return HasRASv8_4; } 466 bool hasMPAM() const { return HasMPAM; } 467 bool hasDIT() const { return HasDIT; } 468 bool hasTRACEV8_4() const { return HasTRACEV8_4; } 469 bool hasAM() const { return HasAM; } 470 bool hasAMVS() const { return HasAMVS; } 471 bool hasSEL2() const { return HasSEL2; } 472 bool hasPMU() const { return HasPMU; } 473 bool hasTLB_RMI() const { return HasTLB_RMI; } 474 bool hasFMI() const { return HasFMI; } 475 bool hasRCPC_IMMO() const { return HasRCPC_IMMO; } 476 477 bool addrSinkUsingGEPs() const override { 478 // Keeping GEPs inbounds is important for exploiting AArch64 479 // addressing-modes in ILP32 mode. 480 return useAA() || isTargetILP32(); 481 } 482 483 bool useSmallAddressing() const { 484 switch (TLInfo.getTargetMachine().getCodeModel()) { 485 case CodeModel::Kernel: 486 // Kernel is currently allowed only for Fuchsia targets, 487 // where it is the same as Small for almost all purposes. 488 case CodeModel::Small: 489 return true; 490 default: 491 return false; 492 } 493 } 494 495 /// ParseSubtargetFeatures - Parses features string setting specified 496 /// subtarget options. Definition of function is auto generated by tblgen. 497 void ParseSubtargetFeatures(StringRef CPU, StringRef FS); 498 499 /// ClassifyGlobalReference - Find the target operand flags that describe 500 /// how a global value should be referenced for the current subtarget. 501 unsigned ClassifyGlobalReference(const GlobalValue *GV, 502 const TargetMachine &TM) const; 503 504 unsigned classifyGlobalFunctionReference(const GlobalValue *GV, 505 const TargetMachine &TM) const; 506 507 void overrideSchedPolicy(MachineSchedPolicy &Policy, 508 unsigned NumRegionInstrs) const override; 509 510 bool enableEarlyIfConversion() const override; 511 512 bool enableAdvancedRASplitCost() const override { return true; } 513 514 std::unique_ptr<PBQPRAConstraint> getCustomPBQPConstraints() const override; 515 516 bool isCallingConvWin64(CallingConv::ID CC) const { 517 switch (CC) { 518 case CallingConv::C: 519 case CallingConv::Fast: 520 case CallingConv::Swift: 521 return isTargetWindows(); 522 case CallingConv::Win64: 523 return true; 524 default: 525 return false; 526 } 527 } 528 529 void mirFileLoaded(MachineFunction &MF) const override; 530 }; 531 } // End llvm namespace 532 533 #endif 534