File indexing completed on 2026-05-10 08:44:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_REMARKS_BITSTREAMREMARKSERIALIZER_H
0015 #define LLVM_REMARKS_BITSTREAMREMARKSERIALIZER_H
0016
0017 #include "llvm/Bitstream/BitstreamWriter.h"
0018 #include "llvm/Remarks/BitstreamRemarkContainer.h"
0019 #include "llvm/Remarks/RemarkSerializer.h"
0020 #include <optional>
0021
0022 namespace llvm {
0023 namespace remarks {
0024
0025 struct Remarks;
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 struct BitstreamRemarkSerializerHelper {
0052
0053
0054 SmallVector<char, 1024> Encoded;
0055
0056 SmallVector<uint64_t, 64> R;
0057
0058 BitstreamWriter Bitstream;
0059
0060 BitstreamRemarkContainerType ContainerType;
0061
0062
0063
0064
0065
0066 uint64_t RecordMetaContainerInfoAbbrevID = 0;
0067 uint64_t RecordMetaRemarkVersionAbbrevID = 0;
0068 uint64_t RecordMetaStrTabAbbrevID = 0;
0069 uint64_t RecordMetaExternalFileAbbrevID = 0;
0070 uint64_t RecordRemarkHeaderAbbrevID = 0;
0071 uint64_t RecordRemarkDebugLocAbbrevID = 0;
0072 uint64_t RecordRemarkHotnessAbbrevID = 0;
0073 uint64_t RecordRemarkArgWithDebugLocAbbrevID = 0;
0074 uint64_t RecordRemarkArgWithoutDebugLocAbbrevID = 0;
0075
0076 BitstreamRemarkSerializerHelper(BitstreamRemarkContainerType ContainerType);
0077
0078
0079
0080
0081 BitstreamRemarkSerializerHelper(const BitstreamRemarkSerializerHelper &) =
0082 delete;
0083 BitstreamRemarkSerializerHelper &
0084 operator=(const BitstreamRemarkSerializerHelper &) = delete;
0085 BitstreamRemarkSerializerHelper(BitstreamRemarkSerializerHelper &&) = delete;
0086 BitstreamRemarkSerializerHelper &
0087 operator=(BitstreamRemarkSerializerHelper &&) = delete;
0088
0089
0090 void setupBlockInfo();
0091
0092
0093 void setupMetaBlockInfo();
0094
0095 void setupMetaRemarkVersion();
0096 void emitMetaRemarkVersion(uint64_t RemarkVersion);
0097
0098 void setupMetaStrTab();
0099 void emitMetaStrTab(const StringTable &StrTab);
0100
0101 void setupMetaExternalFile();
0102 void emitMetaExternalFile(StringRef Filename);
0103
0104
0105 void setupRemarkBlockInfo();
0106
0107
0108 void emitMetaBlock(uint64_t ContainerVersion,
0109 std::optional<uint64_t> RemarkVersion,
0110 std::optional<const StringTable *> StrTab = std::nullopt,
0111 std::optional<StringRef> Filename = std::nullopt);
0112
0113
0114 void emitRemarkBlock(const Remark &Remark, StringTable &StrTab);
0115
0116 void flushToStream(raw_ostream &OS);
0117
0118
0119
0120 StringRef getBuffer();
0121 };
0122
0123
0124 struct BitstreamRemarkSerializer : public RemarkSerializer {
0125
0126
0127
0128
0129
0130
0131
0132
0133 bool DidSetUp = false;
0134
0135 BitstreamRemarkSerializerHelper Helper;
0136
0137
0138 BitstreamRemarkSerializer(raw_ostream &OS, SerializerMode Mode);
0139
0140 BitstreamRemarkSerializer(raw_ostream &OS, SerializerMode Mode,
0141 StringTable StrTab);
0142
0143
0144
0145
0146 void emit(const Remark &Remark) override;
0147
0148
0149
0150 std::unique_ptr<MetaSerializer> metaSerializer(
0151 raw_ostream &OS,
0152 std::optional<StringRef> ExternalFilename = std::nullopt) override;
0153
0154 static bool classof(const RemarkSerializer *S) {
0155 return S->SerializerFormat == Format::Bitstream;
0156 }
0157 };
0158
0159
0160 struct BitstreamMetaSerializer : public MetaSerializer {
0161
0162
0163
0164
0165 std::optional<BitstreamRemarkSerializerHelper> TmpHelper;
0166
0167
0168 BitstreamRemarkSerializerHelper *Helper = nullptr;
0169
0170 std::optional<const StringTable *> StrTab;
0171 std::optional<StringRef> ExternalFilename;
0172
0173
0174 BitstreamMetaSerializer(
0175 raw_ostream &OS, BitstreamRemarkContainerType ContainerType,
0176 std::optional<const StringTable *> StrTab = std::nullopt,
0177 std::optional<StringRef> ExternalFilename = std::nullopt)
0178 : MetaSerializer(OS), TmpHelper(std::nullopt), Helper(nullptr),
0179 StrTab(StrTab), ExternalFilename(ExternalFilename) {
0180 TmpHelper.emplace(ContainerType);
0181 Helper = &*TmpHelper;
0182 }
0183
0184
0185 BitstreamMetaSerializer(
0186 raw_ostream &OS, BitstreamRemarkSerializerHelper &Helper,
0187 std::optional<const StringTable *> StrTab = std::nullopt,
0188 std::optional<StringRef> ExternalFilename = std::nullopt)
0189 : MetaSerializer(OS), TmpHelper(std::nullopt), Helper(&Helper),
0190 StrTab(StrTab), ExternalFilename(ExternalFilename) {}
0191
0192 void emit() override;
0193 };
0194
0195 }
0196 }
0197
0198 #endif