LLVM  14.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 
33 #include "llvm/ADT/Optional.h"
35 #include "llvm/Support/Error.h"
36 #include "llvm/Support/Regex.h"
38 #include <memory>
39 
40 namespace llvm {
41 namespace remarks {
42 class RemarkStreamer final {
43  /// The regex used to filter remarks based on the passes that emit them.
44  Optional<Regex> PassFilter;
45  /// The object used to serialize the remarks to a specific format.
46  std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer;
47  /// The filename that the remark diagnostics are emitted to.
48  const Optional<std::string> Filename;
49 
50 public:
51  RemarkStreamer(std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
52  Optional<StringRef> Filename = None);
53 
54  /// Return the filename that the remark diagnostics are emitted to.
56  return Filename ? Optional<StringRef>(*Filename) : None;
57  }
58  /// Return stream that the remark diagnostics are emitted to.
60  /// Return the serializer used for this stream.
62  /// Set a pass filter based on a regex \p Filter.
63  /// Returns an error if the regex is invalid.
64  Error setFilter(StringRef Filter);
65  /// Check wether the string matches the filter.
66  bool matchesFilter(StringRef Str);
67  /// Check if the remarks also need to have associated metadata in a section.
68  bool needsSection() const;
69 };
70 } // end namespace remarks
71 } // end namespace llvm
72 
73 #endif // LLVM_REMARKS_REMARKSTREAMER_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Optional.h
llvm::remarks::RemarkStreamer
Definition: RemarkStreamer.h:42
Error.h
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:42
llvm::remarks::RemarkStreamer::RemarkStreamer
RemarkStreamer(std::unique_ptr< remarks::RemarkSerializer > RemarkSerializer, Optional< StringRef > Filename=None)
Definition: RemarkStreamer.cpp:26
llvm::remarks::RemarkStreamer::getSerializer
remarks::RemarkSerializer & getSerializer()
Return the serializer used for this stream.
Definition: RemarkStreamer.h:61
remarks
annotation remarks
Definition: AnnotationRemarks.cpp:117
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::remarks::RemarkStreamer::needsSection
bool needsSection() const
Check if the remarks also need to have associated metadata in a section.
Definition: RemarkStreamer.cpp:49
llvm::None
const NoneType None
Definition: None.h:23
llvm::remarks::RemarkSerializer
This is the base class for a remark serializer.
Definition: RemarkSerializer.h:38
llvm::remarks::RemarkStreamer::getFilename
Optional< StringRef > getFilename() const
Return the filename that the remark diagnostics are emitted to.
Definition: RemarkStreamer.h:55
Regex.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::remarks::RemarkStreamer::setFilter
Error setFilter(StringRef Filter)
Set a pass filter based on a regex Filter.
Definition: RemarkStreamer.cpp:32
llvm::remarks::RemarkStreamer::getStream
raw_ostream & getStream()
Return stream that the remark diagnostics are emitted to.
Definition: RemarkStreamer.h:59
llvm::remarks::RemarkStreamer::matchesFilter
bool matchesFilter(StringRef Str)
Check wether the string matches the filter.
Definition: RemarkStreamer.cpp:42
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
RemarkSerializer.h
raw_ostream.h