2016-07-16 01:23:20 +08:00
|
|
|
//===- OptimizationDiagnosticInfo.cpp - Optimization Diagnostic -*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Optimization diagnostic interfaces. It's packaged as an analysis pass so
|
|
|
|
// that by using this service passes become dependent on BFI as well. BFI is
|
|
|
|
// used to compute the "hotness" of the diagnostic message.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
|
|
|
|
#include "llvm/Analysis/LazyBlockFrequencyInfo.h"
|
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/IR/DiagnosticInfo.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2016-07-21 05:44:22 +08:00
|
|
|
Optional<uint64_t> OptimizationRemarkEmitter::computeHotness(const Value *V) {
|
2016-07-16 01:23:20 +08:00
|
|
|
if (!BFI)
|
|
|
|
return None;
|
|
|
|
|
|
|
|
return BFI->getBlockProfileCount(cast<BasicBlock>(V));
|
|
|
|
}
|
|
|
|
|
2016-07-21 09:07:13 +08:00
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName,
|
|
|
|
const DebugLoc &DLoc,
|
|
|
|
const Value *V,
|
|
|
|
const Twine &Msg) {
|
|
|
|
LLVMContext &Ctx = F->getContext();
|
|
|
|
Ctx.diagnose(DiagnosticInfoOptimizationRemark(PassName, *F, DLoc, Msg,
|
|
|
|
computeHotness(V)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemark(const char *PassName,
|
|
|
|
Loop *L,
|
|
|
|
const Twine &Msg) {
|
|
|
|
emitOptimizationRemark(PassName, L->getStartLoc(), L->getHeader(), Msg);
|
|
|
|
}
|
|
|
|
|
2016-07-16 01:23:20 +08:00
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemarkMissed(
|
2016-07-21 05:44:22 +08:00
|
|
|
const char *PassName, const DebugLoc &DLoc, const Value *V,
|
|
|
|
const Twine &Msg) {
|
2016-07-16 01:23:20 +08:00
|
|
|
LLVMContext &Ctx = F->getContext();
|
|
|
|
Ctx.diagnose(DiagnosticInfoOptimizationRemarkMissed(PassName, *F, DLoc, Msg,
|
|
|
|
computeHotness(V)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemarkMissed(
|
|
|
|
const char *PassName, Loop *L, const Twine &Msg) {
|
|
|
|
emitOptimizationRemarkMissed(PassName, L->getStartLoc(), L->getHeader(), Msg);
|
|
|
|
}
|
|
|
|
|
2016-07-21 05:44:26 +08:00
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysis(
|
|
|
|
const char *PassName, const DebugLoc &DLoc, const Value *V,
|
|
|
|
const Twine &Msg) {
|
|
|
|
LLVMContext &Ctx = F->getContext();
|
|
|
|
Ctx.diagnose(DiagnosticInfoOptimizationRemarkAnalysis(PassName, *F, DLoc, Msg,
|
|
|
|
computeHotness(V)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysis(
|
|
|
|
const char *PassName, Loop *L, const Twine &Msg) {
|
|
|
|
emitOptimizationRemarkAnalysis(PassName, L->getStartLoc(), L->getHeader(),
|
|
|
|
Msg);
|
|
|
|
}
|
|
|
|
|
2016-07-21 07:50:32 +08:00
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisFPCommute(
|
2016-07-21 09:11:12 +08:00
|
|
|
const char *PassName, const DebugLoc &DLoc, const Value *V,
|
|
|
|
const Twine &Msg) {
|
2016-07-21 07:50:32 +08:00
|
|
|
LLVMContext &Ctx = F->getContext();
|
|
|
|
Ctx.diagnose(DiagnosticInfoOptimizationRemarkAnalysisFPCommute(
|
|
|
|
PassName, *F, DLoc, Msg, computeHotness(V)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisAliasing(
|
2016-07-21 09:11:12 +08:00
|
|
|
const char *PassName, const DebugLoc &DLoc, const Value *V,
|
|
|
|
const Twine &Msg) {
|
2016-07-21 07:50:32 +08:00
|
|
|
LLVMContext &Ctx = F->getContext();
|
|
|
|
Ctx.diagnose(DiagnosticInfoOptimizationRemarkAnalysisAliasing(
|
|
|
|
PassName, *F, DLoc, Msg, computeHotness(V)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptimizationRemarkEmitter::emitOptimizationRemarkAnalysisAliasing(
|
|
|
|
const char *PassName, Loop *L, const Twine &Msg) {
|
|
|
|
emitOptimizationRemarkAnalysisAliasing(PassName, L->getStartLoc(),
|
|
|
|
L->getHeader(), Msg);
|
|
|
|
}
|
|
|
|
|
2016-07-19 00:29:21 +08:00
|
|
|
OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
|
|
|
|
: FunctionPass(ID) {
|
|
|
|
initializeOptimizationRemarkEmitterWrapperPassPass(
|
|
|
|
*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
|
|
|
|
BlockFrequencyInfo *BFI;
|
2016-07-16 01:23:20 +08:00
|
|
|
|
|
|
|
if (Fn.getContext().getDiagnosticHotnessRequested())
|
|
|
|
BFI = &getAnalysis<LazyBlockFrequencyInfoPass>().getBFI();
|
|
|
|
else
|
|
|
|
BFI = nullptr;
|
|
|
|
|
2016-07-19 00:29:21 +08:00
|
|
|
ORE = llvm::make_unique<OptimizationRemarkEmitter>(&Fn, BFI);
|
2016-07-16 01:23:20 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-19 00:29:21 +08:00
|
|
|
void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
|
|
|
|
AnalysisUsage &AU) const {
|
2016-07-16 01:23:20 +08:00
|
|
|
LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
|
2016-07-19 00:29:21 +08:00
|
|
|
char OptimizationRemarkEmitterAnalysis::PassID;
|
|
|
|
|
|
|
|
OptimizationRemarkEmitter
|
2016-07-21 05:44:18 +08:00
|
|
|
OptimizationRemarkEmitterAnalysis::run(Function &F,
|
|
|
|
AnalysisManager<Function> &AM) {
|
2016-07-19 00:29:21 +08:00
|
|
|
BlockFrequencyInfo *BFI;
|
|
|
|
|
|
|
|
if (F.getContext().getDiagnosticHotnessRequested())
|
|
|
|
BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
|
|
|
|
else
|
|
|
|
BFI = nullptr;
|
|
|
|
|
|
|
|
return OptimizationRemarkEmitter(&F, BFI);
|
|
|
|
}
|
|
|
|
|
|
|
|
char OptimizationRemarkEmitterWrapperPass::ID = 0;
|
2016-07-16 01:23:20 +08:00
|
|
|
static const char ore_name[] = "Optimization Remark Emitter";
|
|
|
|
#define ORE_NAME "opt-remark-emitter"
|
|
|
|
|
2016-07-19 00:29:21 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
|
|
|
|
false, true)
|
2016-07-16 01:23:20 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
|
2016-07-19 00:29:21 +08:00
|
|
|
INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
|
|
|
|
false, true)
|