1 //===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements a target parser to recognise CSKY hardware features
11 // such as CPU/ARCH names.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/TargetParser/CSKYTargetParser.h"
16 #include "llvm/ADT/StringSwitch.h"
20 bool CSKY::getFPUFeatures(CSKYFPUKind CSKYFPUKind
,
21 std::vector
<StringRef
> &Features
) {
23 if (CSKYFPUKind
>= FK_LAST
|| CSKYFPUKind
== FK_INVALID
)
26 switch (CSKYFPUKind
) {
28 Features
.push_back("+fpuv2_sf");
29 Features
.push_back("+fpuv2_df");
30 Features
.push_back("+fdivdu");
33 Features
.push_back("+fpuv2_sf");
34 Features
.push_back("+fpuv2_df");
37 Features
.push_back("+fpuv2_sf");
38 Features
.push_back("+fpuv2_df");
39 Features
.push_back("+fdivdu");
42 Features
.push_back("+fpuv2_sf");
45 Features
.push_back("+fpuv3_hf");
46 Features
.push_back("+fpuv3_hi");
47 Features
.push_back("+fpuv3_sf");
48 Features
.push_back("+fpuv3_df");
51 Features
.push_back("+fpuv3_hf");
52 Features
.push_back("+fpuv3_hi");
55 Features
.push_back("+fpuv3_hf");
56 Features
.push_back("+fpuv3_hi");
57 Features
.push_back("+fpuv3_sf");
60 Features
.push_back("+fpuv3_sf");
61 Features
.push_back("+fpuv3_df");
64 llvm_unreachable("Unknown FPU Kind");
71 // ======================================================= //
73 // ======================================================= //
75 StringRef
CSKY::getArchName(ArchKind AK
) {
76 return ARCHNames
[static_cast<unsigned>(AK
)].getName();
79 // The default cpu's name is same as arch name.
80 StringRef
CSKY::getDefaultCPU(StringRef Arch
) {
81 ArchKind AK
= parseArch(Arch
);
82 if (AK
== CSKY::ArchKind::INVALID
)
88 // ======================================================= //
90 // ======================================================= //
91 CSKY::ArchKind
CSKY::parseArch(StringRef Arch
) {
92 for (const auto A
: ARCHNames
) {
93 if (A
.getName() == Arch
)
97 return CSKY::ArchKind::INVALID
;
100 CSKY::ArchKind
CSKY::parseCPUArch(StringRef CPU
) {
101 for (const auto C
: CPUNames
) {
102 if (CPU
== C
.getName())
106 return CSKY::ArchKind::INVALID
;
109 uint64_t CSKY::parseArchExt(StringRef ArchExt
) {
110 for (const auto &A
: CSKYARCHExtNames
) {
111 if (ArchExt
== A
.getName())
117 void CSKY::fillValidCPUArchList(SmallVectorImpl
<StringRef
> &Values
) {
118 for (const CpuNames
<CSKY::ArchKind
> &Arch
: CPUNames
) {
119 if (Arch
.ArchID
!= CSKY::ArchKind::INVALID
)
120 Values
.push_back(Arch
.getName());
124 StringRef
CSKY::getFPUName(unsigned FPUKind
) {
125 if (FPUKind
>= FK_LAST
)
127 return FPUNames
[FPUKind
].getName();
130 CSKY::FPUVersion
CSKY::getFPUVersion(unsigned FPUKind
) {
131 if (FPUKind
>= FK_LAST
)
132 return FPUVersion::NONE
;
133 return FPUNames
[FPUKind
].FPUVer
;
136 uint64_t CSKY::getDefaultExtensions(StringRef CPU
) {
137 return StringSwitch
<uint64_t>(CPU
)
138 #define CSKY_CPU_NAME(NAME, ID, DEFAULT_EXT) \
139 .Case(NAME, ARCHNames[static_cast<unsigned>(ArchKind::ID)].archBaseExt | \
141 #include "llvm/TargetParser/CSKYTargetParser.def"
142 .Default(CSKY::AEK_INVALID
);
145 StringRef
CSKY::getArchExtName(uint64_t ArchExtKind
) {
146 for (const auto &AE
: CSKYARCHExtNames
)
147 if (ArchExtKind
== AE
.ID
)
152 static bool stripNegationPrefix(StringRef
&Name
) {
153 if (Name
.starts_with("no")) {
154 Name
= Name
.substr(2);
160 StringRef
CSKY::getArchExtFeature(StringRef ArchExt
) {
161 bool Negated
= stripNegationPrefix(ArchExt
);
162 for (const auto &AE
: CSKYARCHExtNames
) {
163 if (AE
.Feature
&& ArchExt
== AE
.getName())
164 return StringRef(Negated
? AE
.NegFeature
: AE
.Feature
);
170 bool CSKY::getExtensionFeatures(uint64_t Extensions
,
171 std::vector
<StringRef
> &Features
) {
172 if (Extensions
== CSKY::AEK_INVALID
)
175 for (const auto &AE
: CSKYARCHExtNames
) {
176 if ((Extensions
& AE
.ID
) == AE
.ID
&& AE
.Feature
)
177 Features
.push_back(AE
.Feature
);