[llvm] 6bb781f - [gn build] Add build files for //bolt

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 21 16:46:27 PST 2022


Author: Nico Weber
Date: 2022-11-21T19:45:54-05:00
New Revision: 6bb781fa9ad34ac60501297f9031a2960d93c97c

URL: https://github.com/llvm/llvm-project/commit/6bb781fa9ad34ac60501297f9031a2960d93c97c
DIFF: https://github.com/llvm/llvm-project/commit/6bb781fa9ad34ac60501297f9031a2960d93c97c.diff

LOG: [gn build] Add build files for //bolt

Adds build files for libraries, tools, and tests -- everything except
the runtime.

Doesn't hook up bolt in the main BUILD.gn file yet -- I want to verify
that it builds on Linux, macOS, Windows before doing that. (I've only
checked on macOS so far.)

`ninja check-bolt` passes on macOS with this.
(I locally bumped the deployment target to macOS 10.12 for that. bolt/ uses
std::mutex quite a bit, which requires 10.12.)

Differential Revision: https://reviews.llvm.org/D138355

Added: 
    llvm/utils/gn/secondary/bolt/include/bolt/RuntimeLibs/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/Core/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/Profile/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/Rewrite/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/RuntimeLibs/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/Target/AArch64/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/Target/X86/BUILD.gn
    llvm/utils/gn/secondary/bolt/lib/Utils/BUILD.gn
    llvm/utils/gn/secondary/bolt/test/BUILD.gn
    llvm/utils/gn/secondary/bolt/test/bolt_lit_site_cfg_files.gni
    llvm/utils/gn/secondary/bolt/tools/bat-dump/BUILD.gn
    llvm/utils/gn/secondary/bolt/tools/driver/BUILD.gn
    llvm/utils/gn/secondary/bolt/tools/heatmap/BUILD.gn
    llvm/utils/gn/secondary/bolt/tools/merge-fdata/BUILD.gn
    llvm/utils/gn/secondary/bolt/unittests/BUILD.gn
    llvm/utils/gn/secondary/bolt/unittests/Core/BUILD.gn
    llvm/utils/gn/secondary/bolt/unittests/Profile/BUILD.gn

Modified: 
    llvm/utils/gn/build/BUILD.gn
    llvm/utils/gn/build/sync_source_lists_from_cmake.py
    llvm/utils/gn/secondary/BUILD.gn
    llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn
index 827f382910e30..16af242979581 100644
--- a/llvm/utils/gn/build/BUILD.gn
+++ b/llvm/utils/gn/build/BUILD.gn
@@ -488,6 +488,13 @@ config("clang_code") {
   ]
 }
 
+config("bolt_code") {
+  include_dirs = [
+    "//bolt/include",
+    "$root_gen_dir/bolt/include",
+  ]
+}
+
 config("crt_code") {
   include_dirs = [ "//compiler-rt/lib" ]
   cflags = [

diff  --git a/llvm/utils/gn/build/sync_source_lists_from_cmake.py b/llvm/utils/gn/build/sync_source_lists_from_cmake.py
index a23a8af9d7f17..7ecff9ddd1398 100755
--- a/llvm/utils/gn/build/sync_source_lists_from_cmake.py
+++ b/llvm/utils/gn/build/sync_source_lists_from_cmake.py
@@ -133,7 +133,7 @@ def sync_unittests():
     # Matches e.g. |add_llvm_unittest_with_input_files|.
     unittest_re = re.compile(r'^add_\S+_unittest', re.MULTILINE)
 
-    checked = [ 'clang', 'clang-tools-extra', 'lld', 'llvm' ]
+    checked = [ 'bolt', 'clang', 'clang-tools-extra', 'lld', 'llvm' ]
     changed = False
     for c in checked:
         for root, _, _ in os.walk(os.path.join(c, 'unittests')):

diff  --git a/llvm/utils/gn/secondary/BUILD.gn b/llvm/utils/gn/secondary/BUILD.gn
index c7ead71d66962..396cec75c56f1 100644
--- a/llvm/utils/gn/secondary/BUILD.gn
+++ b/llvm/utils/gn/secondary/BUILD.gn
@@ -32,6 +32,11 @@ group("default") {
     deps += [ "//libunwind" ]
   }
 
+  # FIXME: Add this on linux/win after testing that it builds.
+  if (current_os == "mac") {
+    deps += [ "//bolt/test" ]
+  }
+
   testonly = true
 }
 
@@ -66,6 +71,11 @@ group("lld") {
 group("llvm-ar") {
   deps = [ "//llvm/tools/llvm-ar:symlinks" ]
 }
+if (current_os == "mac") {
+  group("llvm-bolt") {
+    deps = [ "//bolt/tools/driver:symlinks" ]
+  }
+}
 group("llvm-dwp") {
   deps = [ "//llvm/tools/llvm-dwp:symlinks" ]
 }

diff  --git a/llvm/utils/gn/secondary/bolt/include/bolt/RuntimeLibs/BUILD.gn b/llvm/utils/gn/secondary/bolt/include/bolt/RuntimeLibs/BUILD.gn
new file mode 100644
index 0000000000000..0265fa1e783af
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/include/bolt/RuntimeLibs/BUILD.gn
@@ -0,0 +1,7 @@
+import("//llvm/utils/gn/build/write_cmake_config.gni")
+
+write_cmake_config("RuntimeLibraryVariables") {
+  input = "//bolt/include/bolt/RuntimeLibs/RuntimeLibraryVariables.inc.in"
+  output = "$target_gen_dir/RuntimeLibraryVariables.inc"
+  values = [ "LLVM_LIBDIR_SUFFIX=" ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/Core/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/Core/BUILD.gn
new file mode 100644
index 0000000000000..5010cceaf6105
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/Core/BUILD.gn
@@ -0,0 +1,31 @@
+static_library("Core") {
+  output_name = "LLVMBOLTCore"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Utils",
+    "//llvm/lib/DebugInfo/DWARF",
+    "//llvm/lib/Demangle",
+    "//llvm/lib/MC",
+    "//llvm/lib/MC/MCDisassembler",
+    "//llvm/lib/Object",
+    "//llvm/lib/Support",
+    "//llvm/utils/gn/build/libs/pthread",
+  ]
+  sources = [
+    "BinaryBasicBlock.cpp",
+    "BinaryContext.cpp",
+    "BinaryData.cpp",
+    "BinaryEmitter.cpp",
+    "BinaryFunction.cpp",
+    "BinaryFunctionProfile.cpp",
+    "BinarySection.cpp",
+    "DebugData.cpp",
+    "DynoStats.cpp",
+    "Exceptions.cpp",
+    "FunctionLayout.cpp",
+    "JumpTable.cpp",
+    "MCPlusBuilder.cpp",
+    "ParallelUtilities.cpp",
+    "Relocation.cpp",
+  ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn
new file mode 100644
index 0000000000000..25b78fc19bb37
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/Passes/BUILD.gn
@@ -0,0 +1,62 @@
+static_library("Passes") {
+  output_name = "LLVMBOLTPasses"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Core",
+    "//bolt/lib/Utils",
+    "//llvm/lib/CodeGen/AsmPrinter",
+    "//llvm/lib/MC",
+    "//llvm/lib/Support",
+    "//llvm/lib/Transforms/Utils",
+    "//llvm/utils/gn/build/libs/pthread",
+  ]
+  sources = [
+    "ADRRelaxationPass.cpp",
+    "Aligner.cpp",
+    "AllocCombiner.cpp",
+    "AsmDump.cpp",
+    "BinaryFunctionCallGraph.cpp",
+    "BinaryPasses.cpp",
+    "CMOVConversion.cpp",
+    "CacheMetrics.cpp",
+    "CallGraph.cpp",
+    "CallGraphWalker.cpp",
+    "DataflowAnalysis.cpp",
+    "DataflowInfoManager.cpp",
+    "FrameAnalysis.cpp",
+    "FrameOptimizer.cpp",
+    "HFSort.cpp",
+    "HFSortPlus.cpp",
+    "Hugify.cpp",
+    "IdenticalCodeFolding.cpp",
+    "IndirectCallPromotion.cpp",
+    "Inliner.cpp",
+    "Instrumentation.cpp",
+    "JTFootprintReduction.cpp",
+    "LivenessAnalysis.cpp",
+    "LongJmp.cpp",
+    "LoopInversionPass.cpp",
+    "MCF.cpp",
+    "PLTCall.cpp",
+    "PatchEntries.cpp",
+    "PettisAndHansen.cpp",
+    "RegAnalysis.cpp",
+    "RegReAssign.cpp",
+    "ReorderAlgorithm.cpp",
+    "ReorderData.cpp",
+    "ReorderFunctions.cpp",
+    "RetpolineInsertion.cpp",
+    "ShrinkWrapping.cpp",
+    "SplitFunctions.cpp",
+    "StackAllocationAnalysis.cpp",
+    "StackAvailableExpressions.cpp",
+    "StackPointerTracking.cpp",
+    "StackReachingUses.cpp",
+    "StokeInfo.cpp",
+    "TailDuplication.cpp",
+    "ThreeWayBranch.cpp",
+    "ValidateInternalCalls.cpp",
+    "ValidateMemRefs.cpp",
+    "VeneerElimination.cpp",
+  ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/Profile/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/Profile/BUILD.gn
new file mode 100644
index 0000000000000..fc061af85d818
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/Profile/BUILD.gn
@@ -0,0 +1,19 @@
+static_library("Profile") {
+  output_name = "LLVMBOLTProfile"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Core",
+    "//bolt/lib/Passes",
+    "//bolt/lib/Utils",
+    "//llvm/lib/Support",
+  ]
+  sources = [
+    "BoltAddressTranslation.cpp",
+    "DataAggregator.cpp",
+    "DataReader.cpp",
+    "Heatmap.cpp",
+    "ProfileReaderBase.cpp",
+    "YAMLProfileReader.cpp",
+    "YAMLProfileWriter.cpp",
+  ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/Rewrite/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/Rewrite/BUILD.gn
new file mode 100644
index 0000000000000..fbc40a71fc514
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/Rewrite/BUILD.gn
@@ -0,0 +1,38 @@
+import("//llvm/lib/Target/targets.gni")
+
+static_library("Rewrite") {
+  output_name = "LLVMBOLTRewrite"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Core",
+    "//bolt/lib/Passes",
+    "//bolt/lib/Profile",
+    "//bolt/lib/RuntimeLibs",
+    "//bolt/lib/Utils",
+    "//llvm/lib/DWP",
+    "//llvm/lib/DebugInfo/DWARF",
+    "//llvm/lib/ExecutionEngine",
+    "//llvm/lib/MC",
+    "//llvm/lib/Object",
+    "//llvm/lib/Support",
+    "//llvm/utils/gn/build/libs/pthread",
+  ]
+  sources = [
+    "BinaryPassManager.cpp",
+    "BoltDiff.cpp",
+    "DWARFRewriter.cpp",
+    "ExecutableFileMemoryManager.cpp",
+    "MachORewriteInstance.cpp",
+    "RewriteInstance.cpp",
+  ]
+
+  defines = []
+  if (llvm_build_AArch64) {
+    defines += [ "AARCH64_AVAILABLE" ]
+    deps += [ "//bolt/lib/Target/AArch64" ]
+  }
+  if (llvm_build_X86) {
+    defines += [ "X86_AVAILABLE" ]
+    deps += [ "//bolt/lib/Target/X86" ]
+  }
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/RuntimeLibs/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/RuntimeLibs/BUILD.gn
new file mode 100644
index 0000000000000..a160355978894
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/RuntimeLibs/BUILD.gn
@@ -0,0 +1,21 @@
+static_library("RuntimeLibs") {
+  output_name = "LLVMBOLTRuntimeLibs"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/include/bolt/RuntimeLibs:RuntimeLibraryVariables",
+    "//bolt/lib/Core",
+    "//bolt/lib/Passes",
+    "//bolt/lib/Utils",
+    "//llvm/lib/BinaryFormat",
+    "//llvm/lib/ExecutionEngine/RuntimeDyld",
+    "//llvm/lib/MC",
+    "//llvm/lib/Object",
+    "//llvm/lib/Support",
+  ]
+  include_dirs = [ target_gen_dir ]
+  sources = [
+    "HugifyRuntimeLibrary.cpp",
+    "InstrumentationRuntimeLibrary.cpp",
+    "RuntimeLibrary.cpp",
+  ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/Target/AArch64/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/Target/AArch64/BUILD.gn
new file mode 100644
index 0000000000000..237caf6ab685f
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/Target/AArch64/BUILD.gn
@@ -0,0 +1,19 @@
+static_library("AArch64") {
+  output_name = "LLVMBOLTTargetAArch64"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Core",
+    "//llvm/lib/MC",
+    "//llvm/lib/Support",
+    "//llvm/lib/Target/AArch64/MCTargetDesc",
+  ]
+  sources = [ "AArch64MCPlusBuilder.cpp" ]
+
+  # This target reaches into the internal headers of LLVM's AArch64 library.
+  # That target doesn't expect that, so it doesn't use public_deps for
+  # tblgen-generated headers used only in internal headers (...which this
+  # target here questionably includes). So depend on the target that generates
+  # those headers here.
+  include_dirs = [ "//llvm/lib/Target/AArch64" ]
+  deps += [ "//llvm/lib/Target/AArch64/Utils" ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/Target/X86/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/Target/X86/BUILD.gn
new file mode 100644
index 0000000000000..189e0aab2ca19
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/Target/X86/BUILD.gn
@@ -0,0 +1,19 @@
+static_library("X86") {
+  output_name = "LLVMBOLTTargetX86"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Core",
+    "//bolt/lib/Utils",
+    "//llvm/lib/MC",
+    "//llvm/lib/MC/MCDisassembler",
+    "//llvm/lib/Support",
+    "//llvm/lib/Target/X86/MCTargetDesc",
+  ]
+  sources = [
+    "X86MCPlusBuilder.cpp",
+    "X86MCSymbolizer.cpp",
+  ]
+
+  # This target reaches into the internal headers of LLVM's X86 library.
+  include_dirs = [ "//llvm/lib/Target/X86" ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/lib/Utils/BUILD.gn b/llvm/utils/gn/secondary/bolt/lib/Utils/BUILD.gn
new file mode 100644
index 0000000000000..6a70a90815c8c
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/lib/Utils/BUILD.gn
@@ -0,0 +1,12 @@
+static_library("Utils") {
+  output_name = "LLVMBOLTUtils"
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//llvm/lib/Support",
+    "//llvm/utils/gn/build/libs/pthread",
+  ]
+  sources = [
+    "CommandLineOpts.cpp",
+    "Utils.cpp",
+  ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/test/BUILD.gn b/llvm/utils/gn/secondary/bolt/test/BUILD.gn
new file mode 100644
index 0000000000000..a917d569acd52
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/test/BUILD.gn
@@ -0,0 +1,125 @@
+import("//llvm/lib/Target/targets_string.gni")
+import("//llvm/triples.gni")
+import("//llvm/utils/gn/build/write_cmake_config.gni")
+import("bolt_lit_site_cfg_files.gni")
+
+template("write_lit_config") {
+  write_cmake_config(target_name) {
+    input = invoker.input
+    output = invoker.output
+    values = [
+      "BOLT_BINARY_DIR=" +
+          rebase_path(get_label_info("//bolt", "target_out_dir")),
+      "BOLT_SOURCE_DIR=" + rebase_path("//bolt"),
+      "LIT_SITE_CFG_IN_HEADER=## Autogenerated from $input, do not edit",
+      "LLVM_BINARY_DIR=" + get_label_info("//llvm", "target_out_dir"),
+      "LLVM_LIBS_DIR=",  # needed only for shared builds
+      "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
+      "LLVM_SOURCE_DIR=" + rebase_path("//llvm"),
+      "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
+      "LLVM_TARGET_TRIPLE=$llvm_target_triple",
+    ]
+    values += invoker.extra_values
+  }
+}
+
+write_lit_config("lit_site_cfg") {
+  # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
+  input = "//bolt/test/lit.site.cfg.py.in"
+  output = bolt_lit_site_cfg_file
+  dir = get_path_info(output, "dir")
+  extra_values = [
+    "BOLT_CLANG_EXE=" + rebase_path("$root_build_dir/bin/clang"),
+    "BOLT_LLD_EXE=" + rebase_path("$root_build_dir/bin/ld.lld"),
+    "BOLT_ENABLE_RUNTIME=0",  # FIXME: enable runtime
+    "GNU_LD_EXECUTABLE=",  # FIXME: set sometimes?
+    "LLVM_HOST_TRIPLE=$llvm_current_triple",
+    "LLVM_USE_SANITIZER=",
+    "Python3_EXECUTABLE=$python_path",
+    "TARGETS_TO_BUILD=$llvm_targets_to_build_string",
+  ]
+
+  if (host_os == "win") {
+    # See comment for Windows solink in llvm/utils/gn/build/toolchain/BUILD.gn
+    extra_values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/bin", dir) ]
+  } else {
+    extra_values += [ "SHLIBDIR=" + rebase_path("$root_out_dir/lib", dir) ]
+  }
+
+  if (host_cpu == "x64") {
+    extra_values += [ "HOST_ARCH=x86_64" ]
+  } else if (host_cpu == "arm64") {
+    extra_values += [ "HOST_ARCH=arm64" ]
+  } else if (host_cpu == "ppc64") {
+    extra_values += [ "HOST_ARCH=powerpc64le" ]
+  } else {
+    assert(false, "unimplemented host_cpu " + host_cpu)
+  }
+
+  if (host_os == "mac") {
+    extra_values += [ "LLVM_PLUGIN_EXT=.dylib" ]
+  } else if (host_os == "win") {
+    extra_values += [ "LLVM_PLUGIN_EXT=.dll" ]
+  } else {
+    extra_values += [ "LLVM_PLUGIN_EXT=.so" ]
+  }
+}
+
+write_lit_config("lit_unit_site_cfg") {
+  # Fully-qualified instead of relative for LIT_SITE_CFG_IN_HEADER.
+  input = "//bolt/test/Unit/lit.site.cfg.py.in"
+  output = bolt_lit_unit_site_cfg_file
+  extra_values = [ "LLVM_BUILD_MODE=." ]
+}
+
+# This target should contain all dependencies of check-bolt.
+# //:default depends on it, so that ninja's default target builds all
+# prerequisites for check-bolt but doesn't run check-bolt itself.
+group("test") {
+  deps = [
+    ":lit_site_cfg",
+    ":lit_unit_site_cfg",
+    "//bolt/tools/driver:symlinks",
+    "//bolt/tools/heatmap:llvm-bolt-heatmap",
+    "//bolt/tools/merge-fdata",
+    "//bolt/unittests",
+    "//clang/tools/driver:symlinks",
+    "//lld/tools/lld:symlinks",
+    "//llvm/tools/llc",
+    "//llvm/tools/llvm-config",
+    "//llvm/tools/llvm-dwarfdump",
+    "//llvm/tools/llvm-dwp",
+    "//llvm/tools/llvm-mc",
+    "//llvm/tools/llvm-nm:symlinks",
+    "//llvm/tools/llvm-objcopy:symlinks",
+    "//llvm/tools/llvm-objdump:symlinks",
+    "//llvm/tools/yaml2obj",
+    "//llvm/utils/FileCheck",
+    "//llvm/utils/count",
+    "//llvm/utils/not",
+  ]
+
+  testonly = true
+}
+
+action("check-bolt") {
+  script = "$root_out_dir/bin/llvm-lit"
+  if (host_os == "win") {
+    script += ".py"
+  }
+  args = [
+    "-sv",
+    rebase_path(".", root_out_dir),
+  ]
+  outputs = [ "$target_gen_dir/run-lit" ]  # Non-existing, so that ninja runs it
+                                           # each time.
+
+  # Since check-bolt is always dirty, //:default doesn't depend on it so that
+  # it's not part of the default ninja target.  Hence, check-bolt shouldn't
+  # have any deps except :test. so that the default target is sure to build
+  # all the deps.
+  deps = [ ":test" ]
+  testonly = true
+
+  pool = "//:console"
+}

diff  --git a/llvm/utils/gn/secondary/bolt/test/bolt_lit_site_cfg_files.gni b/llvm/utils/gn/secondary/bolt/test/bolt_lit_site_cfg_files.gni
new file mode 100644
index 0000000000000..0be1434c950eb
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/test/bolt_lit_site_cfg_files.gni
@@ -0,0 +1,2 @@
+bolt_lit_site_cfg_file = "$root_gen_dir/bolt/test/lit.site.cfg.py"
+bolt_lit_unit_site_cfg_file = "$root_gen_dir/bolt/test/Unit/lit.site.cfg.py"

diff  --git a/llvm/utils/gn/secondary/bolt/tools/bat-dump/BUILD.gn b/llvm/utils/gn/secondary/bolt/tools/bat-dump/BUILD.gn
new file mode 100644
index 0000000000000..80f291ae39671
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/tools/bat-dump/BUILD.gn
@@ -0,0 +1,9 @@
+executable("llvm-bat-dump") {
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Profile",
+    "//llvm/lib/Object",
+    "//llvm/lib/Support",
+  ]
+  sources = [ "bat-dump.cpp" ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/tools/driver/BUILD.gn b/llvm/utils/gn/secondary/bolt/tools/driver/BUILD.gn
new file mode 100644
index 0000000000000..004a7359698de
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/tools/driver/BUILD.gn
@@ -0,0 +1,38 @@
+import("//llvm/utils/gn/build/symlink_or_copy.gni")
+
+symlinks = [
+  "perf2bolt",
+  "llvm-bolt
diff ",
+]
+foreach(symlink, symlinks) {
+  symlink_or_copy(symlink) {
+    deps = [ ":llvm-bolt" ]
+    source = "llvm-bolt"
+    output = "$root_out_dir/bin/$symlink"
+  }
+}
+
+# //:llvm-bolt depends on this symlink target, see comment in //BUILD.gn.
+group("symlinks") {
+  deps = [ ":llvm-bolt" ]
+  foreach(symlink, symlinks) {
+    deps += [ ":$symlink" ]
+  }
+}
+
+executable("llvm-bolt") {
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Profile",
+    "//bolt/lib/Rewrite",
+    "//bolt/lib/Utils",
+    "//llvm/lib/MC",
+    "//llvm/lib/Object",
+    "//llvm/lib/Support",
+    "//llvm/lib/Target:TargetsToBuild",
+  ]
+
+  # FIXME: Add dependency on //bolt/runtime once that exists.
+
+  sources = [ "llvm-bolt.cpp" ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/tools/heatmap/BUILD.gn b/llvm/utils/gn/secondary/bolt/tools/heatmap/BUILD.gn
new file mode 100644
index 0000000000000..b6270106dbaf8
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/tools/heatmap/BUILD.gn
@@ -0,0 +1,13 @@
+executable("llvm-bolt-heatmap") {
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Profile",
+    "//bolt/lib/Rewrite",
+    "//bolt/lib/Utils",
+    "//llvm/lib/MC",
+    "//llvm/lib/Object",
+    "//llvm/lib/Support",
+    "//llvm/lib/Target:TargetsToBuild",
+  ]
+  sources = [ "heatmap.cpp" ]
+}

diff  --git a/llvm/utils/gn/secondary/bolt/tools/merge-fdata/BUILD.gn b/llvm/utils/gn/secondary/bolt/tools/merge-fdata/BUILD.gn
new file mode 100644
index 0000000000000..3e6aed77fba07
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/tools/merge-fdata/BUILD.gn
@@ -0,0 +1,11 @@
+executable("merge-fdata") {
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [ "//llvm/lib/Support" ]
+  sources = [ "merge-fdata.cpp" ]
+
+  # Emit relocations for BOLT meta test
+  # (bolt/test/runtime/meta-merge-fdata.test)
+  if (current_os == "linux") {
+    ldflags = [ "-Wl,--emit-relocs" ]
+  }
+}

diff  --git a/llvm/utils/gn/secondary/bolt/unittests/BUILD.gn b/llvm/utils/gn/secondary/bolt/unittests/BUILD.gn
new file mode 100644
index 0000000000000..9c5be5966b3fc
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/unittests/BUILD.gn
@@ -0,0 +1,7 @@
+group("unittests") {
+  deps = [
+    "Core:CoreTests",
+    "Profile:ProfileTests",
+  ]
+  testonly = true
+}

diff  --git a/llvm/utils/gn/secondary/bolt/unittests/Core/BUILD.gn b/llvm/utils/gn/secondary/bolt/unittests/Core/BUILD.gn
new file mode 100644
index 0000000000000..51dc24481a513
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/unittests/Core/BUILD.gn
@@ -0,0 +1,47 @@
+import("//llvm/lib/Target/targets.gni")
+import("//third-party/unittest/unittest.gni")
+
+unittest("CoreTests") {
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [
+    "//bolt/lib/Core",
+    "//bolt/lib/Rewrite",
+    "//llvm/lib/DebugInfo/DWARF",
+    "//llvm/lib/MC",
+    "//llvm/lib/Object",
+    "//llvm/lib/Target:TargetsToBuild",
+  ]
+  sources = [
+    "BinaryContext.cpp",
+    "DynoStats.cpp",
+    "MCPlusBuilder.cpp",
+  ]
+
+  defines = []
+  include_dirs = []
+  if (llvm_build_AArch64) {
+    defines += [ "AARCH64_AVAILABLE" ]
+
+    # This target reaches into the internal headers of LLVM's AArch64 library.
+    # That target doesn't expect that, so it doesn't use public_deps for
+    # tblgen-generated headers used only in internal headers (...which this
+    # target here questionably includes). So depend on the target that generates
+    # those headers here.
+    include_dirs += [ "//llvm/lib/Target/AArch64" ]
+    deps += [
+      "//llvm/lib/Target/AArch64/MCTargetDesc",
+      "//llvm/lib/Target/AArch64/Utils",
+    ]
+  }
+  if (llvm_build_X86) {
+    defines += [ "X86_AVAILABLE" ]
+
+    # This target reaches into the internal headers of LLVM's X86 library.
+    # That target doesn't expect that, so it doesn't use public_deps for
+    # tblgen-generated headers used only in internal headers (...which this
+    # target here questionably includes). So depend on the target that generates
+    # those headers here.
+    include_dirs += [ "//llvm/lib/Target/X86" ]
+    deps += [ "//llvm/lib/Target/X86/MCTargetDesc" ]
+  }
+}

diff  --git a/llvm/utils/gn/secondary/bolt/unittests/Profile/BUILD.gn b/llvm/utils/gn/secondary/bolt/unittests/Profile/BUILD.gn
new file mode 100644
index 0000000000000..b3f7216af0596
--- /dev/null
+++ b/llvm/utils/gn/secondary/bolt/unittests/Profile/BUILD.gn
@@ -0,0 +1,7 @@
+import("//third-party/unittest/unittest.gni")
+
+unittest("ProfileTests") {
+  configs += [ "//llvm/utils/gn/build:bolt_code" ]
+  deps = [ "//bolt/lib/Profile" ]
+  sources = [ "DataAggregator.cpp" ]
+}

diff  --git a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
index 819f6c91d0270..f9b71bf33cd04 100644
--- a/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/utils/llvm-lit/BUILD.gn
@@ -1,3 +1,4 @@
+import("//bolt/test/bolt_lit_site_cfg_files.gni")
 import("//clang-tools-extra/clangd/test/clangd_lit_site_cfg_files.gni")
 import("//clang-tools-extra/pseudo/test/clang_pseudo_lit_site_cfg_files.gni")
 import("//clang-tools-extra/test/clang_tools_extra_lit_site_cfg_files.gni")
@@ -39,6 +40,14 @@ write_cmake_config("llvm-lit") {
   ]
 
   entries = [
+    [
+      "//bolt/test/lit.cfg.py",
+      bolt_lit_site_cfg_file,
+    ],
+    [
+      "//bolt/test/Unit/lit.cfg.py",
+      bolt_lit_unit_site_cfg_file,
+    ],
     [
       "//clang-tools-extra/test/lit.cfg.py",
       clang_tools_extra_lit_site_cfg_file,


        


More information about the llvm-commits mailing list