From ddafabeacf74d0024aac35c367d00b5f633dcb5b Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 1 May 2023 15:26:03 -0700 Subject: [PATCH] [RISCV] Remove or simplify some StringSwitches in RISCVTargetParser.cpp. NFC We can iterate over the RISCVCPUInfo table instead of using a separate StringSwitch. --- llvm/lib/TargetParser/RISCVTargetParser.cpp | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/llvm/lib/TargetParser/RISCVTargetParser.cpp b/llvm/lib/TargetParser/RISCVTargetParser.cpp index 9e1a805..6a35754 100644 --- a/llvm/lib/TargetParser/RISCVTargetParser.cpp +++ b/llvm/lib/TargetParser/RISCVTargetParser.cpp @@ -39,40 +39,39 @@ constexpr CPUInfo RISCVCPUInfo[] = { #include "llvm/TargetParser/RISCVTargetParserDef.inc" }; -static CPUKind getCPUByName(StringRef CPU) { - return llvm::StringSwitch(CPU) -#define PROC(ENUM, NAME, DEFAULT_MARCH) .Case(NAME, CK_##ENUM) -#include "llvm/TargetParser/RISCVTargetParserDef.inc" - .Default(CK_INVALID); +static const CPUInfo *getCPUInfoByName(StringRef CPU) { + for (auto &C : RISCVCPUInfo) + if (C.Name == CPU) + return &C; + return nullptr; } bool parseCPU(StringRef CPU, bool IsRV64) { - CPUKind Kind = getCPUByName(CPU); + const CPUInfo *Info = getCPUInfoByName(CPU); - if (Kind == CK_INVALID) + if (!Info) return false; - return RISCVCPUInfo[static_cast(Kind)].is64Bit() == IsRV64; + return Info->is64Bit() == IsRV64; } bool parseTuneCPU(StringRef TuneCPU, bool IsRV64) { CPUKind Kind = llvm::StringSwitch(TuneCPU) -#define PROC(ENUM, NAME, DEFAULT_MARCH) .Case(NAME, CK_##ENUM) -#define TUNE_PROC(ENUM, NAME) .Case(NAME, CK_##ENUM) -#include "llvm/TargetParser/RISCVTargetParserDef.inc" + #define TUNE_PROC(ENUM, NAME) .Case(NAME, CK_##ENUM) + #include "llvm/TargetParser/RISCVTargetParserDef.inc" .Default(CK_INVALID); - if (Kind == CK_INVALID) - return false; -#define TUNE_PROC(ENUM, NAME) \ - if (Kind == CK_##ENUM) \ + if (Kind != CK_INVALID) return true; -#include "llvm/TargetParser/RISCVTargetParserDef.inc" - return RISCVCPUInfo[static_cast(Kind)].is64Bit() == IsRV64; + + // Fallback to parsing as a CPU. + return parseCPU(TuneCPU, IsRV64); } StringRef getMArchFromMcpu(StringRef CPU) { - CPUKind Kind = getCPUByName(CPU); - return RISCVCPUInfo[static_cast(Kind)].DefaultMarch; + const CPUInfo *Info = getCPUInfoByName(CPU); + if (!Info) + return ""; + return Info->DefaultMarch; } void fillValidCPUArchList(SmallVectorImpl &Values, bool IsRV64) { -- 2.7.4