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("__ELF__");
37 Builder
.defineMacro("__csky__", "2");
38 Builder
.defineMacro("__CSKY__", "2");
39 Builder
.defineMacro("__ckcore__", "2");
40 Builder
.defineMacro("__CKCORE__", "2");
42 Builder
.defineMacro("__CSKYABI__", ABI
== "abiv2" ? "2" : "1");
43 Builder
.defineMacro("__cskyabi__", ABI
== "abiv2" ? "2" : "1");
45 StringRef ArchName
= "ck810";
46 StringRef CPUName
= "ck810";
48 if (Arch
!= llvm::CSKY::ArchKind::INVALID
) {
49 ArchName
= llvm::CSKY::getArchName(Arch
);
53 Builder
.defineMacro("__" + ArchName
.upper() + "__");
54 Builder
.defineMacro("__" + ArchName
.lower() + "__");
55 Builder
.defineMacro("__" + CPUName
.upper() + "__");
56 Builder
.defineMacro("__" + CPUName
.lower() + "__");
58 // TODO: Add support for BE if BE was supported later
59 StringRef endian
= "__cskyLE__";
61 Builder
.defineMacro(endian
);
62 Builder
.defineMacro(endian
.upper());
63 Builder
.defineMacro(endian
.lower());
66 StringRef dspv2
= "__CSKY_DSPV2__";
67 Builder
.defineMacro(dspv2
);
68 Builder
.defineMacro(dspv2
.lower());
72 StringRef vdspv2
= "__CSKY_VDSPV2__";
73 Builder
.defineMacro(vdspv2
);
74 Builder
.defineMacro(vdspv2
.lower());
77 StringRef vdspv2_f
= "__CSKY_VDSPV2_F__";
78 Builder
.defineMacro(vdspv2_f
);
79 Builder
.defineMacro(vdspv2_f
.lower());
83 StringRef vdspv1_64
= "__CSKY_VDSP64__";
84 StringRef vdspv1_128
= "__CSKY_VDSP128__";
86 Builder
.defineMacro(vdspv1_64
);
87 Builder
.defineMacro(vdspv1_64
.lower());
88 Builder
.defineMacro(vdspv1_128
);
89 Builder
.defineMacro(vdspv1_128
.lower());
92 StringRef is3e3r1
= "__CSKY_3E3R1__";
93 Builder
.defineMacro(is3e3r1
);
94 Builder
.defineMacro(is3e3r1
.lower());
98 bool CSKYTargetInfo::hasFeature(StringRef Feature
) const {
99 return llvm::StringSwitch
<bool>(Feature
)
100 .Case("hard-float", HardFloat
)
101 .Case("hard-float-abi", HardFloatABI
)
102 .Case("fpuv2_sf", FPUV2_SF
)
103 .Case("fpuv2_df", FPUV2_DF
)
104 .Case("fpuv3_sf", FPUV3_SF
)
105 .Case("fpuv3_df", FPUV3_DF
)
106 .Case("vdspv2", VDSPV2
)
107 .Case("dspv2", DSPV2
)
108 .Case("vdspv1", VDSPV1
)
109 .Case("3e3r1", is3E3R1
)
113 bool CSKYTargetInfo::handleTargetFeatures(std::vector
<std::string
> &Features
,
114 DiagnosticsEngine
&Diags
) {
115 for (const auto &Feature
: Features
) {
116 if (Feature
== "+hard-float")
118 if (Feature
== "+hard-float-abi")
120 if (Feature
== "+fpuv2_sf")
122 if (Feature
== "+fpuv2_df")
124 if (Feature
== "+fpuv3_sf")
126 if (Feature
== "+fpuv3_df")
128 if (Feature
== "+vdspv2")
130 if (Feature
== "+dspv2")
132 if (Feature
== "+vdspv1")
134 if (Feature
== "+3e3r1")
141 ArrayRef
<Builtin::Info
> CSKYTargetInfo::getTargetBuiltins() const {
142 return ArrayRef
<Builtin::Info
>();
145 ArrayRef
<const char *> CSKYTargetInfo::getGCCRegNames() const {
146 static const char *const GCCRegNames
[] = {
181 // Floating point registers
216 return llvm::makeArrayRef(GCCRegNames
);
219 ArrayRef
<TargetInfo::GCCRegAlias
> CSKYTargetInfo::getGCCRegAliases() const {
220 static const TargetInfo::GCCRegAlias GCCRegAliases
[] = {
244 {{"t7", "fp"}, "r23"},
245 {{"t8", "top"}, "r24"},
246 {{"t9", "bsp"}, "r25"},
249 {{"gb", "rgb", "rdb"}, "r28"},
250 {{"tb", "rtb"}, "r29"},
288 return llvm::makeArrayRef(GCCRegAliases
);
291 bool CSKYTargetInfo::validateAsmConstraint(
292 const char *&Name
, TargetInfo::ConstraintInfo
&Info
) const {
303 case 'v': // A floating-point and vector register.
305 Info
.setAllowsRegister();
310 unsigned CSKYTargetInfo::getMinGlobalAlign(uint64_t Size
) const {