Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:07

0001 //===- llvm/IR/LLVMRemarkStreamer.h - Streamer for LLVM remarks--*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements the conversion between IR Diagnostics and
0010 // serializable remarks::Remark objects.
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 /// Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo
0033 /// objects.
0034 class LLVMRemarkStreamer {
0035   remarks::RemarkStreamer &RS;
0036   /// Convert diagnostics into remark objects.
0037   /// The lifetime of the members of the result is bound to the lifetime of
0038   /// the LLVM diagnostics.
0039   remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag) const;
0040 
0041 public:
0042   LLVMRemarkStreamer(remarks::RemarkStreamer &RS) : RS(RS) {}
0043   /// Emit a diagnostic through the streamer.
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 /// Setup optimization remarks that output to a file.
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 /// Setup optimization remarks that output directly to a raw_ostream.
0092 /// \p OS is managed by the caller and should be open for writing as long as \p
0093 /// Context is streaming remarks to it.
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 } // end namespace llvm
0100 
0101 #endif // LLVM_IR_LLVMREMARKSTREAMER_H