Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:12:20

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2008 Google Inc.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
0007 
0008 // This file contains routines to generate tail-call table parsing tables.
0009 // Everything in this file is for internal use only.
0010 
0011 #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_GEN_H__
0012 #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_GEN_H__
0013 
0014 #include <cstdint>
0015 #include <functional>
0016 #include <string>
0017 #include <vector>
0018 
0019 #include "absl/types/variant.h"
0020 #include "google/protobuf/descriptor.h"
0021 #include "google/protobuf/descriptor.pb.h"
0022 #include "google/protobuf/generated_message_tctable_decl.h"
0023 
0024 // Must come last:
0025 #include "google/protobuf/port_def.inc"
0026 
0027 namespace google {
0028 namespace protobuf {
0029 namespace internal {
0030 enum class TcParseFunction : uint8_t;
0031 
0032 namespace field_layout {
0033 enum TransformValidation : uint16_t;
0034 }  // namespace field_layout
0035 
0036 // Helper class for generating tailcall parsing functions.
0037 struct PROTOBUF_EXPORT TailCallTableInfo {
0038   struct MessageOptions {
0039     bool is_lite;
0040     bool uses_codegen;
0041     // TODO: remove this after A/B test is done.
0042     bool should_profile_driven_cluster_aux_subtable;
0043   };
0044   struct FieldOptions {
0045     const FieldDescriptor* field;
0046     int has_bit_index;
0047     // For presence awareness (e.g. PDProto).
0048     float presence_probability;
0049     // kTvEager, kTvLazy, or 0
0050     field_layout::TransformValidation lazy_opt;
0051     bool is_string_inlined;
0052     bool is_implicitly_weak;
0053     bool use_direct_tcparser_table;
0054     bool should_split;
0055     int inlined_string_index;
0056   };
0057 
0058   TailCallTableInfo(const Descriptor* descriptor,
0059                     const MessageOptions& message_options,
0060                     absl::Span<const FieldOptions> ordered_fields);
0061 
0062   TcParseFunction fallback_function;
0063 
0064   // Fields parsed by the table fast-path.
0065   struct FastFieldInfo {
0066     struct Empty {};
0067     struct Field {
0068       TcParseFunction func;
0069       const FieldDescriptor* field;
0070       uint16_t coded_tag;
0071       uint8_t hasbit_idx;
0072       uint8_t aux_idx;
0073 
0074       // For internal caching.
0075       float presence_probability;
0076     };
0077     struct NonField {
0078       TcParseFunction func;
0079       uint16_t coded_tag;
0080       uint16_t nonfield_info;
0081     };
0082     absl::variant<Empty, Field, NonField> data;
0083 
0084     bool is_empty() const { return absl::holds_alternative<Empty>(data); }
0085     const Field* AsField() const { return absl::get_if<Field>(&data); }
0086     const NonField* AsNonField() const { return absl::get_if<NonField>(&data); }
0087   };
0088   std::vector<FastFieldInfo> fast_path_fields;
0089 
0090   // Fields parsed by mini parsing routines.
0091   struct FieldEntryInfo {
0092     const FieldDescriptor* field;
0093     int hasbit_idx;
0094     int inlined_string_idx;
0095     uint16_t aux_idx;
0096     uint16_t type_card;
0097 
0098     // For internal caching.
0099     cpp::Utf8CheckMode utf8_check_mode;
0100   };
0101   std::vector<FieldEntryInfo> field_entries;
0102 
0103   enum AuxType {
0104     kNothing = 0,
0105     kInlinedStringDonatedOffset,
0106     kSplitOffset,
0107     kSplitSizeof,
0108     kSubMessage,
0109     kSubTable,
0110     kSubMessageWeak,
0111     kMessageVerifyFunc,
0112     kSelfVerifyFunc,
0113     kEnumRange,
0114     kEnumValidator,
0115     kNumericOffset,
0116     kMapAuxInfo,
0117     kCreateInArena,
0118   };
0119   struct AuxEntry {
0120     AuxType type;
0121     struct EnumRange {
0122       int16_t start;
0123       uint16_t size;
0124     };
0125     union {
0126       const FieldDescriptor* field;
0127       const Descriptor* desc;
0128       uint32_t offset;
0129       EnumRange enum_range;
0130     };
0131   };
0132   std::vector<AuxEntry> aux_entries;
0133 
0134   struct SkipEntry16 {
0135     uint16_t skipmap;
0136     uint16_t field_entry_offset;
0137   };
0138   struct SkipEntryBlock {
0139     uint32_t first_fnum;
0140     std::vector<SkipEntry16> entries;
0141   };
0142   struct NumToEntryTable {
0143     uint32_t skipmap32;  // for fields #1 - #32
0144     std::vector<SkipEntryBlock> blocks;
0145     // Compute the number of uint16_t required to represent this table.
0146     int size16() const {
0147       int size = 2;  // for the termination field#
0148       for (const auto& block : blocks) {
0149         // 2 for the field#, 1 for a count of skip entries, 2 for each entry.
0150         size += static_cast<int>(3 + block.entries.size() * 2);
0151       }
0152       return size;
0153     }
0154   };
0155   NumToEntryTable num_to_entry_table;
0156 
0157   std::vector<uint8_t> field_name_data;
0158 
0159   // Table size.
0160   int table_size_log2;
0161 };
0162 
0163 }  // namespace internal
0164 }  // namespace protobuf
0165 }  // namespace google
0166 
0167 #include "google/protobuf/port_undef.inc"
0168 
0169 #endif  // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TCTABLE_GEN_H__