LLVM 23.0.0git
RemarkStreamer.h
Go to the documentation of this file.
1//===- llvm/Remarks/RemarkStreamer.h ----------------------------*- 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 declares the main interface for streaming remarks.
10//
11// This is used to stream any llvm::remarks::Remark to an open file taking
12// advantage of all the serialization capabilities developed for remarks (e.g.
13// metadata in a section, bitstream format, etc.).
14//
15// Typically, a specialized remark emitter should hold a reference to the main
16// remark streamer set up in the LLVMContext, and should convert specialized
17// diagnostics to llvm::remarks::Remark objects as they get emitted.
18//
19// Specialized remark emitters can be components like:
20// * Remarks from LLVM (M)IR passes
21// * Remarks from the frontend
22// * Remarks from an intermediate IR
23//
24// This allows for composition between specialized remark emitters throughout
25// the compilation pipeline, that end up in the same file, using the same format
26// and serialization techniques.
27//
28//===----------------------------------------------------------------------===//
29
30#ifndef LLVM_REMARKS_REMARKSTREAMER_H
31#define LLVM_REMARKS_REMARKSTREAMER_H
32
34#include "llvm/Support/Error.h"
35#include "llvm/Support/Regex.h"
36#include <memory>
37#include <optional>
38
39namespace llvm {
40
41class raw_ostream;
42
43namespace remarks {
44class RemarkStreamer final {
45 /// The regex used to filter remarks based on the passes that emit them.
46 std::optional<Regex> PassFilter;
47 /// The object used to serialize the remarks to a specific format.
48 std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer;
49 /// The filename that the remark diagnostics are emitted to.
50 const std::optional<std::string> Filename;
51
52public:
54 RemarkStreamer(std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
55 std::optional<StringRef> Filename = std::nullopt);
57
58 /// Return the filename that the remark diagnostics are emitted to.
59 std::optional<StringRef> getFilename() const {
60 return Filename ? std::optional<StringRef>(*Filename) : std::nullopt;
61 }
62 /// Return stream that the remark diagnostics are emitted to.
63 raw_ostream &getStream() { return RemarkSerializer->OS; }
64 /// Return the serializer used for this stream.
65 remarks::RemarkSerializer &getSerializer() { return *RemarkSerializer; }
66
67 /// Release the underlying RemarkSerializer. Destructing the RemarkStreamer
68 /// will assert that the RemarkStreamer has been released, to ensure that the
69 /// remarks were properly finalized.
70 std::unique_ptr<remarks::RemarkSerializer> releaseSerializer() {
71 return std::move(RemarkSerializer);
72 }
73
74 /// Set a pass filter based on a regex \p Filter.
75 /// Returns an error if the regex is invalid.
77 /// Check wether the string matches the filter.
79 /// Check if the remarks NEED to have metadata in an object section
80 LLVM_ABI bool needsSection() const;
81 /// Check if the remarks should store associated metadata if suppported
82 LLVM_ABI bool wantsSection() const;
83};
84} // end namespace remarks
85} // end namespace llvm
86
87#endif // LLVM_REMARKS_REMARKSTREAMER_H
#define LLVM_ABI
Definition Compiler.h:213
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
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
std::optional< StringRef > getFilename() const
Return the filename that the remark diagnostics are emitted to.
LLVM_ABI Error setFilter(StringRef Filter)
Set a pass filter based on a regex Filter.
LLVM_ABI bool needsSection() const
Check if the remarks NEED to have metadata in an object section.
LLVM_ABI bool wantsSection() const
Check if the remarks should store associated metadata if suppported.
remarks::RemarkSerializer & getSerializer()
Return the serializer used for this stream.
LLVM_ABI RemarkStreamer(std::unique_ptr< remarks::RemarkSerializer > RemarkSerializer, std::optional< StringRef > Filename=std::nullopt)
std::unique_ptr< remarks::RemarkSerializer > releaseSerializer()
Release the underlying RemarkSerializer.
LLVM_ABI bool matchesFilter(StringRef Str)
Check wether the string matches the filter.
raw_ostream & getStream()
Return stream that the remark diagnostics are emitted to.
This is an optimization pass for GlobalISel generic memory operations.
This is the base class for a remark serializer.