| 1 | //===--- AArch64.h - Declare AArch64 target feature support -----*- 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 AArch64 TargetInfo objects. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H |
| 14 | #define LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H |
| 15 | |
| 16 | #include "OSTargets.h" |
| 17 | #include "clang/Basic/TargetBuiltins.h" |
| 18 | #include "llvm/ADT/DenseSet.h" |
| 19 | #include "llvm/TargetParser/AArch64TargetParser.h" |
| 20 | #include <optional> |
| 21 | |
| 22 | namespace clang { |
| 23 | namespace targets { |
| 24 | |
| 25 | enum AArch64AddrSpace { ptr32_sptr = 270, ptr32_uptr = 271, ptr64 = 272 }; |
| 26 | |
| 27 | static const unsigned ARM64AddrSpaceMap[] = { |
| 28 | 0, // Default |
| 29 | 0, // opencl_global |
| 30 | 0, // opencl_local |
| 31 | 0, // opencl_constant |
| 32 | 0, // opencl_private |
| 33 | 0, // opencl_generic |
| 34 | 0, // opencl_global_device |
| 35 | 0, // opencl_global_host |
| 36 | 0, // cuda_device |
| 37 | 0, // cuda_constant |
| 38 | 0, // cuda_shared |
| 39 | 0, // sycl_global |
| 40 | 0, // sycl_global_device |
| 41 | 0, // sycl_global_host |
| 42 | 0, // sycl_local |
| 43 | 0, // sycl_private |
| 44 | static_cast<unsigned>(AArch64AddrSpace::ptr32_sptr), |
| 45 | static_cast<unsigned>(AArch64AddrSpace::ptr32_uptr), |
| 46 | static_cast<unsigned>(AArch64AddrSpace::ptr64), |
| 47 | 0, // hlsl_groupshared |
| 48 | 0, // hlsl_constant |
| 49 | 0, // hlsl_private |
| 50 | 0, // hlsl_device |
| 51 | 0, // hlsl_input |
| 52 | 0, // hlsl_push_constant |
| 53 | // Wasm address space values for this target are dummy values, |
| 54 | // as it is only enabled for Wasm targets. |
| 55 | 20, // wasm_funcref |
| 56 | }; |
| 57 | |
| 58 | using AArch64FeatureSet = llvm::SmallDenseSet<StringRef, 32>; |
| 59 | |
| 60 | class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo { |
| 61 | static const TargetInfo::GCCRegAlias GCCRegAliases[]; |
| 62 | static const char *const GCCRegNames[]; |
| 63 | |
| 64 | enum FPUModeEnum { |
| 65 | FPUMode = (1 << 0), |
| 66 | NeonMode = (1 << 1), |
| 67 | SveMode = (1 << 2), |
| 68 | }; |
| 69 | |
| 70 | unsigned FPU = FPUMode; |
| 71 | bool HasCRC = false; |
| 72 | bool HasCSSC = false; |
| 73 | bool HasAES = false; |
| 74 | bool HasSHA2 = false; |
| 75 | bool HasSHA3 = false; |
| 76 | bool HasSM4 = false; |
| 77 | bool HasFullFP16 = false; |
| 78 | bool HasDotProd = false; |
| 79 | bool HasFP16FML = false; |
| 80 | bool HasMTE = false; |
| 81 | bool HasPAuth = false; |
| 82 | bool HasLS64 = false; |
| 83 | bool HasRandGen = false; |
| 84 | bool HasMatMul = false; |
| 85 | bool HasBFloat16 = false; |
| 86 | bool HasSVE2 = false; |
| 87 | bool HasSVE2p1 = false; |
| 88 | bool HasSVEAES = false; |
| 89 | bool HasSVE2SHA3 = false; |
| 90 | bool HasSVE2SM4 = false; |
| 91 | bool HasSVEB16B16 = false; |
| 92 | bool HasSVEBitPerm = false; |
| 93 | bool HasMatmulFP64 = false; |
| 94 | bool HasMatmulFP32 = false; |
| 95 | bool HasLSE = false; |
| 96 | bool HasFlagM = false; |
| 97 | bool HasAlternativeNZCV = false; |
| 98 | bool HasMOPS = false; |
| 99 | bool HasD128 = false; |
| 100 | bool HasRCPC = false; |
| 101 | bool HasRDM = false; |
| 102 | bool HasDIT = false; |
| 103 | bool HasCCPP = false; |
| 104 | bool HasCCDP = false; |
| 105 | bool HasFRInt3264 = false; |
| 106 | bool HasSME = false; |
| 107 | bool HasSME2 = false; |
| 108 | bool HasSMEF64F64 = false; |
| 109 | bool HasSMEI16I64 = false; |
| 110 | bool HasSMEF16F16 = false; |
| 111 | bool HasSMEB16B16 = false; |
| 112 | bool HasSME2p1 = false; |
| 113 | bool HasFP8 = false; |
| 114 | bool HasFP8FMA = false; |
| 115 | bool HasFP8DOT2 = false; |
| 116 | bool HasFP8DOT4 = false; |
| 117 | bool HasSSVE_FP8DOT2 = false; |
| 118 | bool HasSSVE_FP8DOT4 = false; |
| 119 | bool HasSSVE_FP8FMA = false; |
| 120 | bool HasSME_F8F32 = false; |
| 121 | bool HasSME_F8F16 = false; |
| 122 | bool HasSB = false; |
| 123 | bool HasPredRes = false; |
| 124 | bool HasSSBS = false; |
| 125 | bool HasBTI = false; |
| 126 | bool HasWFxT = false; |
| 127 | bool HasJSCVT = false; |
| 128 | bool HasFCMA = false; |
| 129 | bool HasNoFP = false; |
| 130 | bool HasNoNeon = false; |
| 131 | bool HasNoSVE = false; |
| 132 | bool HasFMV = true; |
| 133 | bool HasGCS = false; |
| 134 | bool HasRCPC3 = false; |
| 135 | bool HasSMEFA64 = false; |
| 136 | bool HasPAuthLR = false; |
| 137 | bool HasFPRCVT = false; |
| 138 | bool HasF8F16MM = false; |
| 139 | bool HasF8F32MM = false; |
| 140 | bool HasSVE_F16F32MM = false; |
| 141 | bool HasSVE_BFSCALE = false; |
| 142 | bool HasSVE_AES2 = false; |
| 143 | bool HasSSVE_AES = false; |
| 144 | bool HasSVE2p2 = false; |
| 145 | bool HasSME2p2 = false; |
| 146 | |
| 147 | const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A; |
| 148 | |
| 149 | AArch64FeatureSet HasFeatureLookup; |
| 150 | |
| 151 | void computeFeatureLookup(); |
| 152 | |
| 153 | protected: |
| 154 | std::string ABI; |
| 155 | |
| 156 | public: |
| 157 | AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); |
| 158 | |
| 159 | StringRef getABI() const override; |
| 160 | bool setABI(const std::string &Name) override; |
| 161 | |
| 162 | bool validateBranchProtection(StringRef Spec, StringRef Arch, |
| 163 | BranchProtectionInfo &BPI, |
| 164 | const LangOptions &LO, |
| 165 | StringRef &Err) const override; |
| 166 | |
| 167 | bool isValidCPUName(StringRef Name) const override; |
| 168 | void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; |
| 169 | bool setCPU(const std::string &Name) override; |
| 170 | |
| 171 | llvm::APInt getFMVPriority(ArrayRef<StringRef> Features) const override; |
| 172 | |
| 173 | bool useFP16ConversionIntrinsics() const override { |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | void getTargetDefinesARMV81A(const LangOptions &Opts, |
| 178 | MacroBuilder &Builder) const; |
| 179 | void getTargetDefinesARMV82A(const LangOptions &Opts, |
| 180 | MacroBuilder &Builder) const; |
| 181 | void getTargetDefinesARMV83A(const LangOptions &Opts, |
| 182 | MacroBuilder &Builder) const; |
| 183 | void getTargetDefinesARMV84A(const LangOptions &Opts, |
| 184 | MacroBuilder &Builder) const; |
| 185 | void getTargetDefinesARMV85A(const LangOptions &Opts, |
| 186 | MacroBuilder &Builder) const; |
| 187 | void getTargetDefinesARMV86A(const LangOptions &Opts, |
| 188 | MacroBuilder &Builder) const; |
| 189 | void getTargetDefinesARMV87A(const LangOptions &Opts, |
| 190 | MacroBuilder &Builder) const; |
| 191 | void getTargetDefinesARMV88A(const LangOptions &Opts, |
| 192 | MacroBuilder &Builder) const; |
| 193 | void getTargetDefinesARMV89A(const LangOptions &Opts, |
| 194 | MacroBuilder &Builder) const; |
| 195 | void getTargetDefinesARMV9A(const LangOptions &Opts, |
| 196 | MacroBuilder &Builder) const; |
| 197 | void getTargetDefinesARMV91A(const LangOptions &Opts, |
| 198 | MacroBuilder &Builder) const; |
| 199 | void getTargetDefinesARMV92A(const LangOptions &Opts, |
| 200 | MacroBuilder &Builder) const; |
| 201 | void getTargetDefinesARMV93A(const LangOptions &Opts, |
| 202 | MacroBuilder &Builder) const; |
| 203 | void getTargetDefinesARMV94A(const LangOptions &Opts, |
| 204 | MacroBuilder &Builder) const; |
| 205 | void getTargetDefinesARMV95A(const LangOptions &Opts, |
| 206 | MacroBuilder &Builder) const; |
| 207 | void getTargetDefinesARMV96A(const LangOptions &Opts, |
| 208 | MacroBuilder &Builder) const; |
| 209 | void getTargetDefinesARMV97A(const LangOptions &Opts, |
| 210 | MacroBuilder &Builder) const; |
| 211 | void getTargetDefines(const LangOptions &Opts, |
| 212 | MacroBuilder &Builder) const override; |
| 213 | |
| 214 | llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override; |
| 215 | |
| 216 | std::optional<std::pair<unsigned, unsigned>> |
| 217 | getVScaleRange(const LangOptions &LangOpts, ArmStreamingKind Mode, |
| 218 | llvm::StringMap<bool> *FeatureMap = nullptr) const override; |
| 219 | bool doesFeatureAffectCodeGen(StringRef Name) const override; |
| 220 | bool validateCpuSupports(StringRef FeatureStr) const override; |
| 221 | bool hasFeature(StringRef Feature) const override; |
| 222 | void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name, |
| 223 | bool Enabled) const override; |
| 224 | bool handleTargetFeatures(std::vector<std::string> &Features, |
| 225 | DiagnosticsEngine &Diags) override; |
| 226 | ParsedTargetAttr parseTargetAttr(StringRef Str) const override; |
| 227 | bool supportsTargetAttributeTune() const override { return true; } |
| 228 | bool supportsCpuSupports() const override { return true; } |
| 229 | bool checkArithmeticFenceSupported() const override { return true; } |
| 230 | |
| 231 | bool hasBFloat16Type() const override; |
| 232 | |
| 233 | CallingConvCheckResult checkCallingConvention(CallingConv CC) const override; |
| 234 | |
| 235 | bool isCLZForZeroUndef() const override; |
| 236 | |
| 237 | BuiltinVaListKind getBuiltinVaListKind() const override; |
| 238 | |
| 239 | ArrayRef<const char *> getGCCRegNames() const override; |
| 240 | ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; |
| 241 | |
| 242 | std::string convertConstraint(const char *&Constraint) const override; |
| 243 | |
| 244 | bool validateAsmConstraint(const char *&Name, |
| 245 | TargetInfo::ConstraintInfo &Info) const override; |
| 246 | bool |
| 247 | validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size, |
| 248 | std::string &SuggestedModifier) const override; |
| 249 | std::string_view getClobbers() const override; |
| 250 | |
| 251 | StringRef getConstraintRegister(StringRef Constraint, |
| 252 | StringRef Expression) const override { |
| 253 | return Expression; |
| 254 | } |
| 255 | |
| 256 | int getEHDataRegisterNumber(unsigned RegNo) const override; |
| 257 | |
| 258 | bool validatePointerAuthKey(const llvm::APSInt &value) const override; |
| 259 | |
| 260 | const char *getBFloat16Mangling() const override { return "u6__bf16" ; }; |
| 261 | |
| 262 | std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override { |
| 263 | return std::make_pair(x: 256, y: 64); |
| 264 | } |
| 265 | |
| 266 | bool hasInt128Type() const override; |
| 267 | |
| 268 | bool hasBitIntType() const override { return true; } |
| 269 | |
| 270 | bool validateTarget(DiagnosticsEngine &Diags) const override; |
| 271 | |
| 272 | bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize, |
| 273 | bool &HasSizeMismatch) const override; |
| 274 | |
| 275 | uint64_t getPointerWidthV(LangAS AddrSpace) const override { |
| 276 | if (AddrSpace == LangAS::ptr32_sptr || AddrSpace == LangAS::ptr32_uptr) |
| 277 | return 32; |
| 278 | if (AddrSpace == LangAS::ptr64) |
| 279 | return 64; |
| 280 | return PointerWidth; |
| 281 | } |
| 282 | |
| 283 | uint64_t getPointerAlignV(LangAS AddrSpace) const override { |
| 284 | return getPointerWidthV(AddrSpace); |
| 285 | } |
| 286 | }; |
| 287 | |
| 288 | class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo { |
| 289 | public: |
| 290 | AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); |
| 291 | |
| 292 | void getTargetDefines(const LangOptions &Opts, |
| 293 | MacroBuilder &Builder) const override; |
| 294 | }; |
| 295 | |
| 296 | template <> |
| 297 | inline bool |
| 298 | LinuxTargetInfo<AArch64leTargetInfo>::setABI(const std::string &Name) { |
| 299 | if (Name == "pauthtest" ) { |
| 300 | ABI = Name; |
| 301 | return true; |
| 302 | } |
| 303 | return AArch64leTargetInfo::setABI(Name); |
| 304 | } |
| 305 | |
| 306 | class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo |
| 307 | : public WindowsTargetInfo<AArch64leTargetInfo> { |
| 308 | const llvm::Triple Triple; |
| 309 | |
| 310 | public: |
| 311 | WindowsARM64TargetInfo(const llvm::Triple &Triple, |
| 312 | const TargetOptions &Opts); |
| 313 | |
| 314 | BuiltinVaListKind getBuiltinVaListKind() const override; |
| 315 | |
| 316 | CallingConvCheckResult checkCallingConvention(CallingConv CC) const override; |
| 317 | }; |
| 318 | |
| 319 | // Windows ARM, MS (C++) ABI |
| 320 | class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo |
| 321 | : public WindowsARM64TargetInfo { |
| 322 | public: |
| 323 | MicrosoftARM64TargetInfo(const llvm::Triple &Triple, |
| 324 | const TargetOptions &Opts); |
| 325 | |
| 326 | void getTargetDefines(const LangOptions &Opts, |
| 327 | MacroBuilder &Builder) const override; |
| 328 | TargetInfo::CallingConvKind |
| 329 | getCallingConvKind(bool ClangABICompat4) const override; |
| 330 | |
| 331 | unsigned getMinGlobalAlign(uint64_t TypeSize, |
| 332 | bool HasNonWeakDef) const override; |
| 333 | }; |
| 334 | |
| 335 | // ARM64 MinGW target |
| 336 | class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo |
| 337 | : public WindowsARM64TargetInfo { |
| 338 | public: |
| 339 | MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); |
| 340 | }; |
| 341 | |
| 342 | class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo { |
| 343 | public: |
| 344 | AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); |
| 345 | void getTargetDefines(const LangOptions &Opts, |
| 346 | MacroBuilder &Builder) const override; |
| 347 | }; |
| 348 | |
| 349 | void getAppleMachOAArch64Defines(MacroBuilder &Builder, const LangOptions &Opts, |
| 350 | const llvm::Triple &Triple); |
| 351 | |
| 352 | class LLVM_LIBRARY_VISIBILITY AppleMachOAArch64TargetInfo |
| 353 | : public AppleMachOTargetInfo<AArch64leTargetInfo> { |
| 354 | public: |
| 355 | AppleMachOAArch64TargetInfo(const llvm::Triple &Triple, |
| 356 | const TargetOptions &Opts); |
| 357 | |
| 358 | protected: |
| 359 | void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
| 360 | MacroBuilder &Builder) const override; |
| 361 | }; |
| 362 | |
| 363 | class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo |
| 364 | : public DarwinTargetInfo<AArch64leTargetInfo> { |
| 365 | public: |
| 366 | DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); |
| 367 | |
| 368 | BuiltinVaListKind getBuiltinVaListKind() const override; |
| 369 | |
| 370 | protected: |
| 371 | void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, |
| 372 | MacroBuilder &Builder) const override; |
| 373 | }; |
| 374 | |
| 375 | } // namespace targets |
| 376 | } // namespace clang |
| 377 | |
| 378 | #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H |
| 379 | |