Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.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
53 raw_ostream &OS);
54
55 // Disable copy and move: Bitstream points to Encoded, which needs special
56 // handling during copy/move, but moving the vectors is probably useless
57 // anyway.
59 delete;
65
66 /// Set up the necessary block info entries according to the container type.
67 void setupBlockInfo();
68
69 /// Set up the block info for the metadata block.
70 void setupMetaBlockInfo();
71 /// The remark version in the metadata block.
73 void emitMetaRemarkVersion(uint64_t RemarkVersion);
74 /// The strtab in the metadata block.
75 void setupMetaStrTab();
76 void emitMetaStrTab(const StringTable &StrTab);
77 /// The external file in the metadata block.
79 void emitMetaExternalFile(StringRef Filename);
80
81 /// The block info for the remarks block.
83
84 /// Emit the main metadata at the beginning of the file
85 void emitMetaBlock(std::optional<StringRef> Filename = std::nullopt);
86
87 /// Emit the remaining metadata at the end of the file. Here we emit metadata
88 /// that is only known once all remarks were emitted.
89 void emitLateMetaBlock(const StringTable &StrTab);
90
91 /// Emit a remark block. The string table is required.
92 void emitRemark(const Remark &Remark, StringTable &StrTab);
93};
94
95/// Implementation of the remark serializer using LLVM bitstream.
97 /// The file should contain:
98 /// 1) The block info block that describes how to read the blocks.
99 /// 2) The metadata block that contains various information about the remarks
100 /// in the file.
101 /// 3) A number of remark blocks.
102 /// 4) Another metadata block for metadata that is only finalized once all
103 /// remarks were emitted (e.g. StrTab)
104
105 /// The helper to emit bitstream. This is nullopt when the Serializer has not
106 /// been setup yet.
107 std::optional<BitstreamRemarkSerializerHelper> Helper;
108
109 /// Construct a serializer that will create its own string table.
111 /// Construct a serializer with a pre-filled string table.
113
115
116 /// Emit a remark to the stream. This also emits the metadata associated to
117 /// the remarks. This writes the serialized output to the provided stream.
118 void emit(const Remark &Remark) override;
119
120 /// Finalize emission of remarks. This emits the late metadata block and
121 /// flushes internal buffers. It is safe to call this function multiple times,
122 /// and it is automatically executed on destruction of the Serializer.
123 void finalize() override;
124
125 /// The metadata serializer associated to this remark serializer. Based on the
126 /// container type of the current serializer, the container type of the
127 /// metadata serializer will change.
128 std::unique_ptr<MetaSerializer>
129 metaSerializer(raw_ostream &OS, StringRef ExternalFilename) override;
130
131 static bool classof(const RemarkSerializer *S) {
133 }
134
135private:
136 void setup();
137};
138
139/// Serializer of metadata for bitstream remarks.
141 std::optional<BitstreamRemarkSerializerHelper> Helper;
142
144
145 /// Create a new meta serializer based on \p ContainerType.
152
153 void emit() override;
154};
155
156} // end namespace remarks
157} // end namespace llvm
158
159#endif // LLVM_REMARKS_BITSTREAMREMARKSERIALIZER_H
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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
void emitMetaBlock(std::optional< StringRef > Filename=std::nullopt)
Emit the main metadata at the beginning of the file.
void setupMetaBlockInfo()
Set up the block info for the metadata block.
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
void setupRemarkBlockInfo()
The block info for the remarks block.
void setupMetaExternalFile()
The external file in the metadata block.
BitstreamRemarkSerializerHelper(BitstreamRemarkSerializerHelper &&)=delete
void setupBlockInfo()
Set up the necessary block info entries according to the container type.
void setupMetaRemarkVersion()
The remark version in the metadata block.
BitstreamRemarkSerializerHelper & operator=(BitstreamRemarkSerializerHelper &&)=delete
void setupMetaStrTab()
The strtab in the metadata block.
void emitLateMetaBlock(const StringTable &StrTab)
Emit the remaining metadata at the end of the file.
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.
void finalize() override
Finalize emission of remarks.
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:98
The string table used for serializing remarks.