| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 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 <string> |
| 21 |
|
| 22 |
namespace llvm { |
| 23 |
|
| 24 |
class DiagnosticInfoOptimizationBase; |
| 25 |
class LLVMContext; |
| 26 |
class ToolOutputFile; |
| 27 |
namespace remarks { |
| 28 |
class RemarkStreamer; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class LLVMRemarkStreamer { |
| 34 |
remarks::RemarkStreamer &RS; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag) const; |
| 39 |
|
| 40 |
public: |
| 41 |
LLVMRemarkStreamer(remarks::RemarkStreamer &RS) : RS(RS) {} |
| 42 |
|
| 43 |
void emit(const DiagnosticInfoOptimizationBase &Diag); |
| 44 |
}; |
| 45 |
|
| 46 |
template <typename ThisError> |
| 47 |
struct LLVMRemarkSetupErrorInfo : public ErrorInfo<ThisError> { |
| 48 |
std::string Msg; |
| 49 |
std::error_code EC; |
| 50 |
|
| 51 |
LLVMRemarkSetupErrorInfo(Error E) { |
| 52 |
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) { |
| 53 |
Msg = EIB.message(); |
| 54 |
EC = EIB.convertToErrorCode(); |
| 55 |
}); |
| 56 |
} |
| 57 |
|
| 58 |
void log(raw_ostream &OS) const override { OS << Msg; } |
| 59 |
std::error_code convertToErrorCode() const override { return EC; } |
| 60 |
}; |
| 61 |
|
| 62 |
struct LLVMRemarkSetupFileError |
| 63 |
: LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFileError> { |
| 64 |
static char ID; |
| 65 |
using LLVMRemarkSetupErrorInfo< |
| 66 |
LLVMRemarkSetupFileError>::LLVMRemarkSetupErrorInfo; |
| 67 |
}; |
| 68 |
|
| 69 |
struct LLVMRemarkSetupPatternError |
| 70 |
: LLVMRemarkSetupErrorInfo<LLVMRemarkSetupPatternError> { |
| 71 |
static char ID; |
| 72 |
using LLVMRemarkSetupErrorInfo< |
| 73 |
LLVMRemarkSetupPatternError>::LLVMRemarkSetupErrorInfo; |
| 74 |
}; |
| 75 |
|
| 76 |
struct LLVMRemarkSetupFormatError |
| 77 |
: LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFormatError> { |
| 78 |
static char ID; |
| 79 |
using LLVMRemarkSetupErrorInfo< |
| 80 |
LLVMRemarkSetupFormatError>::LLVMRemarkSetupErrorInfo; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
Expected<std::unique_ptr<ToolOutputFile>> |
| 85 |
setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename, |
| 86 |
StringRef RemarksPasses, StringRef RemarksFormat, |
| 87 |
bool RemarksWithHotness, |
| 88 |
Optional<uint64_t> RemarksHotnessThreshold = 0); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
Error setupLLVMOptimizationRemarks( |
| 94 |
LLVMContext &Context, raw_ostream &OS, StringRef RemarksPasses, |
| 95 |
StringRef RemarksFormat, bool RemarksWithHotness, |
| 96 |
Optional<uint64_t> RemarksHotnessThreshold = 0); |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
#endif |