mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:50:14 +01:00
As part of this, move functions that seem reasonable to make out-of-line to a separate `_impl.h` header file that is only included where the explicit instantiation _definition_ is provided. By using explicit instantiation we can make these templates behave more like non-template classes in terms of supporting out-of-line definitions that don't need to be compiled by every translation unit. The set of eventual instantiations here is fundamentally known, and there tend to be headers that define a canonical "leaf" type where it makes sense to trigger the explicit instantiation. Where we already had a `.cpp` file to put the explicit instantiation definition, use it. But in some places we didn't have such a `.cpp` file so this PR adds those. This also requires that we have precise constraints on APIs that _can't_ be instantiated for specific argument types, as now we don't do this lazily. Combined, this appears to reduce the sum of object file sizes in the `check` directory by almost 40% (122mb -> 74mb) in my measurement. My actual goal was to improve compile times, but so far I don't have a great methodology for measuring these... But the object file size reduction seems to confirm this is a net win and likely represents a non-trivial improvement in compile time. Assisted-by: Antigravity with Gemini
384 lines
8.4 KiB
Python
384 lines
8.4 KiB
Python
# 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
|
|
|
|
load("//bazel/cc_rules:defs.bzl", "cc_binary", "cc_library", "cc_test")
|
|
load("llvm_tools.bzl", "LLVM_MAIN_TOOLS", "generate_llvm_tools_def")
|
|
load("runtimes_build_info.bzl", "generate_runtimes_build_info_cc_library")
|
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
exports_files([
|
|
"runtimes_build_vars.tpl.bzl",
|
|
])
|
|
|
|
cc_library(
|
|
name = "block_value_store",
|
|
hdrs = [
|
|
"block_value_store.h",
|
|
"block_value_store_impl.h",
|
|
],
|
|
deps = [
|
|
":id_tag",
|
|
":mem_usage",
|
|
":value_store",
|
|
":yaml",
|
|
"//common:check",
|
|
"//common:hashing",
|
|
"//common:set",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "canonical_value_store",
|
|
hdrs = [
|
|
"canonical_value_store.h",
|
|
"canonical_value_store_impl.h",
|
|
],
|
|
deps = [
|
|
":mem_usage",
|
|
":value_store",
|
|
":value_store_types",
|
|
":yaml",
|
|
"//common:hashtable_key_context",
|
|
"//common:set",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "canonical_value_store_test",
|
|
size = "small",
|
|
srcs = ["canonical_value_store_test.cpp"],
|
|
deps = [
|
|
":canonical_value_store",
|
|
":shared_value_stores",
|
|
":value_ids",
|
|
":value_store",
|
|
"//testing/base:gtest_main",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "clang_invocation",
|
|
srcs = ["clang_invocation.cpp"],
|
|
hdrs = ["clang_invocation.h"],
|
|
deps = [
|
|
":install_paths",
|
|
"//common:check",
|
|
"//common:string_helpers",
|
|
"//toolchain/diagnostics:emitter",
|
|
"@llvm-project//clang:basic",
|
|
"@llvm-project//clang:driver",
|
|
"@llvm-project//clang:frontend",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "fixed_size_value_store",
|
|
hdrs = ["fixed_size_value_store.h"],
|
|
deps = [
|
|
":mem_usage",
|
|
":value_store",
|
|
":value_store_types",
|
|
"//common:check",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "for_each_macro",
|
|
hdrs = ["for_each_macro.h"],
|
|
deps = [
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "id_tag",
|
|
hdrs = ["id_tag.h"],
|
|
deps = [
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "index_base",
|
|
hdrs = ["index_base.h"],
|
|
deps = [
|
|
"//common:ostream",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
# A library for computing install paths for the toolchain. Note that this
|
|
# library does *not* include the data itself, as that would form a dependency
|
|
# cycle. Each part of the toolchain should add the narrow data file groups to
|
|
# their data dependencies, and then use this library to locate them.
|
|
cc_library(
|
|
name = "install_paths",
|
|
srcs = ["install_paths.cpp"],
|
|
hdrs = ["install_paths.h"],
|
|
deps = [
|
|
":llvm_tools",
|
|
"//common:check",
|
|
"//common:error",
|
|
"//common:filesystem",
|
|
"@bazel_tools//tools/cpp/runfiles",
|
|
"@llvm-project//clang:basic",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_binary(
|
|
name = "test_binary",
|
|
testonly = 1,
|
|
srcs = ["test_binary.cpp"],
|
|
data = ["//toolchain/install:install_data"],
|
|
)
|
|
|
|
cc_test(
|
|
name = "install_paths_test",
|
|
size = "small",
|
|
srcs = ["install_paths_test.cpp"],
|
|
data = [
|
|
":test_binary",
|
|
"//toolchain/install:install_data",
|
|
],
|
|
deps = [
|
|
":install_paths",
|
|
"//common:check",
|
|
"//common:error_test_helpers",
|
|
"//common:filesystem",
|
|
"//common:ostream",
|
|
"//testing/base:global_exe_path",
|
|
"//testing/base:gtest_main",
|
|
"@bazel_tools//tools/cpp/runfiles",
|
|
"@googletest//:gtest",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "install_paths_test_helpers",
|
|
testonly = 1,
|
|
srcs = ["install_paths_test_helpers.cpp"],
|
|
hdrs = ["install_paths_test_helpers.h"],
|
|
deps = [
|
|
":install_paths",
|
|
"//testing/base:global_exe_path",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "kind_switch",
|
|
hdrs = ["kind_switch.h"],
|
|
deps = [
|
|
":for_each_macro",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "kind_switch_test",
|
|
size = "small",
|
|
srcs = ["kind_switch_test.cpp"],
|
|
deps = [
|
|
":kind_switch",
|
|
"//common:raw_string_ostream",
|
|
"//testing/base:gtest_main",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "mem_usage",
|
|
hdrs = ["mem_usage.h"],
|
|
deps = [
|
|
":yaml",
|
|
"//common:map",
|
|
"//common:set",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "relational_value_store",
|
|
hdrs = ["relational_value_store.h"],
|
|
deps = [
|
|
":value_store",
|
|
":value_store_types",
|
|
"//common:check",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "timings",
|
|
hdrs = ["timings.h"],
|
|
deps = [
|
|
":yaml",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "value_ids",
|
|
hdrs = ["value_ids.h"],
|
|
deps = [
|
|
":index_base",
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "value_store",
|
|
hdrs = [
|
|
"value_store.h",
|
|
"value_store_impl.h",
|
|
],
|
|
deps = [
|
|
":id_tag",
|
|
":mem_usage",
|
|
":value_store_types",
|
|
":yaml",
|
|
"//common:check",
|
|
"//common:hashtable_key_context",
|
|
"//common:ostream",
|
|
"//common:set",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "value_store_test",
|
|
size = "small",
|
|
srcs = ["value_store_test.cpp"],
|
|
deps = [
|
|
":shared_value_stores",
|
|
":value_ids",
|
|
":value_store",
|
|
"//common:raw_string_ostream",
|
|
"//testing/base:gtest_main",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "value_store_types",
|
|
hdrs = ["value_store_types.h"],
|
|
deps = [
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "int",
|
|
srcs = ["int.cpp"],
|
|
hdrs = ["int.h"],
|
|
deps = [
|
|
":canonical_value_store",
|
|
":index_base",
|
|
":mem_usage",
|
|
":value_store",
|
|
":yaml",
|
|
"//common:check",
|
|
"//common:hashtable_key_context",
|
|
"//common:ostream",
|
|
"//common:set",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "int_test",
|
|
size = "small",
|
|
srcs = ["int_test.cpp"],
|
|
deps = [
|
|
":int",
|
|
"//common:raw_string_ostream",
|
|
"//testing/base:gtest_main",
|
|
"//toolchain/testing:yaml_test_helpers",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
generate_llvm_tools_def(
|
|
name = "llvm_tools_def",
|
|
out = "llvm_tools.def",
|
|
)
|
|
|
|
config_setting(
|
|
name = "is_macos",
|
|
constraint_values = ["@platforms//os:macos"],
|
|
)
|
|
|
|
cc_library(
|
|
name = "llvm_tools",
|
|
srcs = ["llvm_tools.cpp"],
|
|
hdrs = ["llvm_tools.h"],
|
|
linkopts = select({
|
|
# TODO: This should be moved upstream to LLVM's tool libraries that
|
|
# require it.
|
|
":is_macos": [
|
|
"-framework",
|
|
"CoreFoundation",
|
|
],
|
|
"//conditions:default": [],
|
|
}),
|
|
deps = [
|
|
":llvm_tools_def",
|
|
"//common:command_line",
|
|
"//common:enum_base",
|
|
"@llvm-project//llvm:Support",
|
|
] + [info.lib for info in LLVM_MAIN_TOOLS.values()],
|
|
)
|
|
|
|
generate_runtimes_build_info_cc_library(name = "runtimes_build_info")
|
|
|
|
cc_library(
|
|
name = "shared_value_stores",
|
|
srcs = ["shared_value_stores.cpp"],
|
|
hdrs = ["shared_value_stores.h"],
|
|
deps = [
|
|
":canonical_value_store",
|
|
":int",
|
|
":mem_usage",
|
|
":value_ids",
|
|
":value_store",
|
|
":yaml",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|
|
|
|
cc_test(
|
|
name = "shared_value_stores_test",
|
|
size = "small",
|
|
srcs = ["shared_value_stores_test.cpp"],
|
|
deps = [
|
|
":shared_value_stores",
|
|
"//common:raw_string_ostream",
|
|
"//testing/base:gtest_main",
|
|
"//toolchain/testing:yaml_test_helpers",
|
|
"@googletest//:gtest",
|
|
],
|
|
)
|
|
|
|
cc_library(
|
|
name = "yaml",
|
|
hdrs = ["yaml.h"],
|
|
deps = [
|
|
"//common:check",
|
|
"//common:ostream",
|
|
"@llvm-project//llvm:Support",
|
|
],
|
|
)
|