forked from OSchip/llvm-project
[gn build] Add template for running llvm-tblgen and use it to add build file for llvm/lib/IR.
Also adds a boring build file for llvm/lib/BinaryFormat (needed by llvm/lib/IR). lib/IR marks Attributes and IntrinsicsEnum as public_deps (because IR's public headers include the generated .inc files), so projects depending on lib/IR will implicitly depend on them being generated. As a consequence, most targets won't have to explicitly list a dependency on these tablegen steps (contrast with intrinsics_gen in the cmake build). This doesn't yet have the optimization where tablegen's output is only updated if it's changed. Differential Revision: https://reviews.llvm.org/D55028#inline-486755 llvm-svn: 347927
This commit is contained in:
parent
55fcb4e90e
commit
8a2454cab8
|
@ -0,0 +1,8 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
"""Runs tablegen."""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Prefix with ./ to run built binary, not arbitrary stuff from PATH.
|
||||||
|
sys.exit(subprocess.call(['./' + sys.argv[1]] + sys.argv[2:]))
|
|
@ -1,7 +1,8 @@
|
||||||
group("default") {
|
group("default") {
|
||||||
deps = [
|
deps = [
|
||||||
"//llvm/utils/TableGen:llvm-tblgen",
|
"//llvm/lib/IR",
|
||||||
"//llvm/tools/llvm-undname",
|
"//llvm/tools/llvm-undname",
|
||||||
|
"//llvm/utils/TableGen:llvm-tblgen",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
import("//llvm/utils/TableGen/tablegen.gni")
|
||||||
|
|
||||||
|
tablegen("IntrinsicEnums") {
|
||||||
|
visibility = [ "//llvm/lib/IR" ]
|
||||||
|
args = [ "-gen-intrinsic-enums" ]
|
||||||
|
td_file = "Intrinsics.td"
|
||||||
|
}
|
||||||
|
|
||||||
|
tablegen("IntrinsicImpl") {
|
||||||
|
visibility = [ "//llvm/lib/IR" ]
|
||||||
|
args = [ "-gen-intrinsic-impl" ]
|
||||||
|
td_file = "Intrinsics.td"
|
||||||
|
}
|
||||||
|
|
||||||
|
tablegen("Attributes") {
|
||||||
|
visibility = [ "//llvm/lib/IR" ]
|
||||||
|
args = [ "-gen-attrs" ]
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
static_library("BinaryFormat") {
|
||||||
|
output_name = "LLVMBinaryFormat"
|
||||||
|
deps = [
|
||||||
|
"//llvm/lib/Support",
|
||||||
|
]
|
||||||
|
sources = [
|
||||||
|
"Dwarf.cpp",
|
||||||
|
"Magic.cpp",
|
||||||
|
"MsgPackReader.cpp",
|
||||||
|
"MsgPackWriter.cpp",
|
||||||
|
"Wasm.cpp",
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,81 @@
|
||||||
|
import("//llvm/utils/TableGen/tablegen.gni")
|
||||||
|
|
||||||
|
tablegen("AttributesCompatFunc") {
|
||||||
|
visibility = [ ":IR" ]
|
||||||
|
args = [ "-gen-attrs" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
static_library("IR") {
|
||||||
|
output_name = "LLVMCore"
|
||||||
|
public_deps = [
|
||||||
|
# Must be public_dep because IR's public headers include llvm-config.h.
|
||||||
|
"//llvm/include/llvm/Config:llvm-config",
|
||||||
|
|
||||||
|
# Must be public_dep because IR's public headers include Attributes.inc.
|
||||||
|
"//llvm/include/llvm/IR:Attributes",
|
||||||
|
|
||||||
|
# Must be public_dep because IR's public headers include IntrinsicEnums.inc.
|
||||||
|
"//llvm/include/llvm/IR:IntrinsicEnums",
|
||||||
|
]
|
||||||
|
deps = [
|
||||||
|
":AttributesCompatFunc",
|
||||||
|
"//llvm/include/llvm/IR:IntrinsicImpl",
|
||||||
|
"//llvm/lib/BinaryFormat",
|
||||||
|
"//llvm/lib/Support",
|
||||||
|
]
|
||||||
|
sources = [
|
||||||
|
"AsmWriter.cpp",
|
||||||
|
"Attributes.cpp",
|
||||||
|
"AutoUpgrade.cpp",
|
||||||
|
"BasicBlock.cpp",
|
||||||
|
"Comdat.cpp",
|
||||||
|
"ConstantFold.cpp",
|
||||||
|
"ConstantRange.cpp",
|
||||||
|
"Constants.cpp",
|
||||||
|
"Core.cpp",
|
||||||
|
"DIBuilder.cpp",
|
||||||
|
"DataLayout.cpp",
|
||||||
|
"DebugInfo.cpp",
|
||||||
|
"DebugInfoMetadata.cpp",
|
||||||
|
"DebugLoc.cpp",
|
||||||
|
"DiagnosticHandler.cpp",
|
||||||
|
"DiagnosticInfo.cpp",
|
||||||
|
"DiagnosticPrinter.cpp",
|
||||||
|
"DomTreeUpdater.cpp",
|
||||||
|
"Dominators.cpp",
|
||||||
|
"Function.cpp",
|
||||||
|
"GVMaterializer.cpp",
|
||||||
|
"Globals.cpp",
|
||||||
|
"IRBuilder.cpp",
|
||||||
|
"IRPrintingPasses.cpp",
|
||||||
|
"InlineAsm.cpp",
|
||||||
|
"Instruction.cpp",
|
||||||
|
"Instructions.cpp",
|
||||||
|
"IntrinsicInst.cpp",
|
||||||
|
"LLVMContext.cpp",
|
||||||
|
"LLVMContextImpl.cpp",
|
||||||
|
"LegacyPassManager.cpp",
|
||||||
|
"MDBuilder.cpp",
|
||||||
|
"Mangler.cpp",
|
||||||
|
"Metadata.cpp",
|
||||||
|
"Module.cpp",
|
||||||
|
"ModuleSummaryIndex.cpp",
|
||||||
|
"Operator.cpp",
|
||||||
|
"OptBisect.cpp",
|
||||||
|
"Pass.cpp",
|
||||||
|
"PassInstrumentation.cpp",
|
||||||
|
"PassManager.cpp",
|
||||||
|
"PassRegistry.cpp",
|
||||||
|
"PassTimingInfo.cpp",
|
||||||
|
"ProfileSummary.cpp",
|
||||||
|
"SafepointIRVerifier.cpp",
|
||||||
|
"Statepoint.cpp",
|
||||||
|
"Type.cpp",
|
||||||
|
"TypeFinder.cpp",
|
||||||
|
"Use.cpp",
|
||||||
|
"User.cpp",
|
||||||
|
"Value.cpp",
|
||||||
|
"ValueSymbolTable.cpp",
|
||||||
|
"Verifier.cpp",
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
# This file defines a template for running llvm-tblgen.
|
||||||
|
#
|
||||||
|
# Parameters:
|
||||||
|
#
|
||||||
|
# args (required)
|
||||||
|
# [list of strings] Flags to pass to llvm-tblgen.
|
||||||
|
#
|
||||||
|
# output_name (optional)
|
||||||
|
# Basename of the generated output file.
|
||||||
|
# Defaults to target name with ".inc" appended.
|
||||||
|
#
|
||||||
|
# td_file (roptional)
|
||||||
|
# The .td file to pass to llvm-tblgen.
|
||||||
|
# Defaults to target name with ".td" appended.
|
||||||
|
#
|
||||||
|
# visibility (optional)
|
||||||
|
# GN's regular visibility attribute, see `gn help visibility`.
|
||||||
|
#
|
||||||
|
# Example use:
|
||||||
|
#
|
||||||
|
# tablegen("attributes_compat_func_gen") {
|
||||||
|
# visibility = [ ":IR" ]
|
||||||
|
# args = [ "-gen-attrs" ]
|
||||||
|
# td_file = "AttributesCompatFunc.td"
|
||||||
|
# }
|
||||||
|
|
||||||
|
template("tablegen") {
|
||||||
|
assert(defined(invoker.args), "args must be defined for $target_name")
|
||||||
|
|
||||||
|
config_name = "${target_name}_config"
|
||||||
|
config(config_name) {
|
||||||
|
visibility = [ ":$target_name" ]
|
||||||
|
include_dirs = [ target_gen_dir ]
|
||||||
|
}
|
||||||
|
|
||||||
|
action(target_name) {
|
||||||
|
forward_variables_from(invoker, [ "visibility" ])
|
||||||
|
|
||||||
|
# FIXME: In cross builds, this should depend on the host binary.
|
||||||
|
tblgen_target = "//llvm/utils/TableGen:llvm-tblgen"
|
||||||
|
tblgen_executable = get_label_info(tblgen_target, "root_out_dir") +
|
||||||
|
"/bin/" + get_label_info(tblgen_target, "name")
|
||||||
|
deps = [
|
||||||
|
tblgen_target,
|
||||||
|
]
|
||||||
|
if (defined(invoker.td_file)) {
|
||||||
|
td_file = invoker.td_file
|
||||||
|
} else {
|
||||||
|
td_file = "$target_name.td"
|
||||||
|
}
|
||||||
|
sources = [
|
||||||
|
td_file,
|
||||||
|
]
|
||||||
|
script = "//llvm/utils/gn/build/run_tablegen.py"
|
||||||
|
if (defined(invoker.output_name)) {
|
||||||
|
gen_output = "$target_gen_dir/" + invoker.output_name
|
||||||
|
} else {
|
||||||
|
gen_output = "$target_gen_dir/$target_name.inc"
|
||||||
|
}
|
||||||
|
depfile = "$gen_output.d"
|
||||||
|
td_file = rebase_path(td_file, root_build_dir)
|
||||||
|
|
||||||
|
# FIXME: The cmake build lets tablegen write to a temp file and then copies
|
||||||
|
# it over the final output only if it has changed, for ninja's restat
|
||||||
|
# optimization. Instead of doing that in cmake, llvm-tblgen should do this
|
||||||
|
# itself. r330742 tried this, but it caused problems. Fix those and reland,
|
||||||
|
# so that the gn build has the optimization too.
|
||||||
|
args = [
|
||||||
|
rebase_path(tblgen_executable, root_build_dir),
|
||||||
|
"-I",
|
||||||
|
rebase_path("//llvm/include", root_build_dir),
|
||||||
|
|
||||||
|
# FIXME: Rather than duplicating this -I flag in both the CMake and
|
||||||
|
# the gn build, let tablegen add input dir to include search path
|
||||||
|
# instead?
|
||||||
|
"-I",
|
||||||
|
get_path_info(td_file, "dir"),
|
||||||
|
"-d",
|
||||||
|
rebase_path(depfile, root_build_dir),
|
||||||
|
"-o",
|
||||||
|
rebase_path(gen_output, root_build_dir),
|
||||||
|
td_file,
|
||||||
|
] + invoker.args
|
||||||
|
outputs = [
|
||||||
|
gen_output,
|
||||||
|
]
|
||||||
|
|
||||||
|
# Let targets depending on this find the generated file.
|
||||||
|
public_configs = [ ":$config_name" ]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue