clang  14.0.0git
ARM.h
Go to the documentation of this file.
1 //===--- ARM.h - Declare ARM 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 ARM TargetInfo objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H
15 
16 #include "OSTargets.h"
17 #include "clang/Basic/TargetInfo.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/TargetParser.h"
22 
23 namespace clang {
24 namespace targets {
25 
26 class LLVM_LIBRARY_VISIBILITY ARMTargetInfo : public TargetInfo {
27  // Possible FPU choices.
28  enum FPUMode {
29  VFP2FPU = (1 << 0),
30  VFP3FPU = (1 << 1),
31  VFP4FPU = (1 << 2),
32  NeonFPU = (1 << 3),
33  FPARMV8 = (1 << 4)
34  };
35 
36  enum MVEMode {
37  MVE_INT = (1 << 0),
38  MVE_FP = (1 << 1)
39  };
40 
41  // Possible HWDiv features.
42  enum HWDivMode { HWDivThumb = (1 << 0), HWDivARM = (1 << 1) };
43 
44  static bool FPUModeIsVFP(FPUMode Mode) {
45  return Mode & (VFP2FPU | VFP3FPU | VFP4FPU | NeonFPU | FPARMV8);
46  }
47 
48  static const TargetInfo::GCCRegAlias GCCRegAliases[];
49  static const char *const GCCRegNames[];
50 
51  std::string ABI, CPU;
52 
53  StringRef CPUProfile;
54  StringRef CPUAttr;
55 
56  enum { FP_Default, FP_VFP, FP_Neon } FPMath;
57 
58  llvm::ARM::ISAKind ArchISA;
59  llvm::ARM::ArchKind ArchKind = llvm::ARM::ArchKind::ARMV4T;
60  llvm::ARM::ProfileKind ArchProfile;
61  unsigned ArchVersion;
62 
63  unsigned FPU : 5;
64  unsigned MVE : 2;
65 
66  unsigned IsAAPCS : 1;
67  unsigned HWDiv : 2;
68 
69  // Initialized via features.
70  unsigned SoftFloat : 1;
71  unsigned SoftFloatABI : 1;
72 
73  unsigned CRC : 1;
74  unsigned Crypto : 1;
75  unsigned SHA2 : 1;
76  unsigned AES : 1;
77  unsigned DSP : 1;
78  unsigned Unaligned : 1;
79  unsigned DotProd : 1;
80  unsigned HasMatMul : 1;
81  unsigned FPRegsDisabled : 1;
82 
83  enum {
84  LDREX_B = (1 << 0), /// byte (8-bit)
85  LDREX_H = (1 << 1), /// half (16-bit)
86  LDREX_W = (1 << 2), /// word (32-bit)
87  LDREX_D = (1 << 3), /// double (64-bit)
88  };
89 
90  uint32_t LDREX;
91 
92  // ACLE 6.5.1 Hardware floating point
93  enum {
94  HW_FP_HP = (1 << 1), /// half (16-bit)
95  HW_FP_SP = (1 << 2), /// single (32-bit)
96  HW_FP_DP = (1 << 3), /// double (64-bit)
97  };
98  uint32_t HW_FP;
99 
100  static const Builtin::Info BuiltinInfo[];
101 
102  void setABIAAPCS();
103  void setABIAPCS(bool IsAAPCS16);
104 
105  void setArchInfo();
106  void setArchInfo(llvm::ARM::ArchKind Kind);
107 
108  void setAtomic();
109 
110  bool isThumb() const;
111  bool supportsThumb() const;
112  bool supportsThumb2() const;
113  bool hasMVE() const;
114  bool hasMVEFloat() const;
115  bool hasCDE() const;
116 
117  StringRef getCPUAttr() const;
118  StringRef getCPUProfile() const;
119 
120 public:
121  ARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
122 
123  StringRef getABI() const override;
124  bool setABI(const std::string &Name) override;
125 
126  bool validateBranchProtection(StringRef, BranchProtectionInfo &,
127  StringRef &) const override;
128 
129  // FIXME: This should be based on Arch attributes, not CPU names.
130  bool
131  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
132  StringRef CPU,
133  const std::vector<std::string> &FeaturesVec) const override;
134 
135  bool isValidFeatureName(StringRef Feature) const override {
136  // We pass soft-float-abi in as a -target-feature, but the backend figures
137  // this out through other means.
138  return Feature != "soft-float-abi";
139  }
140 
141  bool handleTargetFeatures(std::vector<std::string> &Features,
142  DiagnosticsEngine &Diags) override;
143 
144  bool hasFeature(StringRef Feature) const override;
145 
146  bool hasBFloat16Type() const override;
147 
148  bool isValidCPUName(StringRef Name) const override;
149  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
150 
151  bool setCPU(const std::string &Name) override;
152 
153  bool setFPMath(StringRef Name) override;
154 
155  bool useFP16ConversionIntrinsics() const override {
156  return false;
157  }
158 
159  void getTargetDefinesARMV81A(const LangOptions &Opts,
160  MacroBuilder &Builder) const;
161  void getTargetDefinesARMV82A(const LangOptions &Opts,
162  MacroBuilder &Builder) const;
163  void getTargetDefinesARMV83A(const LangOptions &Opts,
164  MacroBuilder &Builder) const;
165  void getTargetDefines(const LangOptions &Opts,
166  MacroBuilder &Builder) const override;
167 
168  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
169 
170  bool isCLZForZeroUndef() const override;
171  BuiltinVaListKind getBuiltinVaListKind() const override;
172 
173  ArrayRef<const char *> getGCCRegNames() const override;
174  ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
175  bool validateAsmConstraint(const char *&Name,
176  TargetInfo::ConstraintInfo &Info) const override;
177  std::string convertConstraint(const char *&Constraint) const override;
178  bool
179  validateConstraintModifier(StringRef Constraint, char Modifier, unsigned Size,
180  std::string &SuggestedModifier) const override;
181  const char *getClobbers() const override;
182 
183  StringRef getConstraintRegister(StringRef Constraint,
184  StringRef Expression) const override {
185  return Expression;
186  }
187 
188  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
189 
190  int getEHDataRegisterNumber(unsigned RegNo) const override;
191 
192  bool hasSjLjLowering() const override;
193 
194  bool hasBitIntType() const override { return true; }
195 
196  const char *getBFloat16Mangling() const override { return "u6__bf16"; };
197 };
198 
199 class LLVM_LIBRARY_VISIBILITY ARMleTargetInfo : public ARMTargetInfo {
200 public:
201  ARMleTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
202  void getTargetDefines(const LangOptions &Opts,
203  MacroBuilder &Builder) const override;
204 };
205 
206 class LLVM_LIBRARY_VISIBILITY ARMbeTargetInfo : public ARMTargetInfo {
207 public:
208  ARMbeTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
209  void getTargetDefines(const LangOptions &Opts,
210  MacroBuilder &Builder) const override;
211 };
212 
213 class LLVM_LIBRARY_VISIBILITY WindowsARMTargetInfo
214  : public WindowsTargetInfo<ARMleTargetInfo> {
215  const llvm::Triple Triple;
216 
217 public:
218  WindowsARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
219 
220  void getVisualStudioDefines(const LangOptions &Opts,
221  MacroBuilder &Builder) const;
222 
223  BuiltinVaListKind getBuiltinVaListKind() const override;
224 
225  CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
226 };
227 
228 // Windows ARM + Itanium C++ ABI Target
229 class LLVM_LIBRARY_VISIBILITY ItaniumWindowsARMleTargetInfo
230  : public WindowsARMTargetInfo {
231 public:
232  ItaniumWindowsARMleTargetInfo(const llvm::Triple &Triple,
233  const TargetOptions &Opts);
234 
235  void getTargetDefines(const LangOptions &Opts,
236  MacroBuilder &Builder) const override;
237 };
238 
239 // Windows ARM, MS (C++) ABI
240 class LLVM_LIBRARY_VISIBILITY MicrosoftARMleTargetInfo
241  : public WindowsARMTargetInfo {
242 public:
243  MicrosoftARMleTargetInfo(const llvm::Triple &Triple,
244  const TargetOptions &Opts);
245 
246  void getTargetDefines(const LangOptions &Opts,
247  MacroBuilder &Builder) const override;
248 };
249 
250 // ARM MinGW target
251 class LLVM_LIBRARY_VISIBILITY MinGWARMTargetInfo : public WindowsARMTargetInfo {
252 public:
253  MinGWARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
254 
255  void getTargetDefines(const LangOptions &Opts,
256  MacroBuilder &Builder) const override;
257 };
258 
259 // ARM Cygwin target
260 class LLVM_LIBRARY_VISIBILITY CygwinARMTargetInfo : public ARMleTargetInfo {
261 public:
262  CygwinARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
263 
264  void getTargetDefines(const LangOptions &Opts,
265  MacroBuilder &Builder) const override;
266 };
267 
268 class LLVM_LIBRARY_VISIBILITY DarwinARMTargetInfo
269  : public DarwinTargetInfo<ARMleTargetInfo> {
270 protected:
271  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
272  MacroBuilder &Builder) const override;
273 
274 public:
275  DarwinARMTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts);
276 };
277 
278 // 32-bit RenderScript is armv7 with width and align of 'long' set to 8-bytes
279 class LLVM_LIBRARY_VISIBILITY RenderScript32TargetInfo
280  : public ARMleTargetInfo {
281 public:
282  RenderScript32TargetInfo(const llvm::Triple &Triple,
283  const TargetOptions &Opts);
284 
285  void getTargetDefines(const LangOptions &Opts,
286  MacroBuilder &Builder) const override;
287 };
288 
289 } // namespace targets
290 } // namespace clang
291 
292 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::targets::ARMTargetInfo::hasBitIntType
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: ARM.h:194
clang::targets::RenderScript32TargetInfo
Definition: ARM.h:279
TargetInfo.h
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::targets::ARMTargetInfo
Definition: ARM.h:26
Expression
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:267
clang::targets::ARMTargetInfo::isValidFeatureName
bool isValidFeatureName(StringRef Feature) const override
Determine whether this TargetInfo supports the given feature.
Definition: ARM.h:135
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:20
clang::targets::WindowsTargetInfo
Definition: OSTargets.h:814
clang::targets::DarwinTargetInfo
Definition: OSTargets.h:78
clang::targets::MicrosoftARMleTargetInfo
Definition: ARM.h:240
clang::targets::GCCRegNames
static const char *const GCCRegNames[]
Definition: X86.cpp:43
clang::targets::CygwinARMTargetInfo
Definition: ARM.h:260
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:263
clang::TargetInfo::GCCRegAlias
Definition: TargetInfo.h:1154
clang::targets::MinGWARMTargetInfo
Definition: ARM.h:251
clang::targets::WindowsARMTargetInfo
Definition: ARM.h:213
clang::TargetInfo::BranchProtectionInfo
Definition: TargetInfo.h:1283
clang::targets::ARMleTargetInfo
Definition: ARM.h:199
TargetOptions.h
llvm::ArrayRef
Definition: LLVM.h:34
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:973
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::targets::DarwinARMTargetInfo
Definition: ARM.h:268
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang
Definition: CalledOnceCheck.h:17
clang::targets::ARMTargetInfo::getConstraintRegister
StringRef getConstraintRegister(StringRef Constraint, StringRef Expression) const override
Extracts a register from the passed constraint (if it is a single-register constraint) and the asm la...
Definition: ARM.h:183
clang::Builtin::Info
Definition: Builtins.h:55
OSTargets.h
clang::targets::ItaniumWindowsARMleTargetInfo
Definition: ARM.h:229
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
clang::targets::ARMbeTargetInfo
Definition: ARM.h:206
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::targets::ARMTargetInfo::useFP16ConversionIntrinsics
bool useFP16ConversionIntrinsics() const override
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
Definition: ARM.h:155
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1471
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::targets::ARMTargetInfo::getBFloat16Mangling
const char * getBFloat16Mangling() const override
Return the mangled code of bfloat.
Definition: ARM.h:196
hasFeature
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition: Module.cpp:101