Skip to content

Commit

Permalink
Introduce llvm-min-tblgen to build public header files
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
chapuni committed May 2, 2023
1 parent 4071dbb commit 243e8f8
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 89 deletions.
15 changes: 14 additions & 1 deletion llvm/cmake/modules/TableGen.cmake
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions 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)
Expand Down
73 changes: 4 additions & 69 deletions llvm/include/llvm/module.modulemap
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions 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)

Expand Down
27 changes: 18 additions & 9 deletions llvm/utils/TableGen/CMakeLists.txt
Expand Up @@ -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
Expand All @@ -28,7 +40,6 @@ add_tablegen(llvm-tblgen LLVM
DecoderEmitter.cpp
DFAEmitter.cpp
DFAPacketizerEmitter.cpp
DirectiveEmitter.cpp
DisassemblerEmitter.cpp
DXILEmitter.cpp
ExegesisEmitter.cpp
Expand All @@ -38,7 +49,6 @@ add_tablegen(llvm-tblgen LLVM
InfoByHwMode.cpp
InstrInfoEmitter.cpp
InstrDocsEmitter.cpp
IntrinsicEmitter.cpp
OptEmitter.cpp
OptParserEmitter.cpp
OptRSTEmitter.cpp
Expand All @@ -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
Expand All @@ -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")
44 changes: 35 additions & 9 deletions utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
Expand Up @@ -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([
Expand Down Expand Up @@ -621,14 +646,15 @@ cc_binary(
":TableGen",
":TableGenGlobalISel",
":config",
":intrinsic_enums_gen",
":llvm-tblgen-headers",
],
)

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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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"],
)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"],
)
Expand All @@ -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"],
)
Expand Down Expand Up @@ -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"],
)
Expand All @@ -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"],
)
Expand Down
Expand Up @@ -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",
Expand Down

0 comments on commit 243e8f8

Please sign in to comment.