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 |
16 | |
17 | #include "llvm/Remarks/Remark.h" |
18 | #include "llvm/Support/Error.h" |
19 | #include <memory> |
20 | #include <optional> |
21 | #include <string> |
22 | |
23 | namespace llvm { |
24 | |
25 | class DiagnosticInfoOptimizationBase; |
26 | class LLVMContext; |
27 | class ToolOutputFile; |
28 | namespace remarks { |
29 | class ; |
30 | } |
31 | |
32 | /// Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo |
33 | /// objects. |
34 | class { |
35 | remarks::RemarkStreamer &; |
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 (const DiagnosticInfoOptimizationBase &Diag) const; |
40 | |
41 | public: |
42 | (remarks::RemarkStreamer &RS) : RS(RS) {} |
43 | /// Emit a diagnostic through the streamer. |
44 | void (const DiagnosticInfoOptimizationBase &Diag); |
45 | }; |
46 | |
47 | template <typename ThisError> |
48 | struct : public ErrorInfo<ThisError> { |
49 | std::string ; |
50 | std::error_code ; |
51 | |
52 | (Error E) { |
53 | handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) { |
54 | Msg = EIB.message(); |
55 | EC = EIB.convertToErrorCode(); |
56 | }); |
57 | } |
58 | |
59 | void (raw_ostream &OS) const override { OS << Msg; } |
60 | std::error_code () const override { return EC; } |
61 | }; |
62 | |
63 | struct |
64 | : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFileError> { |
65 | static char ; |
66 | using LLVMRemarkSetupErrorInfo< |
67 | LLVMRemarkSetupFileError>::LLVMRemarkSetupErrorInfo; |
68 | }; |
69 | |
70 | struct |
71 | : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupPatternError> { |
72 | static char ; |
73 | using LLVMRemarkSetupErrorInfo< |
74 | LLVMRemarkSetupPatternError>::LLVMRemarkSetupErrorInfo; |
75 | }; |
76 | |
77 | struct |
78 | : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFormatError> { |
79 | static char ; |
80 | using LLVMRemarkSetupErrorInfo< |
81 | LLVMRemarkSetupFormatError>::LLVMRemarkSetupErrorInfo; |
82 | }; |
83 | |
84 | /// Setup optimization remarks that output to a file. |
85 | Expected<std::unique_ptr<ToolOutputFile>> |
86 | (LLVMContext &Context, StringRef , |
87 | StringRef , StringRef , |
88 | bool , |
89 | std::optional<uint64_t> = 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. |
94 | Error ( |
95 | LLVMContext &Context, raw_ostream &OS, StringRef , |
96 | StringRef , bool , |
97 | std::optional<uint64_t> = 0); |
98 | |
99 | } // end namespace llvm |
100 | |
101 | #endif // LLVM_IR_LLVMREMARKSTREAMER_H |
102 | |