From ef218317d7e30eb32a8e4e1a68d3fe95ca3b8402 Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Tue, 18 Feb 2025 11:24:15 +0100 Subject: [PATCH] [bolt][bazel] Port https://github.com/llvm/llvm-project/commit/e235fcb582eec5f58c905b66f96d0732d17b875e. --- utils/bazel/configure.bzl | 13 +++++++++++-- .../bazel/llvm-project-overlay/bolt/BUILD.bazel | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/utils/bazel/configure.bzl b/utils/bazel/configure.bzl index c5da28845ecc..fcc9fc7ecc48 100644 --- a/utils/bazel/configure.bzl +++ b/utils/bazel/configure.bzl @@ -172,10 +172,19 @@ def _llvm_configure_impl(repository_ctx): ) # Create a starlark file with the requested LLVM targets. - targets = repository_ctx.attr.targets + llvm_targets = repository_ctx.attr.targets repository_ctx.file( "llvm/targets.bzl", - content = "llvm_targets = " + str(targets), + content = "llvm_targets = " + str(llvm_targets), + executable = False, + ) + + # Create a starlark file with the requested BOLT targets. + bolt_targets = ["AArch64","X86","RISCV"] # Supported targets. + bolt_targets = [t for t in llvm_targets if t in bolt_targets] + repository_ctx.file( + "bolt/targets.bzl", + content = "bolt_targets = " + str(bolt_targets), executable = False, ) diff --git a/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel b/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel index 187938783a55..a9a7cc59575a 100644 --- a/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception load("@bazel_skylib//rules:expand_template.bzl", "expand_template") +load(":targets.bzl", "bolt_targets") package( default_visibility = ["//visibility:public"], @@ -16,6 +17,20 @@ genrule( cmd = "echo '#undef BOLT_REVISION' >> $@\n", ) +expand_template( + name = "target_config_def_gen", + out = "include/bolt/Core/TargetConfig.def", + substitutions = {"@BOLT_ENUM_TARGETS@": "\n".join( + ["BOLT_TARGET({})".format(target) for target in bolt_targets], + )}, + template = "include/bolt/Core/TargetConfig.def.in", +) + +cc_library( + name = "TargetConfig", + textual_hdrs = [":target_config_def_gen"], +) + cc_binary( name = "llvm-bolt-heatmap", srcs = glob([ @@ -24,6 +39,7 @@ cc_binary( deps = [ ":Profile", ":Rewrite", + ":TargetConfig", ":Utils", "//llvm:AllTargetsAsmParsers", "//llvm:AllTargetsDisassemblers", @@ -54,6 +70,7 @@ cc_binary( ":Profile", ":Rewrite", ":RuntimeLibs", + ":TargetConfig", ":TargetAArch64", ":TargetX86", ":Utils",