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