LLVM 19.0.0git
CSKYTargetParser.cpp
Go to the documentation of this file.
1//===-- TargetParser - Parser for target features ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements a target parser to recognise CSKY hardware features
11// such as CPU/ARCH names.
12//
13//===----------------------------------------------------------------------===//
14
17
18using namespace llvm;
19
21 std::vector<StringRef> &Features) {
22
23 if (CSKYFPUKind >= FK_LAST || CSKYFPUKind == FK_INVALID)
24 return false;
25
26 switch (CSKYFPUKind) {
27 case FK_AUTO:
28 Features.push_back("+fpuv2_sf");
29 Features.push_back("+fpuv2_df");
30 Features.push_back("+fdivdu");
31 break;
32 case FK_FPV2:
33 Features.push_back("+fpuv2_sf");
34 Features.push_back("+fpuv2_df");
35 break;
36 case FK_FPV2_DIVD:
37 Features.push_back("+fpuv2_sf");
38 Features.push_back("+fpuv2_df");
39 Features.push_back("+fdivdu");
40 break;
41 case FK_FPV2_SF:
42 Features.push_back("+fpuv2_sf");
43 break;
44 case FK_FPV3:
45 Features.push_back("+fpuv3_hf");
46 Features.push_back("+fpuv3_hi");
47 Features.push_back("+fpuv3_sf");
48 Features.push_back("+fpuv3_df");
49 break;
50 case FK_FPV3_HF:
51 Features.push_back("+fpuv3_hf");
52 Features.push_back("+fpuv3_hi");
53 break;
54 case FK_FPV3_HSF:
55 Features.push_back("+fpuv3_hf");
56 Features.push_back("+fpuv3_hi");
57 Features.push_back("+fpuv3_sf");
58 break;
59 case FK_FPV3_SDF:
60 Features.push_back("+fpuv3_sf");
61 Features.push_back("+fpuv3_df");
62 break;
63 default:
64 llvm_unreachable("Unknown FPU Kind");
65 return false;
66 }
67
68 return true;
69}
70
71// ======================================================= //
72// Information by ID
73// ======================================================= //
74
76 return ARCHNames[static_cast<unsigned>(AK)].getName();
77}
78
79// The default cpu's name is same as arch name.
81 ArchKind AK = parseArch(Arch);
82 if (AK == CSKY::ArchKind::INVALID)
83 return StringRef();
84
85 return Arch;
86}
87
88// ======================================================= //
89// Parsers
90// ======================================================= //
92 for (const auto A : ARCHNames) {
93 if (A.getName() == Arch)
94 return A.ID;
95 }
96
97 return CSKY::ArchKind::INVALID;
98}
99
101 for (const auto C : CPUNames) {
102 if (CPU == C.getName())
103 return C.ArchID;
104 }
105
106 return CSKY::ArchKind::INVALID;
107}
108
110 for (const auto &A : CSKYARCHExtNames) {
111 if (ArchExt == A.getName())
112 return A.ID;
113 }
114 return AEK_INVALID;
115}
116
118 for (const CpuNames<CSKY::ArchKind> &Arch : CPUNames) {
119 if (Arch.ArchID != CSKY::ArchKind::INVALID)
120 Values.push_back(Arch.getName());
121 }
122}
123
124StringRef CSKY::getFPUName(unsigned FPUKind) {
125 if (FPUKind >= FK_LAST)
126 return StringRef();
127 return FPUNames[FPUKind].getName();
128}
129
131 if (FPUKind >= FK_LAST)
132 return FPUVersion::NONE;
133 return FPUNames[FPUKind].FPUVer;
134}
135
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 | \
140 DEFAULT_EXT)
141#include "llvm/TargetParser/CSKYTargetParser.def"
143}
144
146 for (const auto &AE : CSKYARCHExtNames)
147 if (ArchExtKind == AE.ID)
148 return AE.getName();
149 return StringRef();
150}
151
153 if (Name.starts_with("no")) {
154 Name = Name.substr(2);
155 return true;
156 }
157 return false;
158}
159
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);
165 }
166
167 return StringRef();
168}
169
171 std::vector<StringRef> &Features) {
173 return false;
174
175 for (const auto &AE : CSKYARCHExtNames) {
176 if ((Extensions & AE.ID) == AE.ID && AE.Feature)
177 Features.push_back(AE.Feature);
178 }
179
180 return true;
181}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static bool stripNegationPrefix(StringRef &Name)
std::string Name
static StringRef getName(Value *V)
cl::list< SPIRV::Extension::Extension > Extensions("spirv-extensions", cl::desc("SPIR-V extensions"), cl::ZeroOrMore, cl::Hidden, cl::values(clEnumValN(SPIRV::Extension::SPV_EXT_shader_atomic_float_add, "SPV_EXT_shader_atomic_float_add", "Adds atomic add instruction on floating-point numbers."), clEnumValN(SPIRV::Extension::SPV_EXT_shader_atomic_float16_add, "SPV_EXT_shader_atomic_float16_add", "Extends the SPV_EXT_shader_atomic_float_add extension to support " "atomically adding to 16-bit floating-point numbers in memory."), clEnumValN(SPIRV::Extension::SPV_EXT_shader_atomic_float_min_max, "SPV_EXT_shader_atomic_float_min_max", "Adds atomic min and max instruction on floating-point numbers."), clEnumValN(SPIRV::Extension::SPV_INTEL_arbitrary_precision_integers, "SPV_INTEL_arbitrary_precision_integers", "Allows generating arbitrary width integer types."), clEnumValN(SPIRV::Extension::SPV_INTEL_optnone, "SPV_INTEL_optnone", "Adds OptNoneINTEL value for Function Control mask that " "indicates a request to not optimize the function."), clEnumValN(SPIRV::Extension::SPV_INTEL_usm_storage_classes, "SPV_INTEL_usm_storage_classes", "Introduces two new storage classes that are sub classes of " "the CrossWorkgroup storage class " "that provides additional information that can enable " "optimization."), clEnumValN(SPIRV::Extension::SPV_INTEL_subgroups, "SPV_INTEL_subgroups", "Allows work items in a subgroup to share data without the " "use of local memory and work group barriers, and to " "utilize specialized hardware to load and store blocks of " "data from images or buffers."), clEnumValN(SPIRV::Extension::SPV_KHR_uniform_group_instructions, "SPV_KHR_uniform_group_instructions", "Allows support for additional group operations within " "uniform control flow."), clEnumValN(SPIRV::Extension::SPV_KHR_no_integer_wrap_decoration, "SPV_KHR_no_integer_wrap_decoration", "Adds decorations to indicate that a given instruction does " "not cause integer wrapping."), clEnumValN(SPIRV::Extension::SPV_KHR_expect_assume, "SPV_KHR_expect_assume", "Provides additional information to a compiler, similar to " "the llvm.assume and llvm.expect intrinsics."), clEnumValN(SPIRV::Extension::SPV_KHR_bit_instructions, "SPV_KHR_bit_instructions", "This enables bit instructions to be used by SPIR-V modules " "without requiring the Shader capability."), clEnumValN(SPIRV::Extension::SPV_KHR_linkonce_odr, "SPV_KHR_linkonce_odr", "Allows to use the LinkOnceODR linkage type that is to let " "a function or global variable to be merged with other functions " "or global variables of the same name when linkage occurs."), clEnumValN(SPIRV::Extension::SPV_KHR_subgroup_rotate, "SPV_KHR_subgroup_rotate", "Adds a new instruction that enables rotating values across " "invocations within a subgroup."), clEnumValN(SPIRV::Extension::SPV_INTEL_variable_length_array, "SPV_INTEL_variable_length_array", "Allows to allocate local arrays whose number of elements " "is unknown at compile time."), clEnumValN(SPIRV::Extension::SPV_INTEL_function_pointers, "SPV_INTEL_function_pointers", "Allows translation of function pointers.")))
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static Triple::ArchType parseArch(StringRef ArchName)
Definition: Triple.cpp:502
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void push_back(const T &Elt)
Definition: SmallVector.h:426
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
R Default(T Value)
Definition: StringSwitch.h:182
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef getFPUName(unsigned FPUKind)
StringRef getArchExtFeature(StringRef ArchExt)
bool getExtensionFeatures(uint64_t Extensions, std::vector< StringRef > &Features)
void fillValidCPUArchList(SmallVectorImpl< StringRef > &Values)
const ArchNames< CSKY::ArchKind > ARCHNames[]
bool getFPUFeatures(CSKYFPUKind Kind, std::vector< StringRef > &Features)
uint64_t parseArchExt(StringRef ArchExt)
FPUVersion getFPUVersion(unsigned FPUKind)
ArchKind parseCPUArch(StringRef CPU)
ArchKind parseArch(StringRef Arch)
StringRef getDefaultCPU(StringRef Arch)
const CSKY::ExtName CSKYARCHExtNames[]
StringRef getArchExtName(uint64_t ArchExtKind)
StringRef getArchName(ArchKind AK)
uint64_t getDefaultExtensions(StringRef CPU)
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18