diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -1146,6 +1146,14 @@ add_subdirectory(utils/TableGen) +# Some of the RISCV-specific bits in LLVMTargetParser are generated +# via TableGen. Do not bother in autogenerating the enums needed by +# RISCV if we are not building a compiler that targets RISCV. +set(RISCV_AUTOGEN_TARGETPARSER OFF) +if("RISCV" IN_LIST LLVM_TARGETS_TO_BUILD) + set (RISCV_AUTOGEN_TARGETPARSER ON) +endif() + add_subdirectory(include) add_subdirectory(lib) diff --git a/llvm/include/llvm/TargetParser/CMakeLists.txt b/llvm/include/llvm/TargetParser/CMakeLists.txt --- a/llvm/include/llvm/TargetParser/CMakeLists.txt +++ b/llvm/include/llvm/TargetParser/CMakeLists.txt @@ -1,3 +1,5 @@ -set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/RISCV.td) -tablegen(LLVM RISCVTargetParserDef.inc -gen-riscv-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/) -add_public_tablegen_target(RISCVTargetParserTableGen) +if(RISCV_AUTOGEN_TARGETPARSER) + set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/RISCV.td) + tablegen(LLVM RISCVTargetParserDef.inc -gen-riscv-target-def -I ${PROJECT_SOURCE_DIR}/lib/Target/RISCV/) + add_public_tablegen_target(RISCVTargetParserTableGen) +endif() diff --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt --- a/llvm/lib/TargetParser/CMakeLists.txt +++ b/llvm/lib/TargetParser/CMakeLists.txt @@ -27,7 +27,9 @@ LINK_COMPONENTS Support - - DEPENDS - RISCVTargetParserTableGen ) + +if (RISCV_AUTOGEN_TARGETPARSER) + add_dependencies(LLVMTargetParser RISCVTargetParserTableGen) + target_compile_options(LLVMTargetParser PRIVATE -DRISCV_AUTOGEN_TARGETPARSER) +endif() diff --git a/llvm/lib/TargetParser/RISCVTargetParser.cpp b/llvm/lib/TargetParser/RISCVTargetParser.cpp --- a/llvm/lib/TargetParser/RISCVTargetParser.cpp +++ b/llvm/lib/TargetParser/RISCVTargetParser.cpp @@ -20,9 +20,11 @@ namespace RISCV { enum CPUKind : unsigned { +#ifdef RISCV_AUTOGEN_TARGETPARSER #define PROC(ENUM, NAME, DEFAULT_MARCH) CK_##ENUM, #define TUNE_PROC(ENUM, NAME) CK_##ENUM, #include "llvm/TargetParser/RISCVTargetParserDef.inc" +#endif }; struct CPUInfo { @@ -32,9 +34,13 @@ }; constexpr CPUInfo RISCVCPUInfo[] = { +#ifdef RISCV_AUTOGEN_TARGETPARSER #define PROC(ENUM, NAME, DEFAULT_MARCH) \ {NAME, DEFAULT_MARCH}, #include "llvm/TargetParser/RISCVTargetParserDef.inc" +#else + {"invalid", "invalid"} +#endif }; static const CPUInfo *getCPUInfoByName(StringRef CPU) { @@ -53,6 +59,7 @@ } bool parseTuneCPU(StringRef TuneCPU, bool IsRV64) { +#ifdef RISCV_AUTOGEN_TARGETPARSER std::optional Kind = llvm::StringSwitch>(TuneCPU) #define TUNE_PROC(ENUM, NAME) .Case(NAME, CK_##ENUM) @@ -61,7 +68,9 @@ if (Kind.has_value()) return true; - +#else + return false; +#endif // Fallback to parsing as a CPU. return parseCPU(TuneCPU, IsRV64); } @@ -85,8 +94,10 @@ if (IsRV64 == C.is64Bit()) Values.emplace_back(C.Name); } +#ifdef RISCV_AUTOGEN_TARGETPARSER #define TUNE_PROC(ENUM, NAME) Values.emplace_back(StringRef(NAME)); #include "llvm/TargetParser/RISCVTargetParserDef.inc" +#endif } } // namespace RISCV