xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/AArch64.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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 HasSME2 = false;
72   bool HasSMEF64F64 = false;
73   bool HasSMEI16I64 = false;
74   bool HasSB = false;
75   bool HasPredRes = false;
76   bool HasSSBS = false;
77   bool HasBTI = false;
78   bool HasWFxT = false;
79   bool HasJSCVT = false;
80   bool HasFCMA = false;
81   bool HasNoFP = false;
82   bool HasNoNeon = false;
83   bool HasNoSVE = false;
84   bool HasFMV = true;
85   bool HasGCS = false;
86   bool HasRCPC3 = false;
87   bool HasSMEFA64 = false;
88 
89   const llvm::AArch64::ArchInfo *ArchInfo = &llvm::AArch64::ARMV8A;
90 
91   std::string ABI;
92 
93 public:
94   AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
95 
96   StringRef getABI() const override;
97   bool setABI(const std::string &Name) override;
98 
99   bool validateBranchProtection(StringRef Spec, StringRef Arch,
100                                 BranchProtectionInfo &BPI,
101                                 StringRef &Err) const override;
102 
103   bool isValidCPUName(StringRef Name) const override;
104   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
105   bool setCPU(const std::string &Name) override;
106 
107   unsigned multiVersionSortPriority(StringRef Name) const override;
108   unsigned multiVersionFeatureCost() const override;
109 
110   bool
111   initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
112                  StringRef CPU,
113                  const std::vector<std::string> &FeaturesVec) const override;
114   bool useFP16ConversionIntrinsics() const override {
115     return false;
116   }
117 
118   void setArchFeatures();
119 
120   void getTargetDefinesARMV81A(const LangOptions &Opts,
121                                MacroBuilder &Builder) const;
122   void getTargetDefinesARMV82A(const LangOptions &Opts,
123                                MacroBuilder &Builder) const;
124   void getTargetDefinesARMV83A(const LangOptions &Opts,
125                                MacroBuilder &Builder) const;
126   void getTargetDefinesARMV84A(const LangOptions &Opts,
127                                MacroBuilder &Builder) const;
128   void getTargetDefinesARMV85A(const LangOptions &Opts,
129                                MacroBuilder &Builder) const;
130   void getTargetDefinesARMV86A(const LangOptions &Opts,
131                                MacroBuilder &Builder) const;
132   void getTargetDefinesARMV87A(const LangOptions &Opts,
133                                MacroBuilder &Builder) const;
134   void getTargetDefinesARMV88A(const LangOptions &Opts,
135                                MacroBuilder &Builder) const;
136   void getTargetDefinesARMV89A(const LangOptions &Opts,
137                                MacroBuilder &Builder) const;
138   void getTargetDefinesARMV9A(const LangOptions &Opts,
139                               MacroBuilder &Builder) const;
140   void getTargetDefinesARMV91A(const LangOptions &Opts,
141                                MacroBuilder &Builder) const;
142   void getTargetDefinesARMV92A(const LangOptions &Opts,
143                                MacroBuilder &Builder) const;
144   void getTargetDefinesARMV93A(const LangOptions &Opts,
145                                MacroBuilder &Builder) const;
146   void getTargetDefinesARMV94A(const LangOptions &Opts,
147                                MacroBuilder &Builder) const;
148   void getTargetDefinesARMV95A(const LangOptions &Opts,
149                                MacroBuilder &Builder) const;
150   void getTargetDefines(const LangOptions &Opts,
151                         MacroBuilder &Builder) const override;
152 
153   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
154 
155   std::optional<std::pair<unsigned, unsigned>>
156   getVScaleRange(const LangOptions &LangOpts) const override;
157   bool doesFeatureAffectCodeGen(StringRef Name) const override;
158   StringRef getFeatureDependencies(StringRef Name) const override;
159   bool validateCpuSupports(StringRef FeatureStr) const override;
160   bool hasFeature(StringRef Feature) const override;
161   void setFeatureEnabled(llvm::StringMap<bool> &Features, StringRef Name,
162                          bool Enabled) const override;
163   bool handleTargetFeatures(std::vector<std::string> &Features,
164                             DiagnosticsEngine &Diags) override;
165   ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
166   bool supportsTargetAttributeTune() const override { return true; }
167 
168   bool checkArithmeticFenceSupported() const override { return true; }
169 
170   bool hasBFloat16Type() const override;
171 
172   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
173 
174   bool isCLZForZeroUndef() const override;
175 
176   BuiltinVaListKind getBuiltinVaListKind() const override;
177 
178   ArrayRef<const char *> getGCCRegNames() const override;
179   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
180 
181   std::string convertConstraint(const char *&Constraint) const override;
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   std::string_view 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