xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/AArch64.h (revision 38a52bd3b5cac3da6f7f6eef3dd050e6aa08ebb3)
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 "llvm/Support/TargetParser.h"
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;
32   bool HasCRC;
33   bool HasCrypto;
34   bool HasAES;
35   bool HasSHA2;
36   bool HasSHA3;
37   bool HasSM4;
38   bool HasUnaligned;
39   bool HasFullFP16;
40   bool HasDotProd;
41   bool HasFP16FML;
42   bool HasMTE;
43   bool HasTME;
44   bool HasPAuth;
45   bool HasLS64;
46   bool HasRandGen;
47   bool HasMatMul;
48   bool HasSVE2;
49   bool HasSVE2AES;
50   bool HasSVE2SHA3;
51   bool HasSVE2SM4;
52   bool HasSVE2BitPerm;
53   bool HasMatmulFP64;
54   bool HasMatmulFP32;
55   bool HasLSE;
56   bool HasFlagM;
57   bool HasHBC;
58   bool HasMOPS;
59 
60   llvm::AArch64::ArchKind ArchKind;
61 
62   static const Builtin::Info BuiltinInfo[];
63 
64   std::string ABI;
65   StringRef getArchProfile() const;
66 
67 public:
68   AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
69 
70   StringRef getABI() const override;
71   bool setABI(const std::string &Name) override;
72 
73   bool validateBranchProtection(StringRef Spec, StringRef Arch,
74                                 BranchProtectionInfo &BPI,
75                                 StringRef &Err) const override;
76 
77   bool isValidCPUName(StringRef Name) const override;
78   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
79   bool setCPU(const std::string &Name) override;
80 
81   bool useFP16ConversionIntrinsics() const override {
82     return false;
83   }
84 
85   void getTargetDefinesARMV81A(const LangOptions &Opts,
86                                MacroBuilder &Builder) const;
87   void getTargetDefinesARMV82A(const LangOptions &Opts,
88                                MacroBuilder &Builder) const;
89   void getTargetDefinesARMV83A(const LangOptions &Opts,
90                                MacroBuilder &Builder) const;
91   void getTargetDefinesARMV84A(const LangOptions &Opts,
92                                MacroBuilder &Builder) const;
93   void getTargetDefinesARMV85A(const LangOptions &Opts,
94                                MacroBuilder &Builder) const;
95   void getTargetDefinesARMV86A(const LangOptions &Opts,
96                                MacroBuilder &Builder) const;
97   void getTargetDefinesARMV87A(const LangOptions &Opts,
98                                MacroBuilder &Builder) const;
99   void getTargetDefinesARMV88A(const LangOptions &Opts,
100                                MacroBuilder &Builder) const;
101   void getTargetDefinesARMV9A(const LangOptions &Opts,
102                               MacroBuilder &Builder) const;
103   void getTargetDefinesARMV91A(const LangOptions &Opts,
104                                MacroBuilder &Builder) const;
105   void getTargetDefinesARMV92A(const LangOptions &Opts,
106                                MacroBuilder &Builder) const;
107   void getTargetDefinesARMV93A(const LangOptions &Opts,
108                                MacroBuilder &Builder) const;
109   void getTargetDefines(const LangOptions &Opts,
110                         MacroBuilder &Builder) const override;
111 
112   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
113 
114   Optional<std::pair<unsigned, unsigned>>
115   getVScaleRange(const LangOptions &LangOpts) const override;
116 
117   bool hasFeature(StringRef Feature) const override;
118   bool handleTargetFeatures(std::vector<std::string> &Features,
119                             DiagnosticsEngine &Diags) override;
120 
121   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
122 
123   bool isCLZForZeroUndef() const override;
124 
125   BuiltinVaListKind getBuiltinVaListKind() const override;
126 
127   ArrayRef<const char *> getGCCRegNames() const override;
128   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
129 
130   std::string convertConstraint(const char *&Constraint) const override {
131     std::string R;
132     switch (*Constraint) {
133     case 'U': // Three-character constraint; add "@3" hint for later parsing.
134       R = std::string("@3") + std::string(Constraint, 3);
135       Constraint += 2;
136       break;
137     default:
138       R = TargetInfo::convertConstraint(Constraint);
139       break;
140     }
141     return R;
142   }
143 
144   bool validateAsmConstraint(const char *&Name,
145                              TargetInfo::ConstraintInfo &Info) const override;
146   bool
147   validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
148                              std::string &SuggestedModifier) const override;
149   const char *getClobbers() const override;
150 
151   StringRef getConstraintRegister(StringRef Constraint,
152                                   StringRef Expression) const override {
153     return Expression;
154   }
155 
156   int getEHDataRegisterNumber(unsigned RegNo) const override;
157 
158   const char *getBFloat16Mangling() const override { return "u6__bf16"; };
159   bool hasInt128Type() const override;
160 
161   bool hasBitIntType() const override { return true; }
162 };
163 
164 class LLVM_LIBRARY_VISIBILITY AArch64leTargetInfo : public AArch64TargetInfo {
165 public:
166   AArch64leTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
167 
168   void getTargetDefines(const LangOptions &Opts,
169                             MacroBuilder &Builder) const override;
170 private:
171   void setDataLayout() override;
172 };
173 
174 class LLVM_LIBRARY_VISIBILITY WindowsARM64TargetInfo
175     : public WindowsTargetInfo<AArch64leTargetInfo> {
176   const llvm::Triple Triple;
177 
178 public:
179   WindowsARM64TargetInfo(const llvm::Triple &Triple,
180                          const TargetOptions &Opts);
181 
182   void setDataLayout() override;
183 
184   BuiltinVaListKind getBuiltinVaListKind() const override;
185 
186   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
187 };
188 
189 // Windows ARM, MS (C++) ABI
190 class LLVM_LIBRARY_VISIBILITY MicrosoftARM64TargetInfo
191     : public WindowsARM64TargetInfo {
192 public:
193   MicrosoftARM64TargetInfo(const llvm::Triple &Triple,
194                            const TargetOptions &Opts);
195 
196   void getTargetDefines(const LangOptions &Opts,
197                         MacroBuilder &Builder) const override;
198   TargetInfo::CallingConvKind
199   getCallingConvKind(bool ClangABICompat4) const override;
200 
201   unsigned getMinGlobalAlign(uint64_t TypeSize) const override;
202 };
203 
204 // ARM64 MinGW target
205 class LLVM_LIBRARY_VISIBILITY MinGWARM64TargetInfo
206     : public WindowsARM64TargetInfo {
207 public:
208   MinGWARM64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
209 };
210 
211 class LLVM_LIBRARY_VISIBILITY AArch64beTargetInfo : public AArch64TargetInfo {
212 public:
213   AArch64beTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
214   void getTargetDefines(const LangOptions &Opts,
215                         MacroBuilder &Builder) const override;
216 
217 private:
218   void setDataLayout() override;
219 };
220 
221 class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo
222     : public DarwinTargetInfo<AArch64leTargetInfo> {
223 public:
224   DarwinAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
225 
226   BuiltinVaListKind getBuiltinVaListKind() const override;
227 
228  protected:
229   void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
230                     MacroBuilder &Builder) const override;
231 };
232 
233 // 64-bit RenderScript is aarch64
234 class LLVM_LIBRARY_VISIBILITY RenderScript64TargetInfo
235     : public AArch64leTargetInfo {
236 public:
237   RenderScript64TargetInfo(const llvm::Triple &Triple,
238                            const TargetOptions &Opts);
239 
240   void getTargetDefines(const LangOptions &Opts,
241                         MacroBuilder &Builder) const override;
242 };
243 
244 } // namespace targets
245 } // namespace clang
246 
247 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AARCH64_H
248