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/Support/AArch64TargetParser.h" 19 #include <optional> 20 21 namespace clang { 22 namespace targets { 23 24 class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public TargetInfo { 25 virtual void setDataLayout() = 0; 26 static const TargetInfo::GCCRegAlias GCCRegAliases[]; 27 static const char *const GCCRegNames[]; 28 29 enum FPUModeEnum { FPUMode, NeonMode = (1 << 0), SveMode = (1 << 1) }; 30 31 unsigned FPU = FPUMode; 32 bool HasCRC = false; 33 bool HasAES = false; 34 bool HasSHA2 = false; 35 bool HasSHA3 = false; 36 bool HasSM4 = false; 37 bool HasUnaligned = true; 38 bool HasFullFP16 = false; 39 bool HasDotProd = false; 40 bool HasFP16FML = false; 41 bool HasMTE = false; 42 bool HasTME = false; 43 bool HasPAuth = false; 44 bool HasLS64 = false; 45 bool HasRandGen = false; 46 bool HasMatMul = false; 47 bool HasBFloat16 = false; 48 bool HasSVE2 = false; 49 bool HasSVE2AES = false; 50 bool HasSVE2SHA3 = false; 51 bool HasSVE2SM4 = false; 52 bool HasSVE2BitPerm = false; 53 bool HasMatmulFP64 = false; 54 bool HasMatmulFP32 = false; 55 bool HasLSE = false; 56 bool HasFlagM = false; 57 bool HasAlternativeNZCV = false; 58 bool HasMOPS = false; 59 bool HasD128 = false; 60 bool HasRCPC = false; 61 bool HasRDM = false; 62 bool HasDIT = false; 63 bool HasCCPP = false; 64 bool HasCCDP = false; 65 bool HasFRInt3264 = false; 66 bool HasSME = false; 67 bool HasSMEF64 = false; 68 bool HasSMEI64 = false; 69 bool HasSB = false; 70 bool HasPredRes = false; 71 bool HasSSBS = false; 72 bool HasBTI = false; 73 bool HasWFxT = false; 74 bool HasJSCVT = false; 75 bool HasFCMA = false; 76 bool HasNoNeon = false; 77 bool HasNoSVE = false; 78 bool HasFMV = true; 79 80 const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A; 81 82 std::string ABI; 83 84 public: 85 AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); 86 87 StringRef getABI() const override; 88 bool setABI(const std::string &Name) override; 89 90 bool validateBranchProtection(StringRef Spec, StringRef Arch, 91 BranchProtectionInfo &BPI, 92 StringRef &Err) const override; 93 94 bool isValidCPUName(StringRef Name) const override; 95 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; 96 bool setCPU(const std::string &Name) override; 97 98 unsigned multiVersionSortPriority(StringRef Name) const override; 99 unsigned multiVersionFeatureCost() const override; 100 101 bool 102 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, 103 StringRef CPU, 104 const std::vector<std::string> &FeaturesVec) const override; 105 bool useFP16ConversionIntrinsics() const override { 106 return false; 107 } 108 109 void setArchFeatures(); 110 111 void getTargetDefinesARMV81A(const LangOptions &Opts, 112 MacroBuilder &Builder) const; 113 void getTargetDefinesARMV82A(const LangOptions &Opts, 114 MacroBuilder &Builder) const; 115 void getTargetDefinesARMV83A(const LangOptions &Opts, 116 MacroBuilder &Builder) const; 117 void getTargetDefinesARMV84A(const LangOptions &Opts, 118 MacroBuilder &Builder) const; 119 void getTargetDefinesARMV85A(const LangOptions &Opts, 120 MacroBuilder &Builder) const; 121 void getTargetDefinesARMV86A(const LangOptions &Opts, 122 MacroBuilder &Builder) const; 123 void getTargetDefinesARMV87A(const LangOptions &Opts, 124 MacroBuilder &Builder) const; 125 void getTargetDefinesARMV88A(const LangOptions &Opts, 126 MacroBuilder &Builder) const; 127 void getTargetDefinesARMV89A(const LangOptions &Opts, 128 MacroBuilder &Builder) const; 129 void getTargetDefinesARMV9A(const LangOptions &Opts, 130 MacroBuilder &Builder) const; 131 void getTargetDefinesARMV91A(const LangOptions &Opts, 132 MacroBuilder &Builder) const; 133 void getTargetDefinesARMV92A(const LangOptions &Opts, 134 MacroBuilder &Builder) const; 135 void getTargetDefinesARMV93A(const LangOptions &Opts, 136 MacroBuilder &Builder) const; 137 void getTargetDefinesARMV94A(const LangOptions &Opts, 138 MacroBuilder &Builder) const; 139 void getTargetDefines(const LangOptions &Opts, 140 MacroBuilder &Builder) const override; 141 142 ArrayRef<Builtin::Info> getTargetBuiltins() const override; 143 144 std::optional<std::pair<unsigned, unsigned>> 145 getVScaleRange(const LangOptions &LangOpts) const override; 146 147 bool getFeatureDepOptions(StringRef Feature, 148 std::string &Options) const override; 149 bool validateCpuSupports(StringRef FeatureStr) const override; 150 bool hasFeature(StringRef Feature) const override; 151 void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name, 152 bool Enabled) const override; 153 bool handleTargetFeatures(std::vector<std::string> &Features, 154 DiagnosticsEngine &Diags) override; 155 ParsedTargetAttr parseTargetAttr(StringRef Str) const override; 156 bool supportsTargetAttributeTune() const override { return true; } 157 158 bool hasBFloat16Type() const override; 159 160 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override; 161 162 bool isCLZForZeroUndef() const override; 163 164 BuiltinVaListKind getBuiltinVaListKind() const override; 165 166 ArrayRef<const char *> getGCCRegNames() const override; 167 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; 168 169 std::string convertConstraint(const char *&Constraint) const override { 170 std::string R; 171 switch (*Constraint) { 172 case 'U': // Three-character constraint; add "@3" hint for later parsing. 173 R = std::string("@3") + std::string(Constraint, 3); 174 Constraint += 2; 175 break; 176 default: 177 R = TargetInfo::convertConstraint(Constraint); 178 break; 179 } 180 return R; 181 } 182 183 bool validateAsmConstraint(const char *&Name, 184 TargetInfo::ConstraintInfo &Info) const override; 185 bool 186 validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size, 187 std::string &SuggestedModifier) const override; 188 const char *getClobbers() const override; 189 190 StringRef getConstraintRegister(StringRef Constraint, 191 StringRef Expression) const override { 192 return Expression; 193 } 194 195 int getEHDataRegisterNumber(unsigned RegNo) const override; 196 197 const char *getBFloat16Mangling() const override { return "u6__bf16"; }; 198 bool hasInt128Type() const override; 199 200 bool hasBitIntType() const override { return true; } 201 }; 202 203 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo { 204 public: 205 AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); 206 207 void getTargetDefines(const LangOptions &Opts, 208 MacroBuilder &Builder) const override; 209 private: 210 void setDataLayout() override; 211 }; 212 213 class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo 214 : public WindowsTargetInfo<AArch64leTargetInfo> { 215 const llvm::Triple Triple; 216 217 public: 218 WindowsARM64TargetInfo(const llvm::Triple &Triple, 219 const TargetOptions &Opts); 220 221 void setDataLayout() override; 222 223 BuiltinVaListKind getBuiltinVaListKind() const override; 224 225 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override; 226 }; 227 228 // Windows ARM, MS (C++) ABI 229 class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo 230 : public WindowsARM64TargetInfo { 231 public: 232 MicrosoftARM64TargetInfo(const llvm::Triple &Triple, 233 const TargetOptions &Opts); 234 235 void getTargetDefines(const LangOptions &Opts, 236 MacroBuilder &Builder) const override; 237 TargetInfo::CallingConvKind 238 getCallingConvKind(bool ClangABICompat4) const override; 239 240 unsigned getMinGlobalAlign(uint64_t TypeSize) const override; 241 }; 242 243 // ARM64 MinGW target 244 class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo 245 : public WindowsARM64TargetInfo { 246 public: 247 MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); 248 }; 249 250 class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo { 251 public: 252 AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); 253 void getTargetDefines(const LangOptions &Opts, 254 MacroBuilder &Builder) const override; 255 256 private: 257 void setDataLayout() override; 258 }; 259 260 class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo 261 : public DarwinTargetInfo<AArch64leTargetInfo> { 262 public: 263 DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts); 264 265 BuiltinVaListKind getBuiltinVaListKind() const override; 266 267 protected: 268 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 269 MacroBuilder &Builder) const override; 270 }; 271 272 // 64-bit RenderScript is aarch64 273 class LLVM_LIBRARY_VISIBILITY RenderScript64TargetInfo 274 : public AArch64leTargetInfo { 275 public: 276 RenderScript64TargetInfo(const llvm::Triple &Triple, 277 const TargetOptions &Opts); 278 279 void getTargetDefines(const LangOptions &Opts, 280 MacroBuilder &Builder) const override; 281 }; 282 283 } // namespace targets 284 } // namespace clang 285 286 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H 287