xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/AArch64.h (revision 6c4b055cfb6bf549e9145dde6454cc6b178c35e4)
10b57cec5SDimitry Andric //===--- AArch64.h - Declare AArch64 target feature support -----*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file declares AArch64 TargetInfo objects.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
140b57cec5SDimitry Andric #define LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "OSTargets.h"
170b57cec5SDimitry Andric #include "clang/Basic/TargetBuiltins.h"
1806c3fb27SDimitry Andric #include "llvm/TargetParser/AArch64TargetParser.h"
19bdd1243dSDimitry Andric #include <optional>
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace clang {
220b57cec5SDimitry Andric namespace targets {
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo {
250b57cec5SDimitry Andric   virtual void setDataLayout() = 0;
260b57cec5SDimitry Andric   static const TargetInfo::GCCRegAlias GCCRegAliases[];
270b57cec5SDimitry Andric   static const char *const GCCRegNames[];
280b57cec5SDimitry Andric 
2906c3fb27SDimitry Andric   enum FPUModeEnum {
3006c3fb27SDimitry Andric     FPUMode = (1 << 0),
3106c3fb27SDimitry Andric     NeonMode = (1 << 1),
3206c3fb27SDimitry Andric     SveMode = (1 << 2),
3306c3fb27SDimitry Andric   };
340b57cec5SDimitry Andric 
35bdd1243dSDimitry Andric   unsigned FPU = FPUMode;
36bdd1243dSDimitry Andric   bool HasCRC = false;
37bdd1243dSDimitry Andric   bool HasAES = false;
38bdd1243dSDimitry Andric   bool HasSHA2 = false;
39bdd1243dSDimitry Andric   bool HasSHA3 = false;
40bdd1243dSDimitry Andric   bool HasSM4 = false;
41bdd1243dSDimitry Andric   bool HasFullFP16 = false;
42bdd1243dSDimitry Andric   bool HasDotProd = false;
43bdd1243dSDimitry Andric   bool HasFP16FML = false;
44bdd1243dSDimitry Andric   bool HasMTE = false;
45bdd1243dSDimitry Andric   bool HasTME = false;
46bdd1243dSDimitry Andric   bool HasPAuth = false;
47bdd1243dSDimitry Andric   bool HasLS64 = false;
48bdd1243dSDimitry Andric   bool HasRandGen = false;
49bdd1243dSDimitry Andric   bool HasMatMul = false;
50bdd1243dSDimitry Andric   bool HasBFloat16 = false;
51bdd1243dSDimitry Andric   bool HasSVE2 = false;
520fca6ea1SDimitry Andric   bool HasSVE2p1 = false;
53bdd1243dSDimitry Andric   bool HasSVE2AES = false;
54bdd1243dSDimitry Andric   bool HasSVE2SHA3 = false;
55bdd1243dSDimitry Andric   bool HasSVE2SM4 = false;
56*6c4b055cSDimitry Andric   bool HasSVEB16B16 = false;
57bdd1243dSDimitry Andric   bool HasSVE2BitPerm = false;
58bdd1243dSDimitry Andric   bool HasMatmulFP64 = false;
59bdd1243dSDimitry Andric   bool HasMatmulFP32 = false;
60bdd1243dSDimitry Andric   bool HasLSE = false;
61bdd1243dSDimitry Andric   bool HasFlagM = false;
62bdd1243dSDimitry Andric   bool HasAlternativeNZCV = false;
63bdd1243dSDimitry Andric   bool HasMOPS = false;
64bdd1243dSDimitry Andric   bool HasD128 = false;
65bdd1243dSDimitry Andric   bool HasRCPC = false;
66bdd1243dSDimitry Andric   bool HasRDM = false;
67bdd1243dSDimitry Andric   bool HasDIT = false;
68bdd1243dSDimitry Andric   bool HasCCPP = false;
69bdd1243dSDimitry Andric   bool HasCCDP = false;
70bdd1243dSDimitry Andric   bool HasFRInt3264 = false;
71bdd1243dSDimitry Andric   bool HasSME = false;
72b3edf446SDimitry Andric   bool HasSME2 = false;
7306c3fb27SDimitry Andric   bool HasSMEF64F64 = false;
7406c3fb27SDimitry Andric   bool HasSMEI16I64 = false;
75*6c4b055cSDimitry Andric   bool HasSMEF16F16 = false;
76*6c4b055cSDimitry Andric   bool HasSMEB16B16 = false;
770fca6ea1SDimitry Andric   bool HasSME2p1 = false;
78bdd1243dSDimitry Andric   bool HasSB = false;
79bdd1243dSDimitry Andric   bool HasPredRes = false;
80bdd1243dSDimitry Andric   bool HasSSBS = false;
81bdd1243dSDimitry Andric   bool HasBTI = false;
82bdd1243dSDimitry Andric   bool HasWFxT = false;
83bdd1243dSDimitry Andric   bool HasJSCVT = false;
84bdd1243dSDimitry Andric   bool HasFCMA = false;
8506c3fb27SDimitry Andric   bool HasNoFP = false;
86bdd1243dSDimitry Andric   bool HasNoNeon = false;
87bdd1243dSDimitry Andric   bool HasNoSVE = false;
88bdd1243dSDimitry Andric   bool HasFMV = true;
8906c3fb27SDimitry Andric   bool HasGCS = false;
9006c3fb27SDimitry Andric   bool HasRCPC3 = false;
915f757f3fSDimitry Andric   bool HasSMEFA64 = false;
920fca6ea1SDimitry Andric   bool HasPAuthLR = false;
930b57cec5SDimitry Andric 
94bdd1243dSDimitry Andric   const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   std::string ABI;
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric public:
990b57cec5SDimitry Andric   AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   StringRef getABI() const override;
1020b57cec5SDimitry Andric   bool setABI(const std::string &Name) override;
1030b57cec5SDimitry Andric 
1041fd87a68SDimitry Andric   bool validateBranchProtection(StringRef Spec, StringRef Arch,
1051fd87a68SDimitry Andric                                 BranchProtectionInfo &BPI,
1061fd87a68SDimitry Andric                                 StringRef &Err) const override;
107480093f4SDimitry Andric 
1080b57cec5SDimitry Andric   bool isValidCPUName(StringRef Name) const override;
1090b57cec5SDimitry Andric   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
1100b57cec5SDimitry Andric   bool setCPU(const std::string &Name) override;
1110b57cec5SDimitry Andric 
112bdd1243dSDimitry Andric   unsigned multiVersionSortPriority(StringRef Name) const override;
113bdd1243dSDimitry Andric   unsigned multiVersionFeatureCost() const override;
114bdd1243dSDimitry Andric 
useFP16ConversionIntrinsics()1150b57cec5SDimitry Andric   bool useFP16ConversionIntrinsics() const override {
1160b57cec5SDimitry Andric     return false;
1170b57cec5SDimitry Andric   }
1180b57cec5SDimitry Andric 
119bdd1243dSDimitry Andric   void setArchFeatures();
120bdd1243dSDimitry Andric 
1210b57cec5SDimitry Andric   void getTargetDefinesARMV81A(const LangOptions &Opts,
1220b57cec5SDimitry Andric                                MacroBuilder &Builder) const;
1230b57cec5SDimitry Andric   void getTargetDefinesARMV82A(const LangOptions &Opts,
1240b57cec5SDimitry Andric                                MacroBuilder &Builder) const;
1250b57cec5SDimitry Andric   void getTargetDefinesARMV83A(const LangOptions &Opts,
1260b57cec5SDimitry Andric                                MacroBuilder &Builder) const;
1270b57cec5SDimitry Andric   void getTargetDefinesARMV84A(const LangOptions &Opts,
1280b57cec5SDimitry Andric                                MacroBuilder &Builder) const;
1290b57cec5SDimitry Andric   void getTargetDefinesARMV85A(const LangOptions &Opts,
1300b57cec5SDimitry Andric                                MacroBuilder &Builder) const;
1315ffd83dbSDimitry Andric   void getTargetDefinesARMV86A(const LangOptions &Opts,
1325ffd83dbSDimitry Andric                                MacroBuilder &Builder) const;
133e8d8bef9SDimitry Andric   void getTargetDefinesARMV87A(const LangOptions &Opts,
134e8d8bef9SDimitry Andric                                MacroBuilder &Builder) const;
13504eeddc0SDimitry Andric   void getTargetDefinesARMV88A(const LangOptions &Opts,
13604eeddc0SDimitry Andric                                MacroBuilder &Builder) const;
137bdd1243dSDimitry Andric   void getTargetDefinesARMV89A(const LangOptions &Opts,
138bdd1243dSDimitry Andric                                MacroBuilder &Builder) const;
139349cc55cSDimitry Andric   void getTargetDefinesARMV9A(const LangOptions &Opts,
140349cc55cSDimitry Andric                               MacroBuilder &Builder) const;
141349cc55cSDimitry Andric   void getTargetDefinesARMV91A(const LangOptions &Opts,
142349cc55cSDimitry Andric                                MacroBuilder &Builder) const;
143349cc55cSDimitry Andric   void getTargetDefinesARMV92A(const LangOptions &Opts,
144349cc55cSDimitry Andric                                MacroBuilder &Builder) const;
14504eeddc0SDimitry Andric   void getTargetDefinesARMV93A(const LangOptions &Opts,
14604eeddc0SDimitry Andric                                MacroBuilder &Builder) const;
147bdd1243dSDimitry Andric   void getTargetDefinesARMV94A(const LangOptions &Opts,
148bdd1243dSDimitry Andric                                MacroBuilder &Builder) const;
1495f757f3fSDimitry Andric   void getTargetDefinesARMV95A(const LangOptions &Opts,
1505f757f3fSDimitry Andric                                MacroBuilder &Builder) const;
1510b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
1520b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
1530b57cec5SDimitry Andric 
1540b57cec5SDimitry Andric   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
1550b57cec5SDimitry Andric 
156bdd1243dSDimitry Andric   std::optional<std::pair<unsigned, unsigned>>
157349cc55cSDimitry Andric   getVScaleRange(const LangOptions &LangOpts) const override;
15806c3fb27SDimitry Andric   bool doesFeatureAffectCodeGen(StringRef Name) const override;
159bdd1243dSDimitry Andric   bool validateCpuSupports(StringRef FeatureStr) const override;
1600b57cec5SDimitry Andric   bool hasFeature(StringRef Feature) const override;
161bdd1243dSDimitry Andric   void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
162bdd1243dSDimitry Andric                          bool Enabled) const override;
1630b57cec5SDimitry Andric   bool handleTargetFeatures(std::vector<std::string> &Features,
1640b57cec5SDimitry Andric                             DiagnosticsEngine &Diags) override;
165bdd1243dSDimitry Andric   ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
supportsTargetAttributeTune()166bdd1243dSDimitry Andric   bool supportsTargetAttributeTune() const override { return true; }
supportsCpuSupports()1670fca6ea1SDimitry Andric   bool supportsCpuSupports() const override { return true; }
checkArithmeticFenceSupported()16806c3fb27SDimitry Andric   bool checkArithmeticFenceSupported() const override { return true; }
16906c3fb27SDimitry Andric 
170bdd1243dSDimitry Andric   bool hasBFloat16Type() const override;
1710b57cec5SDimitry Andric 
1720b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
1730b57cec5SDimitry Andric 
1740b57cec5SDimitry Andric   bool isCLZForZeroUndef() const override;
1750b57cec5SDimitry Andric 
1760b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override;
1770b57cec5SDimitry Andric 
1780b57cec5SDimitry Andric   ArrayRef<const char *> getGCCRegNames() const override;
1790b57cec5SDimitry Andric   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
1805ffd83dbSDimitry Andric 
18106c3fb27SDimitry Andric   std::string convertConstraint(const char *&Constraint) const override;
1825ffd83dbSDimitry Andric 
1830b57cec5SDimitry Andric   bool validateAsmConstraint(const char *&Name,
1840b57cec5SDimitry Andric                              TargetInfo::ConstraintInfo &Info) const override;
1850b57cec5SDimitry Andric   bool
1860b57cec5SDimitry Andric   validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
1870b57cec5SDimitry Andric                              std::string &SuggestedModifier) const override;
18806c3fb27SDimitry Andric   std::string_view getClobbers() const override;
1890b57cec5SDimitry Andric 
getConstraintRegister(StringRef Constraint,StringRef Expression)1900b57cec5SDimitry Andric   StringRef getConstraintRegister(StringRef Constraint,
1910b57cec5SDimitry Andric                                   StringRef Expression) const override {
1920b57cec5SDimitry Andric     return Expression;
1930b57cec5SDimitry Andric   }
1940b57cec5SDimitry Andric 
1950b57cec5SDimitry Andric   int getEHDataRegisterNumber(unsigned RegNo) const override;
196480093f4SDimitry Andric 
1970fca6ea1SDimitry Andric   bool validatePointerAuthKey(const llvm::APSInt &value) const override;
1980fca6ea1SDimitry Andric 
getBFloat16Mangling()1995ffd83dbSDimitry Andric   const char *getBFloat16Mangling() const override { return "u6__bf16"; };
200480093f4SDimitry Andric   bool hasInt128Type() const override;
2015ffd83dbSDimitry Andric 
hasBitIntType()2020eae32dcSDimitry Andric   bool hasBitIntType() const override { return true; }
2030fca6ea1SDimitry Andric 
2040fca6ea1SDimitry Andric   bool validateTarget(DiagnosticsEngine &Diags) const override;
2050fca6ea1SDimitry Andric 
2060fca6ea1SDimitry Andric   bool validateGlobalRegisterVariable(StringRef RegName, unsigned RegSize,
2070fca6ea1SDimitry Andric                                       bool &HasSizeMismatch) const override;
2080b57cec5SDimitry Andric };
2090b57cec5SDimitry Andric 
2100b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
2110b57cec5SDimitry Andric public:
2120b57cec5SDimitry Andric   AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
2130b57cec5SDimitry Andric 
2140b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
2150b57cec5SDimitry Andric                             MacroBuilder &Builder) const override;
2160b57cec5SDimitry Andric private:
2170b57cec5SDimitry Andric   void setDataLayout() override;
2180b57cec5SDimitry Andric };
2190b57cec5SDimitry Andric 
2200b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
2210b57cec5SDimitry Andric     : public WindowsTargetInfo<AArch64leTargetInfo> {
2220b57cec5SDimitry Andric   const llvm::Triple Triple;
2230b57cec5SDimitry Andric 
2240b57cec5SDimitry Andric public:
2250b57cec5SDimitry Andric   WindowsARM64TargetInfo(const llvm::Triple &Triple,
2260b57cec5SDimitry Andric                          const TargetOptions &Opts);
2270b57cec5SDimitry Andric 
2280b57cec5SDimitry Andric   void setDataLayout() override;
2290b57cec5SDimitry Andric 
2300b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override;
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
2330b57cec5SDimitry Andric };
2340b57cec5SDimitry Andric 
2350b57cec5SDimitry Andric // Windows ARM, MS (C++) ABI
2360b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
2370b57cec5SDimitry Andric     : public WindowsARM64TargetInfo {
2380b57cec5SDimitry Andric public:
2390b57cec5SDimitry Andric   MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
2400b57cec5SDimitry Andric                            const TargetOptions &Opts);
2410b57cec5SDimitry Andric 
2420b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
2430b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
2440b57cec5SDimitry Andric   TargetInfo::CallingConvKind
2450b57cec5SDimitry Andric   getCallingConvKind(bool ClangABICompat4) const override;
2460b57cec5SDimitry Andric 
2470fca6ea1SDimitry Andric   unsigned getMinGlobalAlign(uint64_t TypeSize,
2480fca6ea1SDimitry Andric                              bool HasNonWeakDef) const override;
2490b57cec5SDimitry Andric };
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric // ARM64 MinGW target
2520b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo
2530b57cec5SDimitry Andric     : public WindowsARM64TargetInfo {
2540b57cec5SDimitry Andric public:
2550b57cec5SDimitry Andric   MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
2560b57cec5SDimitry Andric };
2570b57cec5SDimitry Andric 
2580b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
2590b57cec5SDimitry Andric public:
2600b57cec5SDimitry Andric   AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
2610b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
2620b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric private:
2650b57cec5SDimitry Andric   void setDataLayout() override;
2660b57cec5SDimitry Andric };
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo
2690b57cec5SDimitry Andric     : public DarwinTargetInfo<AArch64leTargetInfo> {
2700b57cec5SDimitry Andric public:
2710b57cec5SDimitry Andric   DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
2720b57cec5SDimitry Andric 
2730b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override;
2740b57cec5SDimitry Andric 
2750b57cec5SDimitry Andric  protected:
2760b57cec5SDimitry Andric   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
2770b57cec5SDimitry Andric                     MacroBuilder &Builder) const override;
2780b57cec5SDimitry Andric };
2790b57cec5SDimitry Andric 
2800b57cec5SDimitry Andric // 64-bit RenderScript is aarch64
2810b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY RenderScript64TargetInfo
2820b57cec5SDimitry Andric     : public AArch64leTargetInfo {
2830b57cec5SDimitry Andric public:
2840b57cec5SDimitry Andric   RenderScript64TargetInfo(const llvm::Triple &Triple,
2850b57cec5SDimitry Andric                            const TargetOptions &Opts);
2860b57cec5SDimitry Andric 
2870b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
2880b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
2890b57cec5SDimitry Andric };
2900b57cec5SDimitry Andric 
2910b57cec5SDimitry Andric } // namespace targets
2920b57cec5SDimitry Andric } // namespace clang
2930b57cec5SDimitry Andric 
2940b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
295