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