[llvm] 243e8f8 - Introduce `llvm-min-tblgen` to build public header files
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Mon May 1 19:36:09 PDT 2023
Author: NAKAMURA Takumi
Date: 2023-05-02T11:32:22+09:00
New Revision: 243e8f8d23ac71717115c73725658dac071ac4c2
URL: https://github.com/llvm/llvm-project/commit/243e8f8d23ac71717115c73725658dac071ac4c2
DIFF: https://github.com/llvm/llvm-project/commit/243e8f8d23ac71717115c73725658dac071ac4c2.diff
LOG: Introduce `llvm-min-tblgen` to build public header files
`llvm-min-tblgen` is capable of building `llvm/include/llvm`;
- `-gen-attrs`
- `-gen-directive-*`
- `-gen-intrinsics-*`
- `-gen-riscv-target-def`
`llvm-min-tblgen` is built and used only when `llvm-tblgen` is built in-tree.
This is not installed.
`llvm-tblgen` is built with complete set and may be installed.
`check-llvm` uses not `llvm-min-tblgen` but `llvm-tblgen`.
`LLVM_TABLEGEN_PROJECT` overrides the definition of `tablegen(project)`.
`LLVM_HEADERS` is used as the overridden prefix for LLVM header generators.
If `EXPORT` is not specified in `add_tablegen`, its tablegen is treated as internal.
Let `llvm-tblgen` depend on `intrinsics_gen`
Depends on D149072
Differential Revision: https://reviews.llvm.org/D146352
Added:
Modified:
llvm/cmake/modules/TableGen.cmake
llvm/include/llvm/CMakeLists.txt
llvm/include/llvm/module.modulemap
llvm/unittests/Support/CMakeLists.txt
llvm/utils/TableGen/CMakeLists.txt
utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
Removed:
################################################################################
diff --git a/llvm/cmake/modules/TableGen.cmake b/llvm/cmake/modules/TableGen.cmake
index 6f84e994156b9..66303450b2979 100644
--- a/llvm/cmake/modules/TableGen.cmake
+++ b/llvm/cmake/modules/TableGen.cmake
@@ -6,6 +6,12 @@ include(LLVMDistributionSupport)
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 @@ macro(add_tablegen target project)
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
index d1dc0a99463ba..7c390fcfac1ad 100644
--- 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
index ec986cb8c3d29..d6dbc2b9cf48b 100644
--- a/llvm/include/llvm/module.modulemap
+++ b/llvm/include/llvm/module.modulemap
@@ -234,72 +234,16 @@ module LLVM_Pass {
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 LLVM_MC {
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
index 773d0049af77d..5e494f7daf750 100644
--- 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
index 3d6f96bcb7fc4..b078e883610de 100644
--- a/llvm/utils/TableGen/CMakeLists.txt
+++ b/llvm/utils/TableGen/CMakeLists.txt
@@ -2,20 +2,32 @@ add_subdirectory(GlobalISel)
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 @@ add_tablegen(llvm-tblgen LLVM
DecoderEmitter.cpp
DFAEmitter.cpp
DFAPacketizerEmitter.cpp
- DirectiveEmitter.cpp
DisassemblerEmitter.cpp
DXILEmitter.cpp
ExegesisEmitter.cpp
@@ -38,7 +49,6 @@ add_tablegen(llvm-tblgen LLVM
InfoByHwMode.cpp
InstrInfoEmitter.cpp
InstrDocsEmitter.cpp
- IntrinsicEmitter.cpp
OptEmitter.cpp
OptParserEmitter.cpp
OptRSTEmitter.cpp
@@ -47,14 +57,10 @@ add_tablegen(llvm-tblgen LLVM
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 @@ add_tablegen(llvm-tblgen LLVM
X86ModRMFilters.cpp
X86RecognizableInstr.cpp
WebAssemblyDisassemblerEmitter.cpp
- CTagsEmitter.cpp
+ $<TARGET_OBJECTS:llvm-min-tblgen>
+
+ 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
index 3ebc98e7fcfd5..38b9f4028ebad 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -572,6 +572,31 @@ cc_library(
],
)
+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 @@ cc_binary(
":TableGen",
":TableGenGlobalISel",
":config",
+ ":intrinsic_enums_gen",
":llvm-tblgen-headers",
],
)
@@ -628,7 +654,7 @@ cc_binary(
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(
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 @@ llvm_target_intrinsics_list = [
"-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 @@ llvm_target_intrinsics_list = [
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 @@ cc_library(
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 @@ gentbl(
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 @@ gentbl(
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 @@ gentbl(
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 @@ gentbl(
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
index cfe9a18f4a03c..d7937f8d12123 100644
--- a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
@@ -558,7 +558,7 @@ gentbl(
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",
More information about the llvm-commits
mailing list