LLVM  16.0.0git
RemarkSerializer.h
Go to the documentation of this file.
1 //===-- RemarkSerializer.h - Remark serialization interface -----*- 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 interface for serializing remarks to different formats.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_REMARKS_REMARKSERIALIZER_H
14 #define LLVM_REMARKS_REMARKSERIALIZER_H
15 
18 
19 namespace llvm {
20 
21 class raw_ostream;
22 
23 namespace remarks {
24 
25 struct Remark;
26 
27 enum class SerializerMode {
28  Separate, // A mode where the metadata is serialized separately from the
29  // remarks. Typically, this is used when the remarks need to be
30  // streamed to a side file and the metadata is embedded into the
31  // final result of the compilation.
32  Standalone // A mode where everything can be retrieved in the same
33  // file/buffer. Typically, this is used for storing remarks for
34  // later use.
35 };
36 
37 struct MetaSerializer;
38 
39 /// This is the base class for a remark serializer.
40 /// It includes support for using a string table while emitting.
42  /// The format of the serializer.
44  /// The open raw_ostream that the remark diagnostics are emitted to.
46  /// The serialization mode.
48  /// The string table containing all the unique strings used in the output.
49  /// The table can be serialized to be consumed after the compilation.
51 
55 
56  /// This is just an interface.
57  virtual ~RemarkSerializer() = default;
58  /// Emit a remark to the stream.
59  virtual void emit(const Remark &Remark) = 0;
60  /// Return the corresponding metadata serializer.
61  virtual std::unique_ptr<MetaSerializer>
63  Optional<StringRef> ExternalFilename = std::nullopt) = 0;
64 };
65 
66 /// This is the base class for a remark metadata serializer.
68  /// The open raw_ostream that the metadata is emitted to.
70 
72 
73  /// This is just an interface.
74  virtual ~MetaSerializer() = default;
75  virtual void emit() = 0;
76 };
77 
78 /// Create a remark serializer.
81  raw_ostream &OS);
82 
83 /// Create a remark serializer that uses a pre-filled string table.
86  raw_ostream &OS, remarks::StringTable StrTab);
87 
88 } // end namespace remarks
89 } // end namespace llvm
90 
91 #endif // LLVM_REMARKS_REMARKSERIALIZER_H
llvm::remarks::SerializerMode
SerializerMode
Definition: RemarkSerializer.h:27
llvm::remarks::MetaSerializer::~MetaSerializer
virtual ~MetaSerializer()=default
This is just an interface.
llvm::remarks::createRemarkSerializer
Expected< std::unique_ptr< RemarkSerializer > > createRemarkSerializer(Format RemarksFormat, SerializerMode Mode, raw_ostream &OS)
Create a remark serializer.
Definition: RemarkSerializer.cpp:21
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::remarks::StringTable
The string table used for serializing remarks.
Definition: RemarkStringTable.h:36
llvm::remarks::SerializerMode::Standalone
@ Standalone
RemarkStringTable.h
llvm::remarks::SerializerMode::Separate
@ Separate
llvm::remarks::RemarkSerializer::StrTab
Optional< StringTable > StrTab
The string table containing all the unique strings used in the output.
Definition: RemarkSerializer.h:50
llvm::Optional
Definition: APInt.h:33
llvm::remarks::RemarkSerializer::OS
raw_ostream & OS
The open raw_ostream that the remark diagnostics are emitted to.
Definition: RemarkSerializer.h:45
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::remarks::RemarkSerializer::SerializerFormat
Format SerializerFormat
The format of the serializer.
Definition: RemarkSerializer.h:43
llvm::remarks::RemarkSerializer::Mode
SerializerMode Mode
The serialization mode.
Definition: RemarkSerializer.h:47
llvm::remarks::RemarkSerializer::metaSerializer
virtual std::unique_ptr< MetaSerializer > metaSerializer(raw_ostream &OS, Optional< StringRef > ExternalFilename=std::nullopt)=0
Return the corresponding metadata serializer.
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::remarks::Remark
A remark type used for both emission and parsing.
Definition: Remark.h:67
llvm::remarks::MetaSerializer::emit
virtual void emit()=0
llvm::remarks::RemarkSerializer
This is the base class for a remark serializer.
Definition: RemarkSerializer.h:41
RemarkFormat.h
llvm::RemarksFormat
cl::opt< std::string > RemarksFormat("lto-pass-remarks-format", cl::desc("The format used for serializing remarks (default: YAML)"), cl::value_desc("format"), cl::init("yaml"))
Definition: ThinLTOCodeGenerator.cpp:83
llvm::remarks::RemarkSerializer::emit
virtual void emit(const Remark &Remark)=0
Emit a remark to the stream.
llvm::HighlightColor::Remark
@ Remark
Mode
SI Whole Quad Mode
Definition: SIWholeQuadMode.cpp:264
llvm::remarks::MetaSerializer::OS
raw_ostream & OS
The open raw_ostream that the metadata is emitted to.
Definition: RemarkSerializer.h:69
llvm::remarks::RemarkSerializer::~RemarkSerializer
virtual ~RemarkSerializer()=default
This is just an interface.
llvm::remarks::MetaSerializer
This is the base class for a remark metadata serializer.
Definition: RemarkSerializer.h:67
llvm::remarks::MetaSerializer::MetaSerializer
MetaSerializer(raw_ostream &OS)
Definition: RemarkSerializer.h:71
llvm::remarks::RemarkSerializer::RemarkSerializer
RemarkSerializer(Format SerializerFormat, raw_ostream &OS, SerializerMode Mode)
Definition: RemarkSerializer.h:52
llvm::remarks::Format
Format
The format used for serializing/deserializing remarks.
Definition: RemarkFormat.h:25