mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
d0b74589e5
This is the #1 of 2 changes that make remarks hotness threshold option available in more tools. The changes also allow the threshold to sync with hotness threshold from profile summary with special value 'auto'. This change modifies the interface of lto::setupLLVMOptimizationRemarks() to accept remarks hotness threshold. Update all the tools that use it with remarks hotness threshold options: * lld: '--opt-remarks-hotness-threshold=' * llvm-lto2: '--pass-remarks-hotness-threshold=' * llvm-lto: '--lto-pass-remarks-hotness-threshold=' * gold plugin: '-plugin-opt=opt-remarks-hotness-threshold=' Differential Revision: https://reviews.llvm.org/D85809
95 lines
3.3 KiB
C++
95 lines
3.3 KiB
C++
//===- llvm/IR/LLVMRemarkStreamer.h - Streamer for LLVM remarks--*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the conversion between IR Diagnostics and
|
|
// serializable remarks::Remark objects.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_IR_LLVMREMARKSTREAMER_H
|
|
#define LLVM_IR_LLVMREMARKSTREAMER_H
|
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
|
#include "llvm/Remarks/RemarkStreamer.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include "llvm/Support/ToolOutputFile.h"
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
namespace llvm {
|
|
/// Streamer for LLVM remarks which has logic for dealing with DiagnosticInfo
|
|
/// objects.
|
|
class LLVMRemarkStreamer {
|
|
remarks::RemarkStreamer &RS;
|
|
/// Convert diagnostics into remark objects.
|
|
/// The lifetime of the members of the result is bound to the lifetime of
|
|
/// the LLVM diagnostics.
|
|
remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag) const;
|
|
|
|
public:
|
|
LLVMRemarkStreamer(remarks::RemarkStreamer &RS) : RS(RS) {}
|
|
/// Emit a diagnostic through the streamer.
|
|
void emit(const DiagnosticInfoOptimizationBase &Diag);
|
|
};
|
|
|
|
template <typename ThisError>
|
|
struct LLVMRemarkSetupErrorInfo : public ErrorInfo<ThisError> {
|
|
std::string Msg;
|
|
std::error_code EC;
|
|
|
|
LLVMRemarkSetupErrorInfo(Error E) {
|
|
handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
|
|
Msg = EIB.message();
|
|
EC = EIB.convertToErrorCode();
|
|
});
|
|
}
|
|
|
|
void log(raw_ostream &OS) const override { OS << Msg; }
|
|
std::error_code convertToErrorCode() const override { return EC; }
|
|
};
|
|
|
|
struct LLVMRemarkSetupFileError
|
|
: LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFileError> {
|
|
static char ID;
|
|
using LLVMRemarkSetupErrorInfo<
|
|
LLVMRemarkSetupFileError>::LLVMRemarkSetupErrorInfo;
|
|
};
|
|
|
|
struct LLVMRemarkSetupPatternError
|
|
: LLVMRemarkSetupErrorInfo<LLVMRemarkSetupPatternError> {
|
|
static char ID;
|
|
using LLVMRemarkSetupErrorInfo<
|
|
LLVMRemarkSetupPatternError>::LLVMRemarkSetupErrorInfo;
|
|
};
|
|
|
|
struct LLVMRemarkSetupFormatError
|
|
: LLVMRemarkSetupErrorInfo<LLVMRemarkSetupFormatError> {
|
|
static char ID;
|
|
using LLVMRemarkSetupErrorInfo<
|
|
LLVMRemarkSetupFormatError>::LLVMRemarkSetupErrorInfo;
|
|
};
|
|
|
|
/// Setup optimization remarks that output to a file.
|
|
Expected<std::unique_ptr<ToolOutputFile>>
|
|
setupLLVMOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
|
|
StringRef RemarksPasses, StringRef RemarksFormat,
|
|
bool RemarksWithHotness,
|
|
Optional<uint64_t> RemarksHotnessThreshold = 0);
|
|
|
|
/// Setup optimization remarks that output directly to a raw_ostream.
|
|
/// \p OS is managed by the caller and should be open for writing as long as \p
|
|
/// Context is streaming remarks to it.
|
|
Error setupLLVMOptimizationRemarks(
|
|
LLVMContext &Context, raw_ostream &OS, StringRef RemarksPasses,
|
|
StringRef RemarksFormat, bool RemarksWithHotness,
|
|
Optional<uint64_t> RemarksHotnessThreshold = 0);
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_IR_LLVMREMARKSTREAMER_H
|