Centralize benchmarking infrastructure and the toolchain-wide benchmarks (#7212)

The benchmarks themselves aren't really specific to `driver`.

Keeping the source generation near to the primary use case of
benchmarking also seems like a more discoverable location.

I feel a little bad doing this reorganization right after I gave a talk
with links to a bunch of this code, but seems good to reorganize a bit
before doing some work to extend things now that we have full standard
library support for C++ benchmarking and other improvements.

Assisted-by: Antigravity with Gemini
This commit is contained in:
Chandler Carruth
2026-05-15 20:17:23 +00:00
committed by GitHub
parent 42a4dba9fd
commit e041afd98d
10 changed files with 100 additions and 89 deletions
+1 -48
View File
@@ -5,7 +5,7 @@
# Trivial, single-file testing libraries. More complex libraries should get
# their own directory.
load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//bazel/cc_rules:defs.bzl", "cc_library", "cc_test")
package(default_visibility = ["//visibility:public"])
@@ -56,53 +56,6 @@ cc_library(
],
)
cc_library(
name = "source_gen_lib",
testonly = 1,
srcs = ["source_gen.cpp"],
hdrs = ["source_gen.h"],
deps = [
"//common:check",
"//common:map",
"//common:raw_string_ostream",
"//common:set",
"//toolchain/lex:token_kind",
"@abseil-cpp//absl/random",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "source_gen_test",
size = "small",
srcs = ["source_gen_test.cpp"],
deps = [
":global_exe_path",
":gtest_main",
":source_gen_lib",
"//common:all_llvm_targets",
"//common:set",
"//toolchain/base:install_paths_test_helpers",
"//toolchain/driver",
"@googletest//:gtest",
"@llvm-project//llvm:Support",
],
)
cc_binary(
name = "source_gen",
testonly = 1,
srcs = ["source_gen_main.cpp"],
deps = [
":source_gen_lib",
"//common:bazel_working_dir",
"//common:command_line",
"//common:init_llvm",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "file_helpers",
testonly = 1,
+89
View File
@@ -0,0 +1,89 @@
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Benchmarking infrastructure as well as comprehensive benchmarks across the
# tolochain. Infrastructure libraries may be depended on by focused benchmarks
# in various other parts of the toolchain.
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//bazel/cc_toolchains:defs.bzl", "cc_env")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "source_gen_lib",
testonly = 1,
srcs = ["source_gen.cpp"],
hdrs = ["source_gen.h"],
deps = [
"//common:check",
"//common:map",
"//common:raw_string_ostream",
"//common:set",
"//toolchain/lex:token_kind",
"@abseil-cpp//absl/random",
"@llvm-project//llvm:Support",
],
)
cc_test(
name = "source_gen_test",
size = "small",
srcs = ["source_gen_test.cpp"],
deps = [
":source_gen_lib",
"//common:all_llvm_targets",
"//common:set",
"//testing/base:global_exe_path",
"//testing/base:gtest_main",
"//toolchain/base:install_paths_test_helpers",
"//toolchain/driver",
"@googletest//:gtest",
"@llvm-project//llvm:Support",
],
)
cc_binary(
name = "source_gen",
testonly = 1,
srcs = ["source_gen_main.cpp"],
deps = [
":source_gen_lib",
"//common:bazel_working_dir",
"//common:command_line",
"//common:init_llvm",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
cc_binary(
name = "compile_benchmark",
testonly = 1,
srcs = ["compile_benchmark.cpp"],
deps = [
":source_gen_lib",
"//common:all_llvm_targets",
"//testing/base:benchmark_main",
"//testing/base:global_exe_path",
"//toolchain/base:install_paths_test_helpers",
"//toolchain/driver",
"//toolchain/testing:compile_helper",
"@google_benchmark//:benchmark",
"@llvm-project//llvm:Support",
],
)
sh_test(
name = "compile_benchmark_test",
size = "small",
srcs = [":compile_benchmark"],
args = [
"--benchmark_dry_run",
# The `$$` is repeated for Bazel escaping of `$`.
"--benchmark_filter=/256$$",
],
env = cc_env(),
)
@@ -8,8 +8,8 @@
#include <string>
#include "testing/base/global_exe_path.h"
#include "testing/base/source_gen.h"
#include "toolchain/base/install_paths_test_helpers.h"
#include "toolchain/benchmarking/source_gen.h"
#include "toolchain/driver/driver.h"
#include "toolchain/testing/compile_helper.h"
@@ -2,7 +2,7 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "testing/base/source_gen.h"
#include "toolchain/benchmarking/source_gen.h"
#include <algorithm>
#include <array>
@@ -2,8 +2,8 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#ifndef CARBON_TESTING_BASE_SOURCE_GEN_H_
#define CARBON_TESTING_BASE_SOURCE_GEN_H_
#ifndef CARBON_TOOLCHAIN_BENCHMARKING_SOURCE_GEN_H_
#define CARBON_TOOLCHAIN_BENCHMARKING_SOURCE_GEN_H_
#include <string>
@@ -296,4 +296,4 @@ class SourceGen {
} // namespace Carbon::Testing
#endif // CARBON_TESTING_BASE_SOURCE_GEN_H_
#endif // CARBON_TOOLCHAIN_BENCHMARKING_SOURCE_GEN_H_
@@ -13,7 +13,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "testing/base/source_gen.h"
#include "toolchain/benchmarking/source_gen.h"
namespace Carbon::Testing {
namespace {
@@ -2,7 +2,7 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "testing/base/source_gen.h"
#include "toolchain/benchmarking/source_gen.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+1 -32
View File
@@ -2,9 +2,7 @@
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//bazel/cc_toolchains:defs.bzl", "cc_env")
load("//bazel/cc_rules:defs.bzl", "cc_library", "cc_test")
load("//testing/fuzzing:rules.bzl", "cc_fuzz_test")
package(default_visibility = ["//visibility:public"])
@@ -113,35 +111,6 @@ cc_test(
],
)
cc_binary(
name = "compile_benchmark",
testonly = 1,
srcs = ["compile_benchmark.cpp"],
deps = [
":driver",
"//common:all_llvm_targets",
"//testing/base:benchmark_main",
"//testing/base:global_exe_path",
"//testing/base:source_gen_lib",
"//toolchain/base:install_paths_test_helpers",
"//toolchain/testing:compile_helper",
"@google_benchmark//:benchmark",
"@llvm-project//llvm:Support",
],
)
sh_test(
name = "compile_benchmark_test",
size = "small",
srcs = [":compile_benchmark"],
args = [
"--benchmark_dry_run",
# The `$$` is repeated for Bazel escaping of `$`.
"--benchmark_filter=/256$$",
],
env = cc_env(),
)
cc_library(
name = "codegen_options",
srcs = [
+1 -1
View File
@@ -326,8 +326,8 @@ cc_binary(
"//common:check",
"//common:raw_string_ostream",
"//testing/base:benchmark_main",
"//testing/base:source_gen_lib",
"//toolchain/base:shared_value_stores",
"//toolchain/benchmarking:source_gen_lib",
"//toolchain/diagnostics:emitter",
"//toolchain/diagnostics:null_diagnostics",
"@abseil-cpp//absl/random",
+1 -1
View File
@@ -14,8 +14,8 @@
#include "common/raw_string_ostream.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/StringExtras.h"
#include "testing/base/source_gen.h"
#include "toolchain/base/shared_value_stores.h"
#include "toolchain/benchmarking/source_gen.h"
#include "toolchain/diagnostics/emitter.h"
#include "toolchain/diagnostics/null_diagnostics.h"
#include "toolchain/lex/lex.h"