LLVM 20.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"
18#include "llvm/Support/Error.h"
19#include <memory>
20#include <optional>
21#include <string>
22
23namespace llvm {
24
25class DiagnosticInfoOptimizationBase;
26class LLVMContext;
27class ToolOutputFile;
28namespace remarks {
29class RemarkStreamer;
30}
31
32/// Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo
33/// objects.
36 /// Convert diagnostics into remark objects.
37 /// The lifetime of the members of the result is bound to the lifetime of
38 /// the LLVM diagnostics.
39 remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag) const;
40
41public:
43 /// Emit a diagnostic through the streamer.
44 void emit(const DiagnosticInfoOptimizationBase &Diag);
45};
46
47template <typename ThisError>
48struct LLVMRemarkSetupErrorInfo : public ErrorInfo<ThisError> {
49 std::string Msg;
50 std::error_code EC;
51
53 handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
54 Msg = EIB.message();
55 EC = EIB.convertToErrorCode();
56 });
57 }
58
59 void log(raw_ostream &OS) const override { OS << Msg; }
60 std::error_code convertToErrorCode() const override { return EC; }
61};
62
64 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFileError> {
65 static char ID;
67 LLVMRemarkSetupFileError>::LLVMRemarkSetupErrorInfo;
68};
69
71 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupPatternError> {
72 static char ID;
74 LLVMRemarkSetupPatternError>::LLVMRemarkSetupErrorInfo;
75};
76
78 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFormatError> {
79 static char ID;
81 LLVMRemarkSetupFormatError>::LLVMRemarkSetupErrorInfo;
82};
83
84/// 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")
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:45
virtual std::string message() const
Return the error message as a string.
Definition: Error.h:53
virtual std::error_code convertToErrorCode() const =0
Convert this error to a std::error_code.
Base class for user error types.
Definition: Error.h:355
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo objects.
LLVMRemarkStreamer(remarks::RemarkStreamer &RS)
void emit(const DiagnosticInfoOptimizationBase &Diag)
Emit a diagnostic through the streamer.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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:977
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:97