]
}
+config("bolt_code") {
+ include_dirs = [
+ "//bolt/include",
+ "$root_gen_dir/bolt/include",
+ ]
+}
+
config("crt_code") {
include_dirs = [ "//compiler-rt/lib" ]
cflags = [
# 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')):
deps += [ "//libunwind" ]
}
+ # FIXME: Add this on linux/win after testing that it builds.
+ if (current_os == "mac") {
+ deps += [ "//bolt/test" ]
+ }
+
testonly = true
}
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" ]
}
--- /dev/null
+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=" ]
+}
--- /dev/null
+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",
+ ]
+}
--- /dev/null
+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",
+ ]
+}
--- /dev/null
+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",
+ ]
+}
--- /dev/null
+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" ]
+ }
+}
--- /dev/null
+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",
+ ]
+}
--- /dev/null
+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" ]
+}
--- /dev/null
+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" ]
+}
--- /dev/null
+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",
+ ]
+}
--- /dev/null
+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"
+}
--- /dev/null
+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"
--- /dev/null
+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" ]
+}
--- /dev/null
+import("//llvm/utils/gn/build/symlink_or_copy.gni")
+
+symlinks = [
+ "perf2bolt",
+ "llvm-boltdiff",
+]
+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" ]
+}
--- /dev/null
+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" ]
+}
--- /dev/null
+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" ]
+ }
+}
--- /dev/null
+group("unittests") {
+ deps = [
+ "Core:CoreTests",
+ "Profile:ProfileTests",
+ ]
+ testonly = true
+}
--- /dev/null
+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" ]
+ }
+}
--- /dev/null
+import("//third-party/unittest/unittest.gni")
+
+unittest("ProfileTests") {
+ configs += [ "//llvm/utils/gn/build:bolt_code" ]
+ deps = [ "//bolt/lib/Profile" ]
+ sources = [ "DataAggregator.cpp" ]
+}
+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")
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,
],