1 //===--- ARM.h - Declare ARM target feature support -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares ARM TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H
16 #include "OSTargets.h"
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/TargetOptions.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/TargetParser/ARMTargetParser.h"
21 #include "llvm/TargetParser/ARMTargetParserCommon.h"
22 #include "llvm/TargetParser/Triple.h"
27 class LLVM_LIBRARY_VISIBILITY ARMTargetInfo
: public TargetInfo
{
28 // Possible FPU choices.
42 // Possible HWDiv features.
43 enum HWDivMode
{ HWDivThumb
= (1 << 0), HWDivARM
= (1 << 1) };
45 static bool FPUModeIsVFP(FPUMode Mode
) {
46 return Mode
& (VFP2FPU
| VFP3FPU
| VFP4FPU
| NeonFPU
| FPARMV8
);
49 static const TargetInfo::GCCRegAlias GCCRegAliases
[];
50 static const char *const GCCRegNames
[];
57 enum { FP_Default
, FP_VFP
, FP_Neon
} FPMath
;
59 llvm::ARM::ISAKind ArchISA
;
60 llvm::ARM::ArchKind ArchKind
= llvm::ARM::ArchKind::ARMV4T
;
61 llvm::ARM::ProfileKind ArchProfile
;
64 LLVM_PREFERRED_TYPE(FPUMode
)
66 LLVM_PREFERRED_TYPE(MVEMode
)
69 LLVM_PREFERRED_TYPE(bool)
71 LLVM_PREFERRED_TYPE(HWDivMode
)
74 // Initialized via features.
75 LLVM_PREFERRED_TYPE(bool)
76 unsigned SoftFloat
: 1;
77 LLVM_PREFERRED_TYPE(bool)
78 unsigned SoftFloatABI
: 1;
80 LLVM_PREFERRED_TYPE(bool)
82 LLVM_PREFERRED_TYPE(bool)
84 LLVM_PREFERRED_TYPE(bool)
86 LLVM_PREFERRED_TYPE(bool)
88 LLVM_PREFERRED_TYPE(bool)
90 LLVM_PREFERRED_TYPE(bool)
92 LLVM_PREFERRED_TYPE(bool)
93 unsigned HasMatMul
: 1;
94 LLVM_PREFERRED_TYPE(bool)
95 unsigned FPRegsDisabled
: 1;
96 LLVM_PREFERRED_TYPE(bool)
98 LLVM_PREFERRED_TYPE(bool)
102 LDREX_B
= (1 << 0), /// byte (8-bit)
103 LDREX_H
= (1 << 1), /// half (16-bit)
104 LDREX_W
= (1 << 2), /// word (32-bit)
105 LDREX_D
= (1 << 3), /// double (64-bit)
110 // ACLE 6.5.1 Hardware floating point
112 HW_FP_HP
= (1 << 1), /// half (16-bit)
113 HW_FP_SP
= (1 << 2), /// single (32-bit)
114 HW_FP_DP
= (1 << 3), /// double (64-bit)
119 /// __arm_cdp __arm_ldc, __arm_ldcl, __arm_stc,
120 /// __arm_stcl, __arm_mcr and __arm_mrc
121 FEATURE_COPROC_B1
= (1 << 0),
122 /// __arm_cdp2, __arm_ldc2, __arm_stc2, __arm_ldc2l,
123 /// __arm_stc2l, __arm_mcr2 and __arm_mrc2
124 FEATURE_COPROC_B2
= (1 << 1),
125 /// __arm_mcrr, __arm_mrrc
126 FEATURE_COPROC_B3
= (1 << 2),
127 /// __arm_mcrr2, __arm_mrrc2
128 FEATURE_COPROC_B4
= (1 << 3),
132 void setABIAPCS(bool IsAAPCS16
);
135 void setArchInfo(llvm::ARM::ArchKind Kind
);
139 bool isThumb() const;
140 bool supportsThumb() const;
141 bool supportsThumb2() const;
143 bool hasMVEFloat() const;
146 StringRef
getCPUAttr() const;
147 StringRef
getCPUProfile() const;
150 ARMTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
);
152 StringRef
getABI() const override
;
153 bool setABI(const std::string
&Name
) override
;
155 bool isBranchProtectionSupportedArch(StringRef Arch
) const override
;
156 bool validateBranchProtection(StringRef Spec
, StringRef Arch
,
157 BranchProtectionInfo
&BPI
,
158 StringRef
&Err
) const override
;
160 // FIXME: This should be based on Arch attributes, not CPU names.
162 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
164 const std::vector
<std::string
> &FeaturesVec
) const override
;
166 bool isValidFeatureName(StringRef Feature
) const override
{
167 // We pass soft-float-abi in as a -target-feature, but the backend figures
168 // this out through other means.
169 return Feature
!= "soft-float-abi";
172 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
173 DiagnosticsEngine
&Diags
) override
;
175 bool hasFeature(StringRef Feature
) const override
;
177 bool hasBFloat16Type() const override
;
179 bool isValidCPUName(StringRef Name
) const override
;
180 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
182 bool setCPU(const std::string
&Name
) override
;
184 bool setFPMath(StringRef Name
) override
;
186 bool useFP16ConversionIntrinsics() const override
{
190 void getTargetDefinesARMV81A(const LangOptions
&Opts
,
191 MacroBuilder
&Builder
) const;
192 void getTargetDefinesARMV82A(const LangOptions
&Opts
,
193 MacroBuilder
&Builder
) const;
194 void getTargetDefinesARMV83A(const LangOptions
&Opts
,
195 MacroBuilder
&Builder
) const;
196 void getTargetDefines(const LangOptions
&Opts
,
197 MacroBuilder
&Builder
) const override
;
199 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
201 bool isCLZForZeroUndef() const override
;
202 BuiltinVaListKind
getBuiltinVaListKind() const override
;
204 ArrayRef
<const char *> getGCCRegNames() const override
;
205 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
;
206 bool validateAsmConstraint(const char *&Name
,
207 TargetInfo::ConstraintInfo
&Info
) const override
;
208 std::string
convertConstraint(const char *&Constraint
) const override
;
210 validateConstraintModifier(StringRef Constraint
, char Modifier
, unsigned Size
,
211 std::string
&SuggestedModifier
) const override
;
212 std::string_view
getClobbers() const override
;
214 StringRef
getConstraintRegister(StringRef Constraint
,
215 StringRef Expression
) const override
{
219 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
;
221 int getEHDataRegisterNumber(unsigned RegNo
) const override
;
223 bool hasSjLjLowering() const override
;
225 bool hasBitIntType() const override
{ return true; }
227 const char *getBFloat16Mangling() const override
{ return "u6__bf16"; };
229 std::pair
<unsigned, unsigned> hardwareInterferenceSizes() const override
{
230 return std::make_pair(getTriple().isArch64Bit() ? 256 : 64, 64);
234 class LLVM_LIBRARY_VISIBILITY ARMleTargetInfo
: public ARMTargetInfo
{
236 ARMleTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
);
237 void getTargetDefines(const LangOptions
&Opts
,
238 MacroBuilder
&Builder
) const override
;
241 class LLVM_LIBRARY_VISIBILITY ARMbeTargetInfo
: public ARMTargetInfo
{
243 ARMbeTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
);
244 void getTargetDefines(const LangOptions
&Opts
,
245 MacroBuilder
&Builder
) const override
;
248 class LLVM_LIBRARY_VISIBILITY WindowsARMTargetInfo
249 : public WindowsTargetInfo
<ARMleTargetInfo
> {
250 const llvm::Triple Triple
;
253 WindowsARMTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
);
255 void getVisualStudioDefines(const LangOptions
&Opts
,
256 MacroBuilder
&Builder
) const;
258 BuiltinVaListKind
getBuiltinVaListKind() const override
;
260 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
;
263 // Windows ARM + Itanium C++ ABI Target
264 class LLVM_LIBRARY_VISIBILITY ItaniumWindowsARMleTargetInfo
265 : public WindowsARMTargetInfo
{
267 ItaniumWindowsARMleTargetInfo(const llvm::Triple
&Triple
,
268 const TargetOptions
&Opts
);
270 void getTargetDefines(const LangOptions
&Opts
,
271 MacroBuilder
&Builder
) const override
;
274 // Windows ARM, MS (C++) ABI
275 class LLVM_LIBRARY_VISIBILITY MicrosoftARMleTargetInfo
276 : public WindowsARMTargetInfo
{
278 MicrosoftARMleTargetInfo(const llvm::Triple
&Triple
,
279 const TargetOptions
&Opts
);
281 void getTargetDefines(const LangOptions
&Opts
,
282 MacroBuilder
&Builder
) const override
;
286 class LLVM_LIBRARY_VISIBILITY MinGWARMTargetInfo
: public WindowsARMTargetInfo
{
288 MinGWARMTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
);
290 void getTargetDefines(const LangOptions
&Opts
,
291 MacroBuilder
&Builder
) const override
;
295 class LLVM_LIBRARY_VISIBILITY CygwinARMTargetInfo
: public ARMleTargetInfo
{
297 CygwinARMTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
);
299 void getTargetDefines(const LangOptions
&Opts
,
300 MacroBuilder
&Builder
) const override
;
303 class LLVM_LIBRARY_VISIBILITY DarwinARMTargetInfo
304 : public DarwinTargetInfo
<ARMleTargetInfo
> {
306 void getOSDefines(const LangOptions
&Opts
, const llvm::Triple
&Triple
,
307 MacroBuilder
&Builder
) const override
;
310 DarwinARMTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&Opts
);
313 } // namespace targets
316 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_ARM_H