LLVM 24.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
25/// Serialize the remarks to LLVM bitstream.
26/// This class provides ways to emit remarks in the LLVM bitstream format and
27/// its associated metadata.
29 /// Buffer used to construct records and pass to the bitstream writer.
31 /// The Bitstream writer.
33 /// The type of the container we are serializing.
35
36 /// Abbrev IDs initialized in the block info block.
37 /// Note: depending on the container type, some IDs might be uninitialized.
38 /// Warning: When adding more abbrev IDs, make sure to update the
39 /// BlockCodeSize (in the call to EnterSubblock).
49
52 raw_ostream &OS);
53
54 // Disable copy and move: Bitstream points to Encoded, which needs special
55 // handling during copy/move, but moving the vectors is probably useless
56 // anyway.
58 delete;
64
65 /// Set up the necessary block info entries according to the container type.
67
68 /// Set up the block info for the metadata block.
70 /// The remark version in the metadata block.
72 LLVM_ABI void emitMetaRemarkVersion(uint64_t RemarkVersion);
73 /// The strtab in the metadata block.
75 LLVM_ABI void emitMetaStrTab(const StringTable &StrTab);
76 /// The external file in the metadata block.
79
80 /// The block info for the remarks block.
82
83 /// Emit the main metadata at the beginning of the file
84 LLVM_ABI void emitMetaBlock(std::optional<StringRef> Filename = std::nullopt);
85
86 /// Emit the remaining metadata at the end of the file. Here we emit metadata
87 /// that is only known once all remarks were emitted.
88 LLVM_ABI void emitLateMetaBlock(const StringTable &StrTab);
89
90 /// Emit a remark block. The string table is required.
91 LLVM_ABI void emitRemark(const Remark &Remark, StringTable &StrTab);
92};
93
94/// Implementation of the remark serializer using LLVM bitstream.
96 /// The file should contain:
97 /// 1) The block info block that describes how to read the blocks.
98 /// 2) The metadata block that contains various information about the remarks
99 /// in the file.
100 /// 3) A number of remark blocks.
101 /// 4) Another metadata block for metadata that is only finalized once all
102 /// remarks were emitted (e.g. StrTab)
103
104 /// The helper to emit bitstream. This is nullopt when the Serializer has not
105 /// been setup yet.
106 std::optional<BitstreamRemarkSerializerHelper> Helper;
107
108 /// Construct a serializer that will create its own string table.
110 /// Construct a serializer with a pre-filled string table.
112
114
115 /// Emit a remark to the stream. This also emits the metadata associated to
116 /// the remarks. This writes the serialized output to the provided stream.
117 void emit(const Remark &Remark) override;
118
119 /// Finalize emission of remarks. This emits the late metadata block and
120 /// flushes internal buffers. It is safe to call this function multiple times,
121 /// and it is automatically executed on destruction of the Serializer.
122 void finalize() override;
123
124 /// The metadata serializer associated to this remark serializer. Based on the
125 /// container type of the current serializer, the container type of the
126 /// metadata serializer will change.
127 std::unique_ptr<MetaSerializer>
128 metaSerializer(raw_ostream &OS, StringRef ExternalFilename) override;
129
130 static bool classof(const RemarkSerializer *S) {
132 }
133
134private:
135 void setup();
136};
137
138/// Serializer of metadata for bitstream remarks.
140 std::optional<BitstreamRemarkSerializerHelper> Helper;
141
143
144 /// Create a new meta serializer based on \p ContainerType.
151
152 void emit() override;
153};
154
155} // end namespace remarks
156} // end namespace llvm
157
158#endif // LLVM_REMARKS_BITSTREAMREMARKSERIALIZER_H
uint64_t uint64_t
arc branch finalize
#define LLVM_ABI
Definition Compiler.h:211
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.