1 //===--- CSKY.cpp - Implement CSKY target feature support -----------------===//
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 implements CSKY TargetInfo objects.
11 //===----------------------------------------------------------------------===//
15 using namespace clang
;
16 using namespace clang::targets
;
18 bool CSKYTargetInfo::isValidCPUName(StringRef Name
) const {
19 return llvm::CSKY::parseCPUArch(Name
) != llvm::CSKY::ArchKind::INVALID
;
22 bool CSKYTargetInfo::setCPU(const std::string
&Name
) {
23 llvm::CSKY::ArchKind archKind
= llvm::CSKY::parseCPUArch(Name
);
24 bool isValid
= (archKind
!= llvm::CSKY::ArchKind::INVALID
);
34 void CSKYTargetInfo::getTargetDefines(const LangOptions
&Opts
,
35 MacroBuilder
&Builder
) const {
36 Builder
.defineMacro("__csky__", "2");
37 Builder
.defineMacro("__CSKY__", "2");
38 Builder
.defineMacro("__ckcore__", "2");
39 Builder
.defineMacro("__CKCORE__", "2");
41 Builder
.defineMacro("__CSKYABI__", ABI
== "abiv2" ? "2" : "1");
42 Builder
.defineMacro("__cskyabi__", ABI
== "abiv2" ? "2" : "1");
44 StringRef ArchName
= "ck810";
45 StringRef CPUName
= "ck810";
47 if (Arch
!= llvm::CSKY::ArchKind::INVALID
) {
48 ArchName
= llvm::CSKY::getArchName(Arch
);
52 Builder
.defineMacro("__" + ArchName
.upper() + "__");
53 Builder
.defineMacro("__" + ArchName
.lower() + "__");
54 if (ArchName
!= CPUName
) {
55 Builder
.defineMacro("__" + CPUName
.upper() + "__");
56 Builder
.defineMacro("__" + CPUName
.lower() + "__");
59 // TODO: Add support for BE if BE was supported later
60 StringRef endian
= "__cskyLE__";
62 Builder
.defineMacro(endian
);
63 Builder
.defineMacro(endian
.upper());
64 Builder
.defineMacro(endian
.lower());
67 StringRef dspv2
= "__CSKY_DSPV2__";
68 Builder
.defineMacro(dspv2
);
69 Builder
.defineMacro(dspv2
.lower());
73 StringRef vdspv2
= "__CSKY_VDSPV2__";
74 Builder
.defineMacro(vdspv2
);
75 Builder
.defineMacro(vdspv2
.lower());
78 StringRef vdspv2_f
= "__CSKY_VDSPV2_F__";
79 Builder
.defineMacro(vdspv2_f
);
80 Builder
.defineMacro(vdspv2_f
.lower());
84 StringRef vdspv1_64
= "__CSKY_VDSP64__";
85 StringRef vdspv1_128
= "__CSKY_VDSP128__";
87 Builder
.defineMacro(vdspv1_64
);
88 Builder
.defineMacro(vdspv1_64
.lower());
89 Builder
.defineMacro(vdspv1_128
);
90 Builder
.defineMacro(vdspv1_128
.lower());
93 StringRef is3e3r1
= "__CSKY_3E3R1__";
94 Builder
.defineMacro(is3e3r1
);
95 Builder
.defineMacro(is3e3r1
.lower());
99 bool CSKYTargetInfo::hasFeature(StringRef Feature
) const {
100 return llvm::StringSwitch
<bool>(Feature
)
101 .Case("hard-float", HardFloat
)
102 .Case("hard-float-abi", HardFloatABI
)
103 .Case("fpuv2_sf", FPUV2_SF
)
104 .Case("fpuv2_df", FPUV2_DF
)
105 .Case("fpuv3_sf", FPUV3_SF
)
106 .Case("fpuv3_df", FPUV3_DF
)
107 .Case("vdspv2", VDSPV2
)
108 .Case("dspv2", DSPV2
)
109 .Case("vdspv1", VDSPV1
)
110 .Case("3e3r1", is3E3R1
)
114 bool CSKYTargetInfo::handleTargetFeatures(std::vector
<std::string
> &Features
,
115 DiagnosticsEngine
&Diags
) {
116 for (const auto &Feature
: Features
) {
117 if (Feature
== "+hard-float")
119 if (Feature
== "+hard-float-abi")
121 if (Feature
== "+fpuv2_sf")
123 if (Feature
== "+fpuv2_df")
125 if (Feature
== "+fpuv3_sf")
127 if (Feature
== "+fpuv3_df")
129 if (Feature
== "+vdspv2")
131 if (Feature
== "+dspv2")
133 if (Feature
== "+vdspv1")
135 if (Feature
== "+3e3r1")
142 ArrayRef
<Builtin::Info
> CSKYTargetInfo::getTargetBuiltins() const {
143 return ArrayRef
<Builtin::Info
>();
146 ArrayRef
<const char *> CSKYTargetInfo::getGCCRegNames() const {
147 static const char *const GCCRegNames
[] = {
182 // Floating point registers
217 return llvm::ArrayRef(GCCRegNames
);
220 ArrayRef
<TargetInfo::GCCRegAlias
> CSKYTargetInfo::getGCCRegAliases() const {
221 static const TargetInfo::GCCRegAlias GCCRegAliases
[] = {
245 {{"t7", "fp"}, "r23"},
246 {{"t8", "top"}, "r24"},
247 {{"t9", "bsp"}, "r25"},
250 {{"gb", "rgb", "rdb"}, "r28"},
251 {{"tb", "rtb"}, "r29"},
289 return llvm::ArrayRef(GCCRegAliases
);
292 bool CSKYTargetInfo::validateAsmConstraint(
293 const char *&Name
, TargetInfo::ConstraintInfo
&Info
) const {
304 case 'v': // A floating-point and vector register.
306 Info
.setAllowsRegister();
311 unsigned CSKYTargetInfo::getMinGlobalAlign(uint64_t Size
) const {