mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Enable FastTable for non-opt builds.
PiperOrigin-RevId: 966151323
This commit is contained in:
parent
b41fd533ea
commit
d46a6ff074
8 changed files with 124 additions and 31 deletions
|
|
@ -244,6 +244,9 @@ upb/wire/byte_size.h
|
|||
upb/wire/decode.h
|
||||
upb/wire/decode_fast/combinations.h
|
||||
upb/wire/decode_fast/data.h
|
||||
upb/wire/decode_fast/dispatch.h
|
||||
upb/wire/decode_fast/field_parsers.h
|
||||
upb/wire/decode_fast/function_array.h
|
||||
upb/wire/decode_fast/select.h
|
||||
upb/wire/encode.h
|
||||
upb/wire/encode_extension.h
|
||||
|
|
|
|||
94
upb/BUILD
94
upb/BUILD
|
|
@ -6,7 +6,7 @@
|
|||
# https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
|
||||
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
load("@rules_python//python:defs.bzl", "py_binary")
|
||||
load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES")
|
||||
|
|
@ -44,28 +44,95 @@ config_setting(
|
|||
visibility = UPB_CONFIG_VISIBILITY,
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
# FastTable flag definition + enablement rules.
|
||||
# FastTable will only enable for builds targeting 64bit.
|
||||
# If not explicitly specified, FastTable will enable by default for non-opt builds.
|
||||
string_flag(
|
||||
name = "fasttable_enabled",
|
||||
build_setting_default = False,
|
||||
build_setting_default = "auto",
|
||||
scope = "universal",
|
||||
values = [
|
||||
"true",
|
||||
"false",
|
||||
"auto",
|
||||
"True",
|
||||
"False",
|
||||
"Auto",
|
||||
],
|
||||
visibility = UPB_CONFIG_VISIBILITY,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "fasttable_enabled_setting_flag",
|
||||
name = "fasttable_enabled_true",
|
||||
flag_values = {"//upb:fasttable_enabled": "true"},
|
||||
visibility = UPB_CONFIG_VISIBILITY,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "fasttable_enabled_True_cap",
|
||||
flag_values = {"//upb:fasttable_enabled": "True"},
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "fasttable_enabled_setting",
|
||||
match_all = [
|
||||
":fasttable_enabled_setting_flag",
|
||||
":any_64bit",
|
||||
name = "fasttable_enabled_explicit_true",
|
||||
match_any = [
|
||||
":fasttable_enabled_true",
|
||||
":fasttable_enabled_True_cap",
|
||||
],
|
||||
visibility = UPB_CONFIG_VISIBILITY,
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "fasttable_enabled_auto",
|
||||
flag_values = {"//upb:fasttable_enabled": "auto"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "fasttable_enabled_Auto_cap",
|
||||
flag_values = {"//upb:fasttable_enabled": "Auto"},
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "fasttable_enabled_is_auto",
|
||||
match_any = [
|
||||
":fasttable_enabled_auto",
|
||||
":fasttable_enabled_Auto_cap",
|
||||
],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "dbg_mode",
|
||||
values = {"compilation_mode": "dbg"},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "fastbuild_mode",
|
||||
values = {"compilation_mode": "fastbuild"},
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "non_opt_build",
|
||||
match_any = [
|
||||
":dbg_mode",
|
||||
":fastbuild_mode",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "fasttable_enabled_default_active",
|
||||
match_all = [
|
||||
":fasttable_enabled_is_auto",
|
||||
":non_opt_build",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "fasttable_enabled_active",
|
||||
match_any = [
|
||||
":fasttable_enabled_explicit_true",
|
||||
":fasttable_enabled_default_active",
|
||||
],
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "any_64bit",
|
||||
match_any = [
|
||||
|
|
@ -82,6 +149,15 @@ selects.config_setting_group(
|
|||
visibility = UPB_CONFIG_VISIBILITY,
|
||||
)
|
||||
|
||||
selects.config_setting_group(
|
||||
name = "fasttable_enabled_setting",
|
||||
match_all = [
|
||||
":fasttable_enabled_active",
|
||||
":any_64bit",
|
||||
],
|
||||
visibility = UPB_CONFIG_VISIBILITY,
|
||||
)
|
||||
|
||||
upb_proto_library_copts(
|
||||
name = "upb_proto_library_copts",
|
||||
copts = UPB_DEFAULT_COPTS,
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ UPB_DEFAULT_CPPOPTS = select({
|
|||
"//upb:windows": [],
|
||||
"//conditions:default": _DEFAULT_CPPOPTS,
|
||||
}) + select({
|
||||
"//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
|
||||
"//upb:fasttable_enabled_explicit_true": ["-DUPB_ENABLE_FASTTABLE"],
|
||||
"//upb:fasttable_enabled_setting": ["-DUPB_TRY_ENABLE_FASTTABLE"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
|
|
@ -52,7 +53,8 @@ UPB_DEFAULT_COPTS = select({
|
|||
"//upb:windows": [],
|
||||
"//conditions:default": _DEFAULT_COPTS,
|
||||
}) + select({
|
||||
"//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"],
|
||||
"//upb:fasttable_enabled_explicit_true": ["-DUPB_ENABLE_FASTTABLE"],
|
||||
"//upb:fasttable_enabled_setting": ["-DUPB_TRY_ENABLE_FASTTABLE"],
|
||||
"//conditions:default": [],
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -230,18 +230,17 @@ cc_binary(
|
|||
# separate tests and use configuration-aware genrules to ensure each test
|
||||
# only performs real validation when its configuration is active.
|
||||
#
|
||||
# We move the generator binary to "srcs" so that it is built in the target
|
||||
# configuration (not the exec configuration), ensuring it correctly receives
|
||||
# the fasttable enablement flag.
|
||||
# Generator binary is in tools so it is built for the host (exec configuration)
|
||||
# to support cross-compilation (e.g. darwin_x86_64).
|
||||
genrule(
|
||||
name = "debug_string_test_txt_gen",
|
||||
srcs = select({
|
||||
"//upb:fasttable_enabled_setting": ["debug_string_test.txt"],
|
||||
"//upb:fasttable_enabled_explicit_true": ["debug_string_test.txt"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
outs = ["generated/debug_string_test.txt"],
|
||||
cmd = select({
|
||||
"//upb:fasttable_enabled_setting": "cp $(location debug_string_test.txt) $@",
|
||||
"//upb:fasttable_enabled_explicit_true": "cp $(location debug_string_test.txt) $@",
|
||||
"//conditions:default": "$(location :debug_string_test_generate) > $@",
|
||||
}),
|
||||
tools = [":debug_string_test_generate"],
|
||||
|
|
@ -250,12 +249,12 @@ genrule(
|
|||
genrule(
|
||||
name = "debug_string_test_fasttable_txt_gen",
|
||||
srcs = select({
|
||||
"//upb:fasttable_enabled_setting": [],
|
||||
"//upb:fasttable_enabled_explicit_true": [],
|
||||
"//conditions:default": ["debug_string_test.fasttable.txt"],
|
||||
}),
|
||||
outs = ["generated/debug_string_test.fasttable.txt"],
|
||||
cmd = select({
|
||||
"//upb:fasttable_enabled_setting": "$(location :debug_string_test_generate) > $@",
|
||||
"//upb:fasttable_enabled_explicit_true": "$(location :debug_string_test_generate) > $@",
|
||||
"//conditions:default": "cp $(location debug_string_test.fasttable.txt) $@",
|
||||
}),
|
||||
tools = [":debug_string_test_generate"],
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ cc_library(
|
|||
],
|
||||
copts = UPB_DEFAULT_COPTS,
|
||||
defines = select({
|
||||
"//upb:fasttable_enabled_setting": ["UPB_ENABLE_FASTTABLE"],
|
||||
"//upb:fasttable_enabled_explicit_true": ["UPB_ENABLE_FASTTABLE"],
|
||||
"//upb:fasttable_enabled_setting": ["UPB_TRY_ENABLE_FASTTABLE"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
features = UPB_DEFAULT_FEATURES,
|
||||
|
|
|
|||
|
|
@ -499,7 +499,7 @@ Error, UINTPTR_MAX is undefined
|
|||
|
||||
/* aarch64 supports big and little endian modes; fasttable performs multibyte
|
||||
* tag loads assumes the tag of a varint is in the low bits. */
|
||||
#if (defined(__x86_64__) || defined(__AARCH64EL__)) && \
|
||||
#if !defined(_WIN32) && (defined(__x86_64__) || defined(__AARCH64EL__)) && \
|
||||
UPB_HAS_ATTRIBUTE(preserve_none) && UPB_HAS_ATTRIBUTE(musttail)
|
||||
#define UPB_FASTTABLE_SUPPORTED 1
|
||||
#else
|
||||
|
|
@ -518,7 +518,11 @@ Error, UINTPTR_MAX is undefined
|
|||
* This is useful for releasing code that might be used on multiple platforms,
|
||||
* for example the PHP or Ruby C extensions. */
|
||||
#elif defined(UPB_TRY_ENABLE_FASTTABLE)
|
||||
#define UPB_FASTTABLE UPB_FASTTABLE_SUPPORTED
|
||||
#if UPB_FASTTABLE_SUPPORTED
|
||||
#define UPB_FASTTABLE 1
|
||||
#else
|
||||
#define UPB_FASTTABLE 0
|
||||
#endif
|
||||
#else
|
||||
#define UPB_FASTTABLE 0
|
||||
#endif
|
||||
|
|
@ -572,6 +576,12 @@ Error, UINTPTR_MAX is undefined
|
|||
#define UPB_RETAIN
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define UPB_HIDDEN __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define UPB_HIDDEN
|
||||
#endif
|
||||
|
||||
// Linker arrays combine elements from multiple translation units into a single
|
||||
// array that can be iterated over at runtime.
|
||||
//
|
||||
|
|
@ -625,7 +635,7 @@ Error, UINTPTR_MAX is undefined
|
|||
|
||||
#elif defined(__MACH__)
|
||||
|
||||
/* As described in: https://stackoverflow.com/a/22366882 */
|
||||
/* As described in: https://stackoverflow.com/a/22366882 */
|
||||
#define UPB_LINKARR_APPEND(name) \
|
||||
__attribute__(( \
|
||||
section("__DATA,__la_" #name))) UPB_LINKARR_ATTR UPB_NO_SANITIZE_ADDRESS
|
||||
|
|
@ -644,10 +654,10 @@ Error, UINTPTR_MAX is undefined
|
|||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
/* See:
|
||||
* https://devblogs.microsoft.com/oldnewthing/20181107-00/?p=100155
|
||||
* https://devblogs.microsoft.com/oldnewthing/20181108-00/?p=100165
|
||||
* https://devblogs.microsoft.com/oldnewthing/20181109-00/?p=100175 */
|
||||
/* See:
|
||||
* https://devblogs.microsoft.com/oldnewthing/20181107-00/?p=100155
|
||||
* https://devblogs.microsoft.com/oldnewthing/20181108-00/?p=100165
|
||||
* https://devblogs.microsoft.com/oldnewthing/20181109-00/?p=100175 */
|
||||
#define UPB_STRINGIFY_INTERNAL(x) #x
|
||||
#define UPB_STRINGIFY(x) UPB_STRINGIFY_INTERNAL(x)
|
||||
#define UPB_CONCAT(a, b, c) a##b##c
|
||||
|
|
@ -656,7 +666,7 @@ Error, UINTPTR_MAX is undefined
|
|||
#define UPB_LINKARR_APPEND(name) \
|
||||
__pragma(section(UPB_LINKARR_NAME(name, $j), read)) \
|
||||
__declspec(allocate(UPB_LINKARR_NAME(name, $j)))
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#define UPB_LINKARR_DECLARE(name, type) \
|
||||
__pragma(message(UPB_LINKARR_NAME(name, $j))) \
|
||||
__pragma(section(UPB_LINKARR_NAME(name, $a), read)) \
|
||||
|
|
@ -667,13 +677,13 @@ Error, UINTPTR_MAX is undefined
|
|||
type __stop_linkarr_##name; \
|
||||
UPB_LINKARR_APPEND(name) \
|
||||
__declspec(selectany) type UPB_linkarr_internal_empty_##name[1] = {0}
|
||||
// clang-format on
|
||||
// clang-format on
|
||||
#define UPB_LINKARR_START(name) (&__start_linkarr_##name)
|
||||
#define UPB_LINKARR_STOP(name) (&__stop_linkarr_##name)
|
||||
|
||||
#else
|
||||
|
||||
// Linker arrays are not supported on this platform. Make macros no-ops.
|
||||
// Linker arrays are not supported on this platform. Make macros no-ops.
|
||||
#define UPB_LINKARR_APPEND(name)
|
||||
#define UPB_LINKARR_DECLARE(name, type) \
|
||||
UPB_STATIC_ASSERT(sizeof("__la_" #name) <= 17, \
|
||||
|
|
|
|||
|
|
@ -94,3 +94,5 @@
|
|||
#undef _UPB_STRINGIFY
|
||||
#undef _UPB_STRINGIFY2
|
||||
#undef UPB_CONSTRUCTOR
|
||||
#undef UPB_RETAIN
|
||||
#undef UPB_HIDDEN
|
||||
|
|
|
|||
|
|
@ -543,8 +543,8 @@ void upb_DecodeFast_InlineMemcpy(void* dst, const char* src, size_t size) {
|
|||
// Workaround for b/177688959. We need to ensure that this function never goes
|
||||
// through PLT lookup. It follows that this function may not be called by
|
||||
// any other cc_library().
|
||||
__attribute__((visibility("hidden"))) UPB_PRESERVE_MOST const char*
|
||||
upb_DecodeFast_IsDoneFallback(upb_Decoder* d, const char* ptr);
|
||||
UPB_HIDDEN UPB_PRESERVE_MOST const char* upb_DecodeFast_IsDoneFallback(
|
||||
upb_Decoder* d, const char* ptr);
|
||||
|
||||
UPB_FORCEINLINE
|
||||
bool upb_DecodeFast_IsDone(upb_Decoder* d, const char** ptr) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue