LLVM  14.0.0git
LLVMRemarkStreamer.h
Go to the documentation of this file.
1 //===- llvm/IR/LLVMRemarkStreamer.h - Streamer for LLVM remarks--*- 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 implements the conversion between IR Diagnostics and
10 // serializable remarks::Remark objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_IR_LLVMREMARKSTREAMER_H
15 #define LLVM_IR_LLVMREMARKSTREAMER_H
16 
17 #include "llvm/IR/DiagnosticInfo.h"
19 #include "llvm/Support/Error.h"
21 #include <memory>
22 #include <string>
23 
24 namespace llvm {
25 /// Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo
26 /// objects.
29  /// Convert diagnostics into remark objects.
30  /// The lifetime of the members of the result is bound to the lifetime of
31  /// the LLVM diagnostics.
32  remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag) const;
33 
34 public:
36  /// Emit a diagnostic through the streamer.
37  void emit(const DiagnosticInfoOptimizationBase &Diag);
38 };
39 
40 template <typename ThisError>
41 struct LLVMRemarkSetupErrorInfo : public ErrorInfo<ThisError> {
42  std::string Msg;
43  std::error_code EC;
44 
46  handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
47  Msg = EIB.message();
48  EC = EIB.convertToErrorCode();
49  });
50  }
51 
52  void log(raw_ostream &OS) const override { OS << Msg; }
53  std::error_code convertToErrorCode() const override { return EC; }
54 };
55 
57  : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFileError> {
58  static char ID;
61 };
62 
64  : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupPatternError> {
65  static char ID;
68 };
69 
71  : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFormatError> {
72  static char ID;
75 };
76 
77 /// Setup optimization remarks that output to a file.
81  bool RemarksWithHotness,
83 
84 /// Setup optimization remarks that output directly to a raw_ostream.
85 /// \p OS is managed by the caller and should be open for writing as long as \p
86 /// Context is streaming remarks to it.
91 
92 } // end namespace llvm
93 
94 #endif // LLVM_IR_LLVMREMARKSTREAMER_H
llvm::RemarksPasses
cl::opt< std::string > RemarksPasses("lto-pass-remarks-filter", cl::desc("Only record optimization remarks from passes whose " "names match the given regular expression"), cl::value_desc("regex"))
Definition: ThinLTOCodeGenerator.cpp:81
llvm::LLVMRemarkSetupPatternError::ID
static char ID
Definition: LLVMRemarkStreamer.h:65
llvm::LLVMRemarkSetupErrorInfo::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: LLVMRemarkStreamer.h:53
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::remarks::RemarkStreamer
Definition: RemarkStreamer.h:42
llvm::LLVMRemarkSetupFileError::ID
static char ID
Definition: LLVMRemarkStreamer.h:58
llvm::LLVMRemarkSetupPatternError
Definition: LLVMRemarkStreamer.h:63
llvm::RemarksFilename
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
Definition: ThinLTOCodeGenerator.cpp:80
Error.h
llvm::RemarksHotnessThreshold
cl::opt< Optional< uint64_t >, false, remarks::HotnessThresholdParser > RemarksHotnessThreshold("lto-pass-remarks-hotness-threshold", cl::desc("Minimum profile count required for an " "optimization remark to be output." " Use 'auto' to apply the threshold from profile summary."), cl::value_desc("uint or 'auto'"), cl::init(0), cl::Hidden)
Definition: ThinLTOCodeGenerator.cpp:84
llvm::Optional< uint64_t >
llvm::RemarksWithHotness
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
Definition: ThinLTOCodeGenerator.cpp:82
llvm::LLVMRemarkSetupErrorInfo::log
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Definition: LLVMRemarkStreamer.h:52
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::LLVMRemarkStreamer::emit
void emit(const DiagnosticInfoOptimizationBase &Diag)
Emit a diagnostic through the streamer.
Definition: LLVMRemarkStreamer.cpp:78
llvm::DiagnosticInfoOptimizationBase
Common features for diagnostics dealing with optimization remarks that are used by both IR and MIR pa...
Definition: DiagnosticInfo.h:409
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::LLVMRemarkStreamer
Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo objects.
Definition: LLVMRemarkStreamer.h:27
llvm::setupLLVMOptimizationRemarks
Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, Optional< uint64_t > RemarksHotnessThreshold=0)
Setup optimization remarks that output to a file.
Definition: LLVMRemarkStreamer.cpp:92
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::LLVMRemarkSetupErrorInfo::EC
std::error_code EC
Definition: LLVMRemarkStreamer.h:43
llvm::LLVMRemarkSetupFileError
Definition: LLVMRemarkStreamer.h:56
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::Remark
A remark type used for both emission and parsing.
Definition: Remark.h:67
llvm::ErrorInfoBase::convertToErrorCode
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
llvm::ErrorInfoBase
Base class for error info classes.
Definition: Error.h:48
llvm::ErrorInfoBase::message
virtual std::string message() const
Return the error message as a string.
Definition: Error.h:56
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:85
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
ToolOutputFile.h
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:349
llvm::LLVMRemarkSetupFormatError
Definition: LLVMRemarkStreamer.h:70
llvm::LLVMRemarkSetupErrorInfo::Msg
std::string Msg
Definition: LLVMRemarkStreamer.h:42
llvm::LLVMRemarkStreamer::LLVMRemarkStreamer
LLVMRemarkStreamer(remarks::RemarkStreamer &RS)
Definition: LLVMRemarkStreamer.h:35
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::LLVMRemarkSetupErrorInfo
Definition: LLVMRemarkStreamer.h:41
llvm::LLVMRemarkSetupErrorInfo::LLVMRemarkSetupErrorInfo
LLVMRemarkSetupErrorInfo(Error E)
Definition: LLVMRemarkStreamer.h:45
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
RemarkStreamer.h
DiagnosticInfo.h
llvm::LLVMRemarkSetupFormatError::ID
static char ID
Definition: LLVMRemarkStreamer.h:72
llvm::handleAllErrors
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:958