File indexing completed on 2026-05-10 08:44:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_IR_LLVMREMARKSTREAMER_H
0015 #define LLVM_IR_LLVMREMARKSTREAMER_H
0016
0017 #include "llvm/Remarks/Remark.h"
0018 #include "llvm/Support/Error.h"
0019 #include <memory>
0020 #include <optional>
0021 #include <string>
0022
0023 namespace llvm {
0024
0025 class DiagnosticInfoOptimizationBase;
0026 class LLVMContext;
0027 class ToolOutputFile;
0028 namespace remarks {
0029 class RemarkStreamer;
0030 }
0031
0032
0033
0034 class LLVMRemarkStreamer {
0035 remarks::RemarkStreamer &RS;
0036
0037
0038
0039 remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag) const;
0040
0041 public:
0042 LLVMRemarkStreamer(remarks::RemarkStreamer &RS) : RS(RS) {}
0043
0044 void emit(const DiagnosticInfoOptimizationBase &Diag);
0045 };
0046
0047 template <typename ThisError>
0048 struct LLVMRemarkSetupErrorInfo : public ErrorInfo<ThisError> {
0049 std::string Msg;
0050 std::error_code EC;
0051
0052 LLVMRemarkSetupErrorInfo(Error E) {
0053 handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
0054 Msg = EIB.message();
0055 EC = EIB.convertToErrorCode();
0056 });
0057 }
0058
0059 void log(raw_ostream &OS) const override { OS << Msg; }
0060 std::error_code convertToErrorCode() const override { return EC; }
0061 };
0062
0063 struct LLVMRemarkSetupFileError
0064 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFileError> {
0065 static char ID;
0066 using LLVMRemarkSetupErrorInfo<
0067 LLVMRemarkSetupFileError>::LLVMRemarkSetupErrorInfo;
0068 };
0069
0070 struct LLVMRemarkSetupPatternError
0071 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupPatternError> {
0072 static char ID;
0073 using LLVMRemarkSetupErrorInfo<
0074 LLVMRemarkSetupPatternError>::LLVMRemarkSetupErrorInfo;
0075 };
0076
0077 struct LLVMRemarkSetupFormatError
0078 : LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFormatError> {
0079 static char ID;
0080 using LLVMRemarkSetupErrorInfo<
0081 LLVMRemarkSetupFormatError>::LLVMRemarkSetupErrorInfo;
0082 };
0083
0084
0085 Expected<std::unique_ptr<ToolOutputFile>>
0086 setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
0087 StringRef RemarksPasses, StringRef RemarksFormat,
0088 bool RemarksWithHotness,
0089 std::optional<uint64_t> RemarksHotnessThreshold = 0);
0090
0091
0092
0093
0094 Error setupLLVMOptimizationRemarks(
0095 LLVMContext &Context, raw_ostream &OS, StringRef RemarksPasses,
0096 StringRef RemarksFormat, bool RemarksWithHotness,
0097 std::optional<uint64_t> RemarksHotnessThreshold = 0);
0098
0099 }
0100
0101 #endif