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