LLVM 23.0.0git
BitstreamRemarkSerializer.h
Go to the documentation of this file.
1//===-- BitstreamRemarkSerializer.h - Bitstream serializer ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides an implementation of the serializer using the LLVM
10// Bitstream format.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_REMARKS_BITSTREAMREMARKSERIALIZER_H
15#define LLVM_REMARKS_BITSTREAMREMARKSERIALIZER_H
16
20#include <optional>
21
22namespace llvm {
23namespace remarks {
24
25struct Remarks;
26
27/// Serialize the remarks to LLVM bitstream.
28/// This class provides ways to emit remarks in the LLVM bitstream format and
29/// its associated metadata.
31 /// Buffer used to construct records and pass to the bitstream writer.
33 /// The Bitstream writer.
35 /// The type of the container we are serializing.
37
38 /// Abbrev IDs initialized in the block info block.
39 /// Note: depending on the container type, some IDs might be uninitialized.
40 /// Warning: When adding more abbrev IDs, make sure to update the
41 /// BlockCodeSize (in the call to EnterSubblock).
51
54 raw_ostream &OS);
55
56 // Disable copy and move: Bitstream points to Encoded, which needs special
57 // handling during copy/move, but moving the vectors is probably useless
58 // anyway.
60 delete;
66
67 /// Set up the necessary block info entries according to the container type.
69
70 /// Set up the block info for the metadata block.
72 /// The remark version in the metadata block.
74 LLVM_ABI void emitMetaRemarkVersion(uint64_t RemarkVersion);
75 /// The strtab in the metadata block.
77 LLVM_ABI void emitMetaStrTab(const StringTable &StrTab);
78 /// The external file in the metadata block.
81
82 /// The block info for the remarks block.
84
85 /// Emit the main metadata at the beginning of the file
86 LLVM_ABI void emitMetaBlock(std::optional<StringRef> Filename = std::nullopt);
87
88 /// Emit the remaining metadata at the end of the file. Here we emit metadata
89 /// that is only known once all remarks were emitted.
90 LLVM_ABI void emitLateMetaBlock(const StringTable &StrTab);
91
92 /// Emit a remark block. The string table is required.
93 LLVM_ABI void emitRemark(const Remark &Remark, StringTable &StrTab);
94};
95
96/// Implementation of the remark serializer using LLVM bitstream.
98 /// The file should contain:
99 /// 1) The block info block that describes how to read the blocks.
100 /// 2) The metadata block that contains various information about the remarks
101 /// in the file.
102 /// 3) A number of remark blocks.
103 /// 4) Another metadata block for metadata that is only finalized once all
104 /// remarks were emitted (e.g. StrTab)
105
106 /// The helper to emit bitstream. This is nullopt when the Serializer has not
107 /// been setup yet.
108 std::optional<BitstreamRemarkSerializerHelper> Helper;
109
110 /// Construct a serializer that will create its own string table.
112 /// Construct a serializer with a pre-filled string table.
114
116
117 /// Emit a remark to the stream. This also emits the metadata associated to
118 /// the remarks. This writes the serialized output to the provided stream.
119 void emit(const Remark &Remark) override;
120
121 /// Finalize emission of remarks. This emits the late metadata block and
122 /// flushes internal buffers. It is safe to call this function multiple times,
123 /// and it is automatically executed on destruction of the Serializer.
124 void finalize() override;
125
126 /// The metadata serializer associated to this remark serializer. Based on the
127 /// container type of the current serializer, the container type of the
128 /// metadata serializer will change.
129 std::unique_ptr<MetaSerializer>
130 metaSerializer(raw_ostream &OS, StringRef ExternalFilename) override;
131
132 static bool classof(const RemarkSerializer *S) {
134 }
135
136private:
137 void setup();
138};
139
140/// Serializer of metadata for bitstream remarks.
142 std::optional<BitstreamRemarkSerializerHelper> Helper;
143
145
146 /// Create a new meta serializer based on \p ContainerType.
153
154 void emit() override;
155};
156
157} // end namespace remarks
158} // end namespace llvm
159
160#endif // LLVM_REMARKS_BITSTREAMREMARKSERIALIZER_H
arc branch finalize
#define LLVM_ABI
Definition Compiler.h:213
static constexpr StringLiteral Filename
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
BitstreamRemarkContainerType
Type of the remark container.
This is an optimization pass for GlobalISel generic memory operations.
std::optional< BitstreamRemarkSerializerHelper > Helper
BitstreamMetaSerializer(raw_ostream &OS, BitstreamRemarkContainerType ContainerType, StringRef ExternalFilename)
Create a new meta serializer based on ContainerType.
BitstreamRemarkSerializerHelper(const BitstreamRemarkSerializerHelper &)=delete
LLVM_ABI void emitMetaBlock(std::optional< StringRef > Filename=std::nullopt)
Emit the main metadata at the beginning of the file.
LLVM_ABI void setupMetaBlockInfo()
Set up the block info for the metadata block.
LLVM_ABI BitstreamRemarkSerializerHelper(BitstreamRemarkContainerType ContainerType, raw_ostream &OS)
SmallVector< uint64_t, 64 > R
Buffer used to construct records and pass to the bitstream writer.
BitstreamRemarkContainerType ContainerType
The type of the container we are serializing.
BitstreamRemarkSerializerHelper & operator=(const BitstreamRemarkSerializerHelper &)=delete
LLVM_ABI void setupRemarkBlockInfo()
The block info for the remarks block.
LLVM_ABI void setupMetaExternalFile()
The external file in the metadata block.
BitstreamRemarkSerializerHelper(BitstreamRemarkSerializerHelper &&)=delete
LLVM_ABI void setupBlockInfo()
Set up the necessary block info entries according to the container type.
LLVM_ABI void setupMetaRemarkVersion()
The remark version in the metadata block.
BitstreamRemarkSerializerHelper & operator=(BitstreamRemarkSerializerHelper &&)=delete
LLVM_ABI void emitMetaRemarkVersion(uint64_t RemarkVersion)
LLVM_ABI void emitMetaStrTab(const StringTable &StrTab)
LLVM_ABI void setupMetaStrTab()
The strtab in the metadata block.
LLVM_ABI void emitLateMetaBlock(const StringTable &StrTab)
Emit the remaining metadata at the end of the file.
LLVM_ABI void emitRemark(const Remark &Remark, StringTable &StrTab)
Emit a remark block. The string table is required.
uint64_t RecordMetaContainerInfoAbbrevID
Abbrev IDs initialized in the block info block.
std::unique_ptr< MetaSerializer > metaSerializer(raw_ostream &OS, StringRef ExternalFilename) override
The metadata serializer associated to this remark serializer.
std::optional< BitstreamRemarkSerializerHelper > Helper
The file should contain: 1) The block info block that describes how to read the blocks.
BitstreamRemarkSerializer(raw_ostream &OS)
Construct a serializer that will create its own string table.
static bool classof(const RemarkSerializer *S)
void emit(const Remark &Remark) override
Emit a remark to the stream.
raw_ostream & OS
The open raw_ostream that the metadata is emitted to.
Format SerializerFormat
The format of the serializer.
RemarkSerializer(Format SerializerFormat, raw_ostream &OS)
std::optional< StringTable > StrTab
The string table containing all the unique strings used in the output.
raw_ostream & OS
The open raw_ostream that the remark diagnostics are emitted to.
A remark type used for both emission and parsing.
Definition Remark.h:107
The string table used for serializing remarks.