[llvm] r347927 - [gn build] Add template for running llvm-tblgen and use it to add build file for llvm/lib/IR.
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 29 14:53:21 PST 2018
Author: nico
Date: Thu Nov 29 14:53:21 2018
New Revision: 347927
URL: http://llvm.org/viewvc/llvm-project?rev=347927&view=rev
Log:
[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
Added:
llvm/trunk/utils/gn/build/run_tablegen.py
llvm/trunk/utils/gn/secondary/llvm/include/llvm/IR/
llvm/trunk/utils/gn/secondary/llvm/include/llvm/IR/BUILD.gn
llvm/trunk/utils/gn/secondary/llvm/lib/BinaryFormat/
llvm/trunk/utils/gn/secondary/llvm/lib/BinaryFormat/BUILD.gn
llvm/trunk/utils/gn/secondary/llvm/lib/IR/
llvm/trunk/utils/gn/secondary/llvm/lib/IR/BUILD.gn
llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni
Modified:
llvm/trunk/utils/gn/secondary/BUILD.gn
Added: llvm/trunk/utils/gn/build/run_tablegen.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/build/run_tablegen.py?rev=347927&view=auto
==============================================================================
--- llvm/trunk/utils/gn/build/run_tablegen.py (added)
+++ llvm/trunk/utils/gn/build/run_tablegen.py Thu Nov 29 14:53:21 2018
@@ -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:]))
Modified: llvm/trunk/utils/gn/secondary/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/BUILD.gn?rev=347927&r1=347926&r2=347927&view=diff
==============================================================================
--- llvm/trunk/utils/gn/secondary/BUILD.gn (original)
+++ llvm/trunk/utils/gn/secondary/BUILD.gn Thu Nov 29 14:53:21 2018
@@ -1,7 +1,8 @@
group("default") {
deps = [
- "//llvm/utils/TableGen:llvm-tblgen",
+ "//llvm/lib/IR",
"//llvm/tools/llvm-undname",
+ "//llvm/utils/TableGen:llvm-tblgen",
]
}
Added: llvm/trunk/utils/gn/secondary/llvm/include/llvm/IR/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/include/llvm/IR/BUILD.gn?rev=347927&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/include/llvm/IR/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/include/llvm/IR/BUILD.gn Thu Nov 29 14:53:21 2018
@@ -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" ]
+}
Added: llvm/trunk/utils/gn/secondary/llvm/lib/BinaryFormat/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/lib/BinaryFormat/BUILD.gn?rev=347927&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/lib/BinaryFormat/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/lib/BinaryFormat/BUILD.gn Thu Nov 29 14:53:21 2018
@@ -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",
+ ]
+}
Added: llvm/trunk/utils/gn/secondary/llvm/lib/IR/BUILD.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/lib/IR/BUILD.gn?rev=347927&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/lib/IR/BUILD.gn (added)
+++ llvm/trunk/utils/gn/secondary/llvm/lib/IR/BUILD.gn Thu Nov 29 14:53:21 2018
@@ -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",
+ ]
+}
Added: llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni?rev=347927&view=auto
==============================================================================
--- llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni (added)
+++ llvm/trunk/utils/gn/secondary/llvm/utils/TableGen/tablegen.gni Thu Nov 29 14:53:21 2018
@@ -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" ]
+ }
+}
More information about the llvm-commits
mailing list