Skip to content

Commit 243e8f8

Browse files
committed
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
1 parent 4071dbb commit 243e8f8

File tree

7 files changed

+77
-89
lines changed

7 files changed

+77
-89
lines changed

llvm/cmake/modules/TableGen.cmake

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ include(LLVMDistributionSupport)
66

77
function(tablegen project ofn)
88
cmake_parse_arguments(ARG "" "" "DEPENDS;EXTRA_INCLUDES" ${ARGN})
9+
10+
# Override ${project} with ${project}_TABLEGEN_PROJECT
11+
if(NOT "${${project}_TABLEGEN_PROJECT}" STREQUAL "")
12+
set(project ${${project}_TABLEGEN_PROJECT})
13+
endif()
14+
915
# Validate calling context.
1016
if(NOT ${project}_TABLEGEN_EXE)
1117
message(FATAL_ERROR "${project}_TABLEGEN_EXE not set")
@@ -153,8 +159,15 @@ macro(add_tablegen target project)
153159
set(${project}_TABLEGEN_DEFAULT "${LLVM_NATIVE_TOOL_DIR}/${target}${LLVM_HOST_EXECUTABLE_SUFFIX}")
154160
endif()
155161
endif()
156-
set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}" CACHE
162+
163+
if(ADD_TABLEGEN_EXPORT)
164+
set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}" CACHE
157165
STRING "Native TableGen executable. Saves building one when cross-compiling.")
166+
else()
167+
# Internal tablegen
168+
set(${project}_TABLEGEN "${${project}_TABLEGEN_DEFAULT}")
169+
set_target_properties(${target} PROPERTIES EXCLUDE_FROM_ALL ON)
170+
endif()
158171

159172
# Effective tblgen executable to be used:
160173
set(${project}_TABLEGEN_EXE ${${project}_TABLEGEN} PARENT_SCOPE)

llvm/include/llvm/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Use LLVM_HEADERS for each `tablegen(LLVM)` in subdirectories
2+
# LLVM_HEADERS_TABLEGEN points to `llvm-min-tblgen`
3+
set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS)
4+
15
add_subdirectory(IR)
26
add_subdirectory(Support)
37
add_subdirectory(Frontend)

llvm/include/llvm/module.modulemap

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -234,72 +234,16 @@ module LLVM_Pass {
234234
module InitializePasses { header "InitializePasses.h" export * }
235235
}
236236

237-
module LLVM_intrinsic_gen {
238-
requires cplusplus
239-
240-
// Delay building the modules containing dependencies to Attributes.h and
241-
// Intrinsics.h because they need to be generated by tablegen first.
242-
243-
// Attributes.h
244-
module IR_Argument { header "IR/Argument.h" export * }
245-
module IR_Attributes {
246-
header "IR/Attributes.h"
247-
extern module LLVM_Extern_IR_Attributes_Gen "module.extern.modulemap"
248-
export *
249-
}
250-
module IR_AbstractCallSite { header "IR/AbstractCallSite.h" export * }
251-
module IR_ConstantFold { header "IR/ConstantFold.h" export * }
252-
module IR_ConstantFolder { header "IR/ConstantFolder.h" export * }
253-
module IR_GlobalVariable { header "IR/GlobalVariable.h" export * }
254-
module IR_NoFolder { header "IR/NoFolder.h" export * }
255-
module IRBuilderFolder { header "IR/IRBuilderFolder.h" export * }
256-
module IR_Module { header "IR/Module.h" export * }
257-
module IR_ModuleSummaryIndex { header "IR/ModuleSummaryIndex.h" export * }
258-
module IR_ModuleSummaryIndexYAML { header "IR/ModuleSummaryIndexYAML.h" export * }
259-
module IR_Function { header "IR/Function.h" export * }
260-
module IR_InstrTypes { header "IR/InstrTypes.h" export * }
261-
module IR_Instructions { header "IR/Instructions.h" export * }
262-
module IR_TypeFinder { header "IR/TypeFinder.h" export * }
263-
module IR_VectorBuilder { header "IR/VectorBuilder.h" export * }
264-
265-
266-
// Intrinsics.h
267-
module IR_CFG { header "IR/CFG.h" export * }
268-
module IR_ConstantRange { header "IR/ConstantRange.h" export * }
269-
module IR_Dominators { header "IR/Dominators.h" export * }
270-
module IR_FixedPointBuilder { header "IR/FixedPointBuilder.h" export * }
271-
module Analysis_PostDominators { header "Analysis/PostDominators.h" export * }
272-
module Analysis_DomTreeUpdater { header "Analysis/DomTreeUpdater.h" export * }
273-
module IR_IRBuilder { header "IR/IRBuilder.h" export * }
274-
module IR_IRPrintingPasses { header "IR/IRPrintingPasses.h" export * }
275-
module IR_MatrixBuilder { header "IR/MatrixBuilder.h" export * }
276-
module IR_PassManager { header "IR/PassManager.h" export * }
277-
module IR_PassManagerImpl { header "IR/PassManagerImpl.h" export * }
278-
module IR_PredIteratorCache { header "IR/PredIteratorCache.h" export * }
279-
module IR_Verifier { header "IR/Verifier.h" export * }
280-
module IR_InstIterator { header "IR/InstIterator.h" export * }
281-
module IR_InstVisitor { header "IR/InstVisitor.h" export * }
282-
module IR_Intrinsics {
283-
header "IR/Intrinsics.h"
284-
extern module LLVM_Extern_IR_Intricsics_Gen "module.extern.modulemap"
285-
extern module LLVM_Extern_IR_Intrinsics_Enum "module.extern.modulemap"
286-
export *
287-
}
288-
module IR_IntrinsicInst { header "IR/IntrinsicInst.h" export * }
289-
module IR_PatternMatch { header "IR/PatternMatch.h" export * }
290-
module IR_SafepointIRVerifier { header "IR/SafepointIRVerifier.h" export * }
291-
module IR_Statepoint { header "IR/Statepoint.h" export * }
292-
module IR_DebugInfo { header "IR/DebugInfo.h" export * }
293-
294-
export *
295-
}
296-
297237
module LLVM_IR {
298238
requires cplusplus
299239

300240
umbrella "IR"
301241
module * { export * }
302242

243+
extern module LLVM_Extern_IR_Attributes_Gen "module.extern.modulemap"
244+
extern module LLVM_Extern_IR_Intricsics_Gen "module.extern.modulemap"
245+
extern module LLVM_Extern_IR_Intrinsics_Enum "module.extern.modulemap"
246+
303247
// These are intended for (repeated) textual inclusion.
304248
textual header "IR/ConstrainedOps.def"
305249
textual header "IR/DebugInfoFlags.def"
@@ -336,15 +280,6 @@ module LLVM_MC {
336280
module * { export * }
337281
}
338282

339-
// Used by llvm-tblgen
340-
module LLVM_MC_TableGen {
341-
requires cplusplus
342-
module MC_LaneBitmask { header "MC/LaneBitmask.h" export * }
343-
module MC_InstrItineraries { header "MC/MCInstrItineraries.h" export * }
344-
module MC_Schedule { header "MC/MCSchedule.h" export * }
345-
module MC_SubtargetFeature { header "MC/SubtargetFeature.h" export * }
346-
}
347-
348283
module LLVM_Object {
349284
requires cplusplus
350285
umbrella "Object"

llvm/unittests/Support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set(LLVM_TABLEGEN_PROJECT LLVM_HEADERS)
12
set(LLVM_TARGET_DEFINITIONS ${PROJECT_SOURCE_DIR}/include/llvm/CodeGen/ValueTypes.td)
23
tablegen(LLVM GenVT.inc -gen-vt)
34

llvm/utils/TableGen/CMakeLists.txt

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@ add_subdirectory(GlobalISel)
22

33
set(LLVM_LINK_COMPONENTS Support)
44

5+
add_tablegen(llvm-min-tblgen LLVM_HEADERS
6+
Attributes.cpp
7+
CodeGenIntrinsics.cpp
8+
DirectiveEmitter.cpp
9+
IntrinsicEmitter.cpp
10+
RISCVTargetDefEmitter.cpp
11+
SDNodeProperties.cpp
12+
TableGen.cpp
13+
VTEmitter.cpp
14+
PARTIAL_SOURCES_INTENDED
15+
)
16+
set_target_properties(llvm-min-tblgen PROPERTIES FOLDER "Tablegenning")
17+
518
add_tablegen(llvm-tblgen LLVM
619
DESTINATION "${LLVM_TOOLS_INSTALL_DIR}"
720
EXPORT LLVM
821
AsmMatcherEmitter.cpp
922
AsmWriterEmitter.cpp
1023
AsmWriterInst.cpp
11-
Attributes.cpp
24+
CTagsEmitter.cpp
1225
CallingConvEmitter.cpp
1326
CodeEmitterGen.cpp
1427
CodeGenDAGPatterns.cpp
1528
CodeGenHwModes.cpp
1629
CodeGenInstAlias.cpp
1730
CodeGenInstruction.cpp
18-
CodeGenIntrinsics.cpp
1931
CodeGenMapTable.cpp
2032
CodeGenRegisters.cpp
2133
CodeGenSchedule.cpp
@@ -28,7 +40,6 @@ add_tablegen(llvm-tblgen LLVM
2840
DecoderEmitter.cpp
2941
DFAEmitter.cpp
3042
DFAPacketizerEmitter.cpp
31-
DirectiveEmitter.cpp
3243
DisassemblerEmitter.cpp
3344
DXILEmitter.cpp
3445
ExegesisEmitter.cpp
@@ -38,7 +49,6 @@ add_tablegen(llvm-tblgen LLVM
3849
InfoByHwMode.cpp
3950
InstrInfoEmitter.cpp
4051
InstrDocsEmitter.cpp
41-
IntrinsicEmitter.cpp
4252
OptEmitter.cpp
4353
OptParserEmitter.cpp
4454
OptRSTEmitter.cpp
@@ -47,14 +57,10 @@ add_tablegen(llvm-tblgen LLVM
4757
CompressInstEmitter.cpp
4858
RegisterBankEmitter.cpp
4959
RegisterInfoEmitter.cpp
50-
RISCVTargetDefEmitter.cpp
51-
SDNodeProperties.cpp
5260
SearchableTableEmitter.cpp
5361
SubtargetEmitter.cpp
5462
SubtargetFeatureInfo.cpp
55-
TableGen.cpp
5663
Types.cpp
57-
VTEmitter.cpp
5864
VarLenCodeEmitterGen.cpp
5965
X86DisassemblerTables.cpp
6066
X86EVEX2VEXTablesEmitter.cpp
@@ -63,7 +69,10 @@ add_tablegen(llvm-tblgen LLVM
6369
X86ModRMFilters.cpp
6470
X86RecognizableInstr.cpp
6571
WebAssemblyDisassemblerEmitter.cpp
66-
CTagsEmitter.cpp
72+
$<TARGET_OBJECTS:llvm-min-tblgen>
73+
74+
DEPENDS
75+
intrinsics_gen
6776
)
6877
target_link_libraries(llvm-tblgen PRIVATE LLVMTableGenGlobalISel)
6978
set_target_properties(llvm-tblgen PROPERTIES FOLDER "Tablegenning")

utils/bazel/llvm-project-overlay/llvm/BUILD.bazel

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,31 @@ cc_library(
572572
],
573573
)
574574

575+
cc_binary(
576+
name = "llvm-min-tblgen",
577+
srcs = [
578+
"utils/TableGen/Attributes.cpp",
579+
"utils/TableGen/CodeGenIntrinsics.cpp",
580+
"utils/TableGen/DirectiveEmitter.cpp",
581+
"utils/TableGen/IntrinsicEmitter.cpp",
582+
"utils/TableGen/RISCVTargetDefEmitter.cpp",
583+
"utils/TableGen/SDNodeProperties.cpp",
584+
"utils/TableGen/TableGen.cpp",
585+
"utils/TableGen/VTEmitter.cpp",
586+
587+
"utils/TableGen/CodeGenIntrinsics.h",
588+
"utils/TableGen/SDNodeProperties.h",
589+
"utils/TableGen/SequenceToOffsetTable.h",
590+
],
591+
copts = llvm_copts,
592+
stamp = 0,
593+
deps = [
594+
":Support",
595+
":TableGen",
596+
":config",
597+
],
598+
)
599+
575600
cc_library(
576601
name = "TableGenGlobalISel",
577602
srcs = glob([
@@ -621,14 +646,15 @@ cc_binary(
621646
":TableGen",
622647
":TableGenGlobalISel",
623648
":config",
649+
":intrinsic_enums_gen",
624650
":llvm-tblgen-headers",
625651
],
626652
)
627653

628654
gentbl(
629655
name = "intrinsic_enums_gen",
630656
tbl_outs = [("-gen-intrinsic-enums", "include/llvm/IR/IntrinsicEnums.inc")],
631-
tblgen = ":llvm-tblgen",
657+
tblgen = ":llvm-min-tblgen",
632658
td_file = "include/llvm/IR/Intrinsics.td",
633659
td_srcs = glob([
634660
"include/llvm/CodeGen/*.td",
@@ -639,7 +665,7 @@ gentbl(
639665
gentbl(
640666
name = "intrinsics_impl_gen",
641667
tbl_outs = [("-gen-intrinsic-impl", "include/llvm/IR/IntrinsicImpl.inc")],
642-
tblgen = ":llvm-tblgen",
668+
tblgen = ":llvm-min-tblgen",
643669
td_file = "include/llvm/IR/Intrinsics.td",
644670
td_srcs = glob([
645671
"include/llvm/CodeGen/*.td",
@@ -727,7 +753,7 @@ llvm_target_intrinsics_list = [
727753
"-gen-intrinsic-enums -intrinsic-prefix=" + target["intrinsic_prefix"],
728754
"include/llvm/IR/Intrinsics" + target["name"] + ".h",
729755
)],
730-
tblgen = ":llvm-tblgen",
756+
tblgen = ":llvm-min-tblgen",
731757
td_file = "include/llvm/IR/Intrinsics.td",
732758
td_srcs = glob([
733759
"include/llvm/CodeGen/*.td",
@@ -739,7 +765,7 @@ llvm_target_intrinsics_list = [
739765
gentbl(
740766
name = "attributes_gen",
741767
tbl_outs = [("-gen-attrs", "include/llvm/IR/Attributes.inc")],
742-
tblgen = ":llvm-tblgen",
768+
tblgen = ":llvm-min-tblgen",
743769
td_file = "include/llvm/IR/Attributes.td",
744770
td_srcs = ["include/llvm/IR/Attributes.td"],
745771
)
@@ -1108,7 +1134,7 @@ cc_library(
11081134
gentbl(
11091135
name = "RISCVTargetParserDefGen",
11101136
tbl_outs = [("-gen-riscv-target-def", "include/llvm/TargetParser/RISCVTargetParserDef.inc")],
1111-
tblgen = ":llvm-tblgen",
1137+
tblgen = ":llvm-min-tblgen",
11121138
td_file = "lib/Target/RISCV/RISCV.td",
11131139
td_srcs = [
11141140
":common_target_td_sources",
@@ -1375,7 +1401,7 @@ gentbl(
13751401
tbl_outs = [
13761402
("--gen-directive-decl", "include/llvm/Frontend/OpenMP/OMP.h.inc"),
13771403
],
1378-
tblgen = ":llvm-tblgen",
1404+
tblgen = ":llvm-min-tblgen",
13791405
td_file = "include/llvm/Frontend/OpenMP/OMP.td",
13801406
td_srcs = [":omp_td_files"],
13811407
)
@@ -1386,7 +1412,7 @@ gentbl(
13861412
tbl_outs = [
13871413
("--gen-directive-impl", "include/llvm/Frontend/OpenMP/OMP.inc"),
13881414
],
1389-
tblgen = ":llvm-tblgen",
1415+
tblgen = ":llvm-min-tblgen",
13901416
td_file = "include/llvm/Frontend/OpenMP/OMP.td",
13911417
td_srcs = [":omp_td_files"],
13921418
)
@@ -1434,7 +1460,7 @@ gentbl(
14341460
tbl_outs = [
14351461
("--gen-directive-decl", "include/llvm/Frontend/OpenACC/ACC.h.inc"),
14361462
],
1437-
tblgen = ":llvm-tblgen",
1463+
tblgen = ":llvm-min-tblgen",
14381464
td_file = "include/llvm/Frontend/OpenACC/ACC.td",
14391465
td_srcs = [":acc_td_files"],
14401466
)
@@ -1445,7 +1471,7 @@ gentbl(
14451471
tbl_outs = [
14461472
("--gen-directive-impl", "include/llvm/Frontend/OpenACC/ACC.inc"),
14471473
],
1448-
tblgen = ":llvm-tblgen",
1474+
tblgen = ":llvm-min-tblgen",
14491475
td_file = "include/llvm/Frontend/OpenACC/ACC.td",
14501476
td_srcs = [":acc_td_files"],
14511477
)

utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ gentbl(
558558
name = "vt_gen",
559559
strip_include_prefix = "Support",
560560
tbl_outs = [("-gen-vt", "Support/GenVT.inc")],
561-
tblgen = "//llvm:llvm-tblgen",
561+
tblgen = "//llvm:llvm-min-tblgen",
562562
td_file = "//llvm:include/llvm/CodeGen/ValueTypes.td",
563563
td_srcs = [
564564
"//llvm:include/llvm/CodeGen/ValueTypes.td",

0 commit comments

Comments
 (0)