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 + 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) @@ -168,15 +181,15 @@ build_native_tool(${target} ${project}_TABLEGEN_EXE DEPENDS ${target}) set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN_EXE} PARENT_SCOPE) - add_custom_target(${project}-tablegen-host DEPENDS ${${project}_TABLEGEN_EXE}) - set(${project}_TABLEGEN_TARGET ${project}-tablegen-host PARENT_SCOPE) + add_custom_target(${${project}_TABLEGEN}-host DEPENDS ${${project}_TABLEGEN_EXE}) + set(${project}_TABLEGEN_TARGET ${target}-host PARENT_SCOPE) # Create an artificial dependency between tablegen projects, because they # compile the same dependencies, thus using the same build folders. # FIXME: A proper fix requires sequentially chaining tablegens. - if (NOT ${project} STREQUAL LLVM AND TARGET ${project}-tablegen-host AND - TARGET LLVM-tablegen-host) - add_dependencies(${project}-tablegen-host LLVM-tablegen-host) + if (NOT ${project} STREQUAL LLVM AND TARGET ${target}-host AND + TARGET llvm-tblgen-host) + add_dependencies(${target}-host llvm-tblgen-host) endif() # If we're using the host tablegen, and utils were not requested, we have no 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,5 @@ +set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS) + add_subdirectory(IR) add_subdirectory(Support) add_subdirectory(Frontend) 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,7 @@ X86ModRMFilters.cpp X86RecognizableInstr.cpp WebAssemblyDisassemblerEmitter.cpp - CTagsEmitter.cpp + $ ) 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 = "LLVMTableGenGlobalISel", srcs = glob([ @@ -628,7 +653,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 +664,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 +752,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 +764,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 +1133,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", @@ -1376,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"], ) @@ -1387,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"], ) @@ -1435,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"], ) @@ -1446,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"], )