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