xref: /freebsd/contrib/llvm-project/llvm/include/llvm/TargetParser/CSKYTargetParser.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1*bdd1243dSDimitry Andric //===-- CSKYTargetParser - Parser for CSKY target features --------*- C++
2*bdd1243dSDimitry Andric //-*-===//
3*bdd1243dSDimitry Andric //
4*bdd1243dSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*bdd1243dSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
6*bdd1243dSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*bdd1243dSDimitry Andric //
8*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
9*bdd1243dSDimitry Andric //
10*bdd1243dSDimitry Andric // This file implements a target parser to recognise CSKY hardware features
11*bdd1243dSDimitry Andric // such as FPU/CPU/ARCH/extensions and specific support such as HWDIV.
12*bdd1243dSDimitry Andric //
13*bdd1243dSDimitry Andric //===----------------------------------------------------------------------===//
14*bdd1243dSDimitry Andric 
15*bdd1243dSDimitry Andric #ifndef LLVM_TARGETPARSER_CSKYTARGETPARSER_H
16*bdd1243dSDimitry Andric #define LLVM_TARGETPARSER_CSKYTARGETPARSER_H
17*bdd1243dSDimitry Andric 
18*bdd1243dSDimitry Andric #include "llvm/TargetParser/Triple.h"
19*bdd1243dSDimitry Andric #include <vector>
20*bdd1243dSDimitry Andric 
21*bdd1243dSDimitry Andric namespace llvm {
22*bdd1243dSDimitry Andric class StringRef;
23*bdd1243dSDimitry Andric 
24*bdd1243dSDimitry Andric namespace CSKY {
25*bdd1243dSDimitry Andric 
26*bdd1243dSDimitry Andric // Arch extension modifiers for CPUs.
27*bdd1243dSDimitry Andric enum ArchExtKind : uint64_t {
28*bdd1243dSDimitry Andric   AEK_INVALID = 0,
29*bdd1243dSDimitry Andric   AEK_NONE = 1,
30*bdd1243dSDimitry Andric   AEK_FPUV2SF = 1 << 1,
31*bdd1243dSDimitry Andric   AEK_FPUV2DF = 1 << 2,
32*bdd1243dSDimitry Andric   AEK_FDIVDU = 1 << 3,
33*bdd1243dSDimitry Andric   AEK_FPUV3HI = 1 << 4,
34*bdd1243dSDimitry Andric   AEK_FPUV3HF = 1 << 5,
35*bdd1243dSDimitry Andric   AEK_FPUV3SF = 1 << 6,
36*bdd1243dSDimitry Andric   AEK_FPUV3DF = 1 << 7,
37*bdd1243dSDimitry Andric   AEK_FLOATE1 = 1 << 8,
38*bdd1243dSDimitry Andric   AEK_FLOAT1E2 = 1 << 9,
39*bdd1243dSDimitry Andric   AEK_FLOAT1E3 = 1 << 10,
40*bdd1243dSDimitry Andric   AEK_FLOAT3E4 = 1 << 11,
41*bdd1243dSDimitry Andric   AEK_FLOAT7E60 = 1 << 12,
42*bdd1243dSDimitry Andric   AEK_HWDIV = 1 << 13,
43*bdd1243dSDimitry Andric   AEK_STLD = 1 << 14,
44*bdd1243dSDimitry Andric   AEK_PUSHPOP = 1 << 15,
45*bdd1243dSDimitry Andric   AEK_EDSP = 1 << 16,
46*bdd1243dSDimitry Andric   AEK_DSP1E2 = 1 << 17,
47*bdd1243dSDimitry Andric   AEK_DSPE60 = 1 << 18,
48*bdd1243dSDimitry Andric   AEK_DSPV2 = 1 << 19,
49*bdd1243dSDimitry Andric   AEK_DSPSILAN = 1 << 20,
50*bdd1243dSDimitry Andric   AEK_ELRW = 1 << 21,
51*bdd1243dSDimitry Andric   AEK_TRUST = 1 << 22,
52*bdd1243dSDimitry Andric   AEK_JAVA = 1 << 23,
53*bdd1243dSDimitry Andric   AEK_CACHE = 1 << 24,
54*bdd1243dSDimitry Andric   AEK_NVIC = 1 << 25,
55*bdd1243dSDimitry Andric   AEK_DOLOOP = 1 << 26,
56*bdd1243dSDimitry Andric   AEK_HIGHREG = 1 << 27,
57*bdd1243dSDimitry Andric   AEK_SMART = 1 << 28,
58*bdd1243dSDimitry Andric   AEK_VDSP2E3 = 1 << 29,
59*bdd1243dSDimitry Andric   AEK_VDSP2E60F = 1 << 30,
60*bdd1243dSDimitry Andric   AEK_VDSPV2 = 1ULL << 31,
61*bdd1243dSDimitry Andric   AEK_HARDTP = 1ULL << 32,
62*bdd1243dSDimitry Andric   AEK_SOFTTP = 1ULL << 33,
63*bdd1243dSDimitry Andric   AEK_ISTACK = 1ULL << 34,
64*bdd1243dSDimitry Andric   AEK_CONSTPOOL = 1ULL << 35,
65*bdd1243dSDimitry Andric   AEK_STACKSIZE = 1ULL << 36,
66*bdd1243dSDimitry Andric   AEK_CCRT = 1ULL << 37,
67*bdd1243dSDimitry Andric   AEK_VDSPV1 = 1ULL << 38,
68*bdd1243dSDimitry Andric   AEK_E1 = 1ULL << 39,
69*bdd1243dSDimitry Andric   AEK_E2 = 1ULL << 40,
70*bdd1243dSDimitry Andric   AEK_2E3 = 1ULL << 41,
71*bdd1243dSDimitry Andric   AEK_MP = 1ULL << 42,
72*bdd1243dSDimitry Andric   AEK_3E3R1 = 1ULL << 43,
73*bdd1243dSDimitry Andric   AEK_3E3R2 = 1ULL << 44,
74*bdd1243dSDimitry Andric   AEK_3E3R3 = 1ULL << 45,
75*bdd1243dSDimitry Andric   AEK_3E7 = 1ULL << 46,
76*bdd1243dSDimitry Andric   AEK_MP1E2 = 1ULL << 47,
77*bdd1243dSDimitry Andric   AEK_7E10 = 1ULL << 48,
78*bdd1243dSDimitry Andric   AEK_10E60 = 1ULL << 49
79*bdd1243dSDimitry Andric 
80*bdd1243dSDimitry Andric };
81*bdd1243dSDimitry Andric 
82*bdd1243dSDimitry Andric // Arch extension modifiers for CPUs.
83*bdd1243dSDimitry Andric enum MultiArchExtKind : uint64_t {
84*bdd1243dSDimitry Andric   MAEK_E1 = CSKY::AEK_E1 | CSKY::AEK_ELRW,
85*bdd1243dSDimitry Andric   MAEK_E2 = CSKY::AEK_E2 | CSKY::MAEK_E1,
86*bdd1243dSDimitry Andric   MAEK_2E3 = CSKY::AEK_2E3 | CSKY::MAEK_E2,
87*bdd1243dSDimitry Andric   MAEK_MP = CSKY::AEK_MP | CSKY::MAEK_2E3,
88*bdd1243dSDimitry Andric   MAEK_3E3R1 = CSKY::AEK_3E3R1,
89*bdd1243dSDimitry Andric   MAEK_3E3R2 = CSKY::AEK_3E3R1 | CSKY::AEK_3E3R2 | CSKY::AEK_DOLOOP,
90*bdd1243dSDimitry Andric   MAEK_3E7 = CSKY::AEK_3E7 | CSKY::MAEK_2E3,
91*bdd1243dSDimitry Andric   MAEK_MP1E2 = CSKY::AEK_MP1E2 | CSKY::MAEK_3E7,
92*bdd1243dSDimitry Andric   MAEK_7E10 = CSKY::AEK_7E10 | CSKY::MAEK_3E7,
93*bdd1243dSDimitry Andric   MAEK_10E60 = CSKY::AEK_10E60 | CSKY::MAEK_7E10,
94*bdd1243dSDimitry Andric };
95*bdd1243dSDimitry Andric // FPU names.
96*bdd1243dSDimitry Andric enum CSKYFPUKind {
97*bdd1243dSDimitry Andric #define CSKY_FPU(NAME, KIND, VERSION) KIND,
98*bdd1243dSDimitry Andric #include "CSKYTargetParser.def"
99*bdd1243dSDimitry Andric   FK_LAST
100*bdd1243dSDimitry Andric };
101*bdd1243dSDimitry Andric 
102*bdd1243dSDimitry Andric // FPU Version
103*bdd1243dSDimitry Andric enum class FPUVersion {
104*bdd1243dSDimitry Andric   NONE,
105*bdd1243dSDimitry Andric   FPV2,
106*bdd1243dSDimitry Andric   FPV3,
107*bdd1243dSDimitry Andric };
108*bdd1243dSDimitry Andric 
109*bdd1243dSDimitry Andric // Arch names.
110*bdd1243dSDimitry Andric enum class ArchKind {
111*bdd1243dSDimitry Andric #define CSKY_ARCH(NAME, ID, ARCH_BASE_EXT) ID,
112*bdd1243dSDimitry Andric #include "CSKYTargetParser.def"
113*bdd1243dSDimitry Andric };
114*bdd1243dSDimitry Andric 
115*bdd1243dSDimitry Andric // List of Arch Extension names.
116*bdd1243dSDimitry Andric // FIXME: TableGen this.
117*bdd1243dSDimitry Andric struct ExtName {
118*bdd1243dSDimitry Andric   const char *NameCStr;
119*bdd1243dSDimitry Andric   size_t NameLength;
120*bdd1243dSDimitry Andric   uint64_t ID;
121*bdd1243dSDimitry Andric   const char *Feature;
122*bdd1243dSDimitry Andric   const char *NegFeature;
123*bdd1243dSDimitry Andric 
getNameExtName124*bdd1243dSDimitry Andric   StringRef getName() const { return StringRef(NameCStr, NameLength); }
125*bdd1243dSDimitry Andric };
126*bdd1243dSDimitry Andric 
127*bdd1243dSDimitry Andric const CSKY::ExtName CSKYARCHExtNames[] = {
128*bdd1243dSDimitry Andric #define CSKY_ARCH_EXT_NAME(NAME, ID, FEATURE, NEGFEATURE)                      \
129*bdd1243dSDimitry Andric   {NAME, sizeof(NAME) - 1, ID, FEATURE, NEGFEATURE},
130*bdd1243dSDimitry Andric #include "CSKYTargetParser.def"
131*bdd1243dSDimitry Andric };
132*bdd1243dSDimitry Andric 
133*bdd1243dSDimitry Andric // List of CPU names and their arches.
134*bdd1243dSDimitry Andric template <typename T> struct CpuNames {
135*bdd1243dSDimitry Andric   const char *NameCStr;
136*bdd1243dSDimitry Andric   size_t NameLength;
137*bdd1243dSDimitry Andric   T ArchID;
138*bdd1243dSDimitry Andric   uint64_t defaultExt;
139*bdd1243dSDimitry Andric 
getNameCpuNames140*bdd1243dSDimitry Andric   StringRef getName() const { return StringRef(NameCStr, NameLength); }
141*bdd1243dSDimitry Andric };
142*bdd1243dSDimitry Andric const CpuNames<CSKY::ArchKind> CPUNames[] = {
143*bdd1243dSDimitry Andric #define CSKY_CPU_NAME(NAME, ARCH_ID, DEFAULT_EXT)                              \
144*bdd1243dSDimitry Andric   {NAME, sizeof(NAME) - 1, CSKY::ArchKind::ARCH_ID, DEFAULT_EXT},
145*bdd1243dSDimitry Andric #include "llvm/TargetParser/CSKYTargetParser.def"
146*bdd1243dSDimitry Andric };
147*bdd1243dSDimitry Andric 
148*bdd1243dSDimitry Andric // FIXME: TableGen this.
149*bdd1243dSDimitry Andric // The entries must appear in the order listed in CSKY::CSKYFPUKind for correct
150*bdd1243dSDimitry Andric // indexing
151*bdd1243dSDimitry Andric struct FPUName {
152*bdd1243dSDimitry Andric   const char *NameCStr;
153*bdd1243dSDimitry Andric   size_t NameLength;
154*bdd1243dSDimitry Andric   CSKYFPUKind ID;
155*bdd1243dSDimitry Andric   FPUVersion FPUVer;
156*bdd1243dSDimitry Andric 
getNameFPUName157*bdd1243dSDimitry Andric   StringRef getName() const { return StringRef(NameCStr, NameLength); }
158*bdd1243dSDimitry Andric };
159*bdd1243dSDimitry Andric 
160*bdd1243dSDimitry Andric static const FPUName FPUNames[] = {
161*bdd1243dSDimitry Andric #define CSKY_FPU(NAME, KIND, VERSION) {NAME, sizeof(NAME) - 1, KIND, VERSION},
162*bdd1243dSDimitry Andric #include "llvm/TargetParser/CSKYTargetParser.def"
163*bdd1243dSDimitry Andric };
164*bdd1243dSDimitry Andric 
165*bdd1243dSDimitry Andric // List of canonical arch names.
166*bdd1243dSDimitry Andric template <typename T> struct ArchNames {
167*bdd1243dSDimitry Andric   const char *NameCStr;
168*bdd1243dSDimitry Andric   size_t NameLength;
169*bdd1243dSDimitry Andric   T ID;
170*bdd1243dSDimitry Andric   uint64_t archBaseExt;
getNameArchNames171*bdd1243dSDimitry Andric   StringRef getName() const { return StringRef(NameCStr, NameLength); }
172*bdd1243dSDimitry Andric };
173*bdd1243dSDimitry Andric const ArchNames<CSKY::ArchKind> ARCHNames[] = {
174*bdd1243dSDimitry Andric #define CSKY_ARCH(NAME, ID, ARCH_BASE_EXT)                                     \
175*bdd1243dSDimitry Andric   {NAME, sizeof(NAME) - 1, CSKY::ArchKind::ID, ARCH_BASE_EXT},
176*bdd1243dSDimitry Andric #include "llvm/TargetParser/CSKYTargetParser.def"
177*bdd1243dSDimitry Andric };
178*bdd1243dSDimitry Andric 
179*bdd1243dSDimitry Andric StringRef getArchName(ArchKind AK);
180*bdd1243dSDimitry Andric StringRef getDefaultCPU(StringRef Arch);
181*bdd1243dSDimitry Andric StringRef getArchExtName(uint64_t ArchExtKind);
182*bdd1243dSDimitry Andric StringRef getArchExtFeature(StringRef ArchExt);
183*bdd1243dSDimitry Andric uint64_t getDefaultExtensions(StringRef CPU);
184*bdd1243dSDimitry Andric bool getExtensionFeatures(uint64_t Extensions,
185*bdd1243dSDimitry Andric                           std::vector<StringRef> &Features);
186*bdd1243dSDimitry Andric 
187*bdd1243dSDimitry Andric // Information by ID
188*bdd1243dSDimitry Andric StringRef getFPUName(unsigned FPUKind);
189*bdd1243dSDimitry Andric FPUVersion getFPUVersion(unsigned FPUKind);
190*bdd1243dSDimitry Andric 
191*bdd1243dSDimitry Andric bool getFPUFeatures(CSKYFPUKind Kind, std::vector<StringRef> &Features);
192*bdd1243dSDimitry Andric 
193*bdd1243dSDimitry Andric // Parser
194*bdd1243dSDimitry Andric ArchKind parseArch(StringRef Arch);
195*bdd1243dSDimitry Andric ArchKind parseCPUArch(StringRef CPU);
196*bdd1243dSDimitry Andric uint64_t parseArchExt(StringRef ArchExt);
197*bdd1243dSDimitry Andric void fillValidCPUArchList(SmallVectorImpl<StringRef> &Values);
198*bdd1243dSDimitry Andric 
199*bdd1243dSDimitry Andric } // namespace CSKY
200*bdd1243dSDimitry Andric 
201*bdd1243dSDimitry Andric } // namespace llvm
202*bdd1243dSDimitry Andric 
203*bdd1243dSDimitry Andric #endif
204