LLVM 22.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/Remarks/Remark.h"
19#include "llvm/Support/Error.h"
20#include <memory>
21#include <optional>
22#include <string>
23
24namespace llvm {
25
26class DiagnosticInfoOptimizationBase;
27class LLVMContext;
28class ToolOutputFile;
29namespace remarks {
30class RemarkStreamer;
31}
32
33/// Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo
34/// objects.
37 /// Convert diagnostics into remark objects.
38 /// The lifetime of the members of the result is bound to the lifetime of
39 /// the LLVM diagnostics.
40 remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag) const;
41
42public:
44 /// Emit a diagnostic through the streamer.
46};
47
48template <typename ThisError>
49struct LLVMRemarkSetupErrorInfo : public ErrorInfo<ThisError> {
50 std::string Msg;
51 std::error_code EC;
52
54 handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
55 Msg = EIB.message();
56 EC = EIB.convertToErrorCode();
57 });
58 }
59
60 void log(raw_ostream &OS) const override { OS << Msg; }
61 std::error_code convertToErrorCode() const override { return EC; }
62};
63
65 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFileError> {
66 LLVM_ABI static char ID;
68 LLVMRemarkSetupFileError>::LLVMRemarkSetupErrorInfo;
69};
70
72 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupPatternError> {
73 LLVM_ABI static char ID;
75 LLVMRemarkSetupPatternError>::LLVMRemarkSetupErrorInfo;
76};
77
79 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFormatError> {
80 LLVM_ABI static char ID;
82 LLVMRemarkSetupFormatError>::LLVMRemarkSetupErrorInfo;
83};
84
85/// Setup optimization remarks that output to a file.
89 std::optional<uint64_t> RemarksHotnessThreshold = 0);
90
91/// Setup optimization remarks that output directly to a raw_ostream.
92/// \p OS is managed by the caller and should be open for writing as long as \p
93/// Context is streaming remarks to it.
97 std::optional<uint64_t> RemarksHotnessThreshold = 0);
98
99} // end namespace llvm
100
101#endif // LLVM_IR_LLVMREMARKSTREAMER_H
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
Common features for diagnostics dealing with optimization remarks that are used by both IR and MIR pa...
Base class for error info classes.
Definition: Error.h:44
virtual std::string message() const
Return the error message as a string.
Definition: Error.h:52
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
Base class for user error types.
Definition: Error.h:354
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Tagged union holding either a T or a Error.
Definition: Error.h:485
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo objects.
LLVMRemarkStreamer(remarks::RemarkStreamer &RS)
LLVM_ABI void emit(const DiagnosticInfoOptimizationBase &Diag)
Emit a diagnostic through the streamer.
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
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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"))
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"))
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:990
LLVM_ABI Expected< std::unique_ptr< ToolOutputFile > > setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, StringRef RemarksPasses, StringRef RemarksFormat, bool RemarksWithHotness, std::optional< uint64_t > RemarksHotnessThreshold=0)
Setup optimization remarks that output to a file.
cl::opt< bool > RemarksWithHotness("lto-pass-remarks-with-hotness", cl::desc("With PGO, include profile count in optimization remarks"), cl::Hidden)
cl::opt< std::string > RemarksFilename("lto-pass-remarks-output", cl::desc("Output filename for pass remarks"), cl::value_desc("filename"))
cl::opt< std::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)
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
void log(raw_ostream &OS) const override
Print an error message to an output stream.
A remark type used for both emission and parsing.
Definition: Remark.h:98