Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 580726494
  • Loading branch information
congliuthu authored and copybara-github committed Nov 9, 2023
1 parent 6105bb1 commit 5987c89
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/google/protobuf/compiler/cpp/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,13 @@ bool IsPresentMessage(const Descriptor* descriptor, const Options& options) {
return true;
}

const FieldDescriptor* FindHottestField(
const std::vector<const FieldDescriptor*>& fields, const Options& options) {
(void)fields;
(void)options;
return nullptr;
}

static bool HasRepeatedFields(const Descriptor* descriptor) {
for (int i = 0; i < descriptor->field_count(); ++i) {
if (descriptor->field(i)->label() == FieldDescriptor::LABEL_REPEATED) {
Expand Down
5 changes: 5 additions & 0 deletions src/google/protobuf/compiler/cpp/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <iterator>
#include <string>
#include <tuple>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/log/absl_check.h"
Expand Down Expand Up @@ -429,6 +430,10 @@ bool ShouldForceAllocationOnConstruction(const Descriptor* desc,
// Returns true if the message is present based on PDProto profile.
bool IsPresentMessage(const Descriptor* descriptor, const Options& options);

// Returns the most likely present field. Returns nullptr if not profile driven.
const FieldDescriptor* FindHottestField(
const std::vector<const FieldDescriptor*>& fields, const Options& options);

// Does the file contain any definitions that need extension_set.h?
bool HasExtensionsOrExtendableMessage(const FileDescriptor* file);

Expand Down
24 changes: 22 additions & 2 deletions src/google/protobuf/compiler/cpp/parse_function_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,29 @@ void ParseFunctionGenerator::GenerateTailCallTable(io::Printer* printer) {
}
format(
"&$1$._instance,\n"
"$2$, // fallback\n"
"",
"$2$, // fallback\n",
DefaultInstanceName(descriptor_, options_), fallback);
std::vector<const FieldDescriptor*> subtable_fields;
for (const auto& aux : tc_table_info_->aux_entries) {
if (aux.type == internal::TailCallTableInfo::kSubTable) {
subtable_fields.push_back(aux.field);
}
}
const auto* hottest = FindHottestField(subtable_fields, options_);
// We'll prefetch `to_prefetch->to_prefetch` unconditionally to avoid
// branches. Set the pointer to itself to avoid nullptr.
printer->Emit(
{{"hottest_type_name",
QualifiedClassName(
hottest == nullptr ? descriptor_ : hottest->message_type(),
options_)}},
// clang-format off
R"cc(
#ifdef PROTOBUF_PREFETCH_PARSE_TABLE
::_pbi::TcParser::GetTable<$hottest_type_name$>(), // to_prefetch
#endif // PROTOBUF_PREFETCH_PARSE_TABLE
)cc");
// clang-format on
}
format("}, {{\n");
{
Expand Down
3 changes: 3 additions & 0 deletions src/google/protobuf/compiler/java/java_features.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/google/protobuf/compiler/plugin.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/google/protobuf/cpp_features.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5987c89

Please sign in to comment.