diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake --- a/llvm/cmake/modules/TableGen.cmake +++ b/llvm/cmake/modules/TableGen.cmake @@ -6,6 +6,12 @@ function(tablegen project ofn) cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN}) + + # Override ${project} with ${project}_TABLEGEN_PROJECT + if(NOT "${${project}_TABLEGEN_PROJECT}" STREQUAL "") + set(project ${${project}_TABLEGEN_PROJECT}) + endif() + # Validate calling context. if(NOT ${project}_TABLEGEN_EXE) message(FATAL_ERROR "${project}_TABLEGEN_EXE not set") @@ -153,8 +159,15 @@ set(${project}_TABLEGEN_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/${target}${LLVM_HOST_EXECUTABLE_SUFFIX}") endif() endif() - set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}" CACHE + + if(ADD_TABLEGEN_EXPORT) + set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}" CACHE STRING "Native TableGen executable. Saves building one when cross-compiling.") + else() + # Internal tablegen + set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}") + set_target_properties(${target} PROPERTIES EXCLUDE_FROM_ALL ON) + endif() # Effective tblgen executable to be used: set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN} PARENT_SCOPE) diff --git a/llvm/include/llvm/CMakeLists.txt b/llvm/include/llvm/CMakeLists.txt --- a/llvm/include/llvm/CMakeLists.txt +++ b/llvm/include/llvm/CMakeLists.txt @@ -1,3 +1,7 @@ +# Use LLVM_HEADERS for each `tablegen(LLVM)` in subdirectories +# LLVM_HEADERS_TABLEGEN points to `llvm-min-tblgen` +set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS) + add_subdirectory(IR) add_subdirectory(Support) add_subdirectory(Frontend) diff --git a/llvm/include/llvm/module.modulemap b/llvm/include/llvm/module.modulemap --- a/llvm/include/llvm/module.modulemap +++ b/llvm/include/llvm/module.modulemap @@ -234,72 +234,16 @@ module InitializePasses { header "InitializePasses.h" export * } } -module LLVM_intrinsic_gen { - requires cplusplus - - // Delay building the modules containing dependencies to Attributes.h and - // Intrinsics.h because they need to be generated by tablegen first. - - // Attributes.h - module IR_Argument { header "IR/Argument.h" export * } - module IR_Attributes { - header "IR/Attributes.h" - extern module LLVM_Extern_IR_Attributes_Gen "module.extern.modulemap" - export * - } - module IR_AbstractCallSite { header "IR/AbstractCallSite.h" export * } - module IR_ConstantFold { header "IR/ConstantFold.h" export * } - module IR_ConstantFolder { header "IR/ConstantFolder.h" export * } - module IR_GlobalVariable { header "IR/GlobalVariable.h" export * } - module IR_NoFolder { header "IR/NoFolder.h" export * } - module IRBuilderFolder { header "IR/IRBuilderFolder.h" export * } - module IR_Module { header "IR/Module.h" export * } - module IR_ModuleSummaryIndex { header "IR/ModuleSummaryIndex.h" export * } - module IR_ModuleSummaryIndexYAML { header "IR/ModuleSummaryIndexYAML.h" export * } - module IR_Function { header "IR/Function.h" export * } - module IR_InstrTypes { header "IR/InstrTypes.h" export * } - module IR_Instructions { header "IR/Instructions.h" export * } - module IR_TypeFinder { header "IR/TypeFinder.h" export * } - module IR_VectorBuilder { header "IR/VectorBuilder.h" export * } - - - // Intrinsics.h - module IR_CFG { header "IR/CFG.h" export * } - module IR_ConstantRange { header "IR/ConstantRange.h" export * } - module IR_Dominators { header "IR/Dominators.h" export * } - module IR_FixedPointBuilder { header "IR/FixedPointBuilder.h" export * } - module Analysis_PostDominators { header "Analysis/PostDominators.h" export * } - module Analysis_DomTreeUpdater { header "Analysis/DomTreeUpdater.h" export * } - module IR_IRBuilder { header "IR/IRBuilder.h" export * } - module IR_IRPrintingPasses { header "IR/IRPrintingPasses.h" export * } - module IR_MatrixBuilder { header "IR/MatrixBuilder.h" export * } - module IR_PassManager { header "IR/PassManager.h" export * } - module IR_PassManagerImpl { header "IR/PassManagerImpl.h" export * } - module IR_PredIteratorCache { header "IR/PredIteratorCache.h" export * } - module IR_Verifier { header "IR/Verifier.h" export * } - module IR_InstIterator { header "IR/InstIterator.h" export * } - module IR_InstVisitor { header "IR/InstVisitor.h" export * } - module IR_Intrinsics { - header "IR/Intrinsics.h" - extern module LLVM_Extern_IR_Intricsics_Gen "module.extern.modulemap" - extern module LLVM_Extern_IR_Intrinsics_Enum "module.extern.modulemap" - export * - } - module IR_IntrinsicInst { header "IR/IntrinsicInst.h" export * } - module IR_PatternMatch { header "IR/PatternMatch.h" export * } - module IR_SafepointIRVerifier { header "IR/SafepointIRVerifier.h" export * } - module IR_Statepoint { header "IR/Statepoint.h" export * } - module IR_DebugInfo { header "IR/DebugInfo.h" export * } - - export * -} - module LLVM_IR { requires cplusplus umbrella "IR" module * { export * } + extern module LLVM_Extern_IR_Attributes_Gen "module.extern.modulemap" + extern module LLVM_Extern_IR_Intricsics_Gen "module.extern.modulemap" + extern module LLVM_Extern_IR_Intrinsics_Enum "module.extern.modulemap" + // These are intended for (repeated) textual inclusion. textual header "IR/ConstrainedOps.def" textual header "IR/DebugInfoFlags.def" @@ -336,15 +280,6 @@ module * { export * } } -// Used by llvm-tblgen -module LLVM_MC_TableGen { - requires cplusplus - module MC_LaneBitmask { header "MC/LaneBitmask.h" export * } - module MC_InstrItineraries { header "MC/MCInstrItineraries.h" export * } - module MC_Schedule { header "MC/MCSchedule.h" export * } - module MC_SubtargetFeature { header "MC/SubtargetFeature.h" export * } -} - module LLVM_Object { requires cplusplus umbrella "Object" diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -1,3 +1,4 @@ +set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS) set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/include/llvm/CodeGen/ValueTypes.td) tablegen(LLVM GenVT.inc -gen-vt) diff --git a/llvm/utils/TableGen/CMakeLists.txt b/llvm/utils/TableGen/CMakeLists.txt --- a/llvm/utils/TableGen/CMakeLists.txt +++ b/llvm/utils/TableGen/CMakeLists.txt @@ -2,20 +2,32 @@ set(LLVM_LINK_COMPONENTS Support) +add_tablegen(llvm-min-tblgen LLVM_HEADERS + Attributes.cpp + CodeGenIntrinsics.cpp + DirectiveEmitter.cpp + IntrinsicEmitter.cpp + RISCVTargetDefEmitter.cpp + SDNodeProperties.cpp + TableGen.cpp + VTEmitter.cpp + PARTIAL_SOURCES_INTENDED + ) +set_target_properties(llvm-min-tblgen PROPERTIES FOLDER "Tablegenning") + add_tablegen(llvm-tblgen LLVM DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" EXPORT LLVM AsmMatcherEmitter.cpp AsmWriterEmitter.cpp AsmWriterInst.cpp - Attributes.cpp + CTagsEmitter.cpp CallingConvEmitter.cpp CodeEmitterGen.cpp CodeGenDAGPatterns.cpp CodeGenHwModes.cpp CodeGenInstAlias.cpp CodeGenInstruction.cpp - CodeGenIntrinsics.cpp CodeGenMapTable.cpp CodeGenRegisters.cpp CodeGenSchedule.cpp @@ -28,7 +40,6 @@ DecoderEmitter.cpp DFAEmitter.cpp DFAPacketizerEmitter.cpp - DirectiveEmitter.cpp DisassemblerEmitter.cpp DXILEmitter.cpp ExegesisEmitter.cpp @@ -38,7 +49,6 @@ InfoByHwMode.cpp InstrInfoEmitter.cpp InstrDocsEmitter.cpp - IntrinsicEmitter.cpp OptEmitter.cpp OptParserEmitter.cpp OptRSTEmitter.cpp @@ -47,14 +57,10 @@ CompressInstEmitter.cpp RegisterBankEmitter.cpp RegisterInfoEmitter.cpp - RISCVTargetDefEmitter.cpp - SDNodeProperties.cpp SearchableTableEmitter.cpp SubtargetEmitter.cpp SubtargetFeatureInfo.cpp - TableGen.cpp Types.cpp - VTEmitter.cpp VarLenCodeEmitterGen.cpp X86DisassemblerTables.cpp X86EVEX2VEXTablesEmitter.cpp @@ -63,7 +69,10 @@ X86ModRMFilters.cpp X86RecognizableInstr.cpp WebAssemblyDisassemblerEmitter.cpp - CTagsEmitter.cpp + $ + + DEPENDS + intrinsics_gen ) target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenGlobalISel) set_target_properties(llvm-tblgen PROPERTIES FOLDER "Tablegenning") diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel @@ -572,6 +572,31 @@ ], ) +cc_binary( + name = "llvm-min-tblgen", + srcs = [ + "utils/TableGen/Attributes.cpp", + "utils/TableGen/CodeGenIntrinsics.cpp", + "utils/TableGen/DirectiveEmitter.cpp", + "utils/TableGen/IntrinsicEmitter.cpp", + "utils/TableGen/RISCVTargetDefEmitter.cpp", + "utils/TableGen/SDNodeProperties.cpp", + "utils/TableGen/TableGen.cpp", + "utils/TableGen/VTEmitter.cpp", + + "utils/TableGen/CodeGenIntrinsics.h", + "utils/TableGen/SDNodeProperties.h", + "utils/TableGen/SequenceToOffsetTable.h", + ], + copts = llvm_copts, + stamp = 0, + deps = [ + ":Support", + ":TableGen", + ":config", + ], +) + cc_library( name = "TableGenGlobalISel", srcs = glob([ @@ -621,6 +646,7 @@ ":TableGen", ":TableGenGlobalISel", ":config", + ":intrinsic_enums_gen", ":llvm-tblgen-headers", ], ) @@ -628,7 +654,7 @@ gentbl( name = "intrinsic_enums_gen", tbl_outs = [("-gen-intrinsic-enums", "include/llvm/IR/IntrinsicEnums.inc")], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/IR/Intrinsics.td", td_srcs = glob([ "include/llvm/CodeGen/*.td", @@ -639,7 +665,7 @@ gentbl( name = "intrinsics_impl_gen", tbl_outs = [("-gen-intrinsic-impl", "include/llvm/IR/IntrinsicImpl.inc")], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/IR/Intrinsics.td", td_srcs = glob([ "include/llvm/CodeGen/*.td", @@ -727,7 +753,7 @@ "-gen-intrinsic-enums -intrinsic-prefix=" + target["intrinsic_prefix"], "include/llvm/IR/Intrinsics" + target["name"] + ".h", )], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/IR/Intrinsics.td", td_srcs = glob([ "include/llvm/CodeGen/*.td", @@ -739,7 +765,7 @@ gentbl( name = "attributes_gen", tbl_outs = [("-gen-attrs", "include/llvm/IR/Attributes.inc")], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/IR/Attributes.td", td_srcs = ["include/llvm/IR/Attributes.td"], ) @@ -1108,7 +1134,7 @@ gentbl( name = "RISCVTargetParserDefGen", tbl_outs = [("-gen-riscv-target-def", "include/llvm/TargetParser/RISCVTargetParserDef.inc")], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "lib/Target/RISCV/RISCV.td", td_srcs = [ ":common_target_td_sources", @@ -1375,7 +1401,7 @@ tbl_outs = [ ("--gen-directive-decl", "include/llvm/Frontend/OpenMP/OMP.h.inc"), ], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/Frontend/OpenMP/OMP.td", td_srcs = [":omp_td_files"], ) @@ -1386,7 +1412,7 @@ tbl_outs = [ ("--gen-directive-impl", "include/llvm/Frontend/OpenMP/OMP.inc"), ], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/Frontend/OpenMP/OMP.td", td_srcs = [":omp_td_files"], ) @@ -1434,7 +1460,7 @@ tbl_outs = [ ("--gen-directive-decl", "include/llvm/Frontend/OpenACC/ACC.h.inc"), ], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/Frontend/OpenACC/ACC.td", td_srcs = [":acc_td_files"], ) @@ -1445,7 +1471,7 @@ tbl_outs = [ ("--gen-directive-impl", "include/llvm/Frontend/OpenACC/ACC.inc"), ], - tblgen = ":llvm-tblgen", + tblgen = ":llvm-min-tblgen", td_file = "include/llvm/Frontend/OpenACC/ACC.td", td_srcs = [":acc_td_files"], ) diff --git a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel @@ -558,7 +558,7 @@ name = "vt_gen", strip_include_prefix = "Support", tbl_outs = [("-gen-vt", "Support/GenVT.inc")], - tblgen = "//llvm:llvm-tblgen", + tblgen = "//llvm:llvm-min-tblgen", td_file = "//llvm:include/llvm/CodeGen/ValueTypes.td", td_srcs = [ "//llvm:include/llvm/CodeGen/ValueTypes.td",