summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAdam Nemet <anemet@apple.com>2016-09-27 23:47:03 +0000
committerAdam Nemet <anemet@apple.com>2016-09-27 23:47:03 +0000
commitc507ac96f5bf6a22890e9459e9cebe8ba81949cd (patch)
tree26d4569a37897a89ee61ab29805daf0d3e138b45 /llvm/lib
parent04279094343763f111cbc570d666dfeaf18389ed (diff)
downloadbcm5719-llvm-c507ac96f5bf6a22890e9459e9cebe8ba81949cd.tar.gz
bcm5719-llvm-c507ac96f5bf6a22890e9459e9cebe8ba81949cd.zip
[Inliner] Port all opt remarks to new streaming API
llvm-svn: 282559
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp8
-rw-r--r--llvm/lib/IR/DiagnosticInfo.cpp23
-rw-r--r--llvm/lib/Transforms/IPO/Inliner.cpp69
3 files changed, 65 insertions, 35 deletions
diff --git a/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp b/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp
index 5c0a81f60e5..181e375ad65 100644
--- a/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp
+++ b/llvm/lib/Analysis/OptimizationDiagnosticInfo.cpp
@@ -59,7 +59,13 @@ template <> struct MappingTraits<DiagnosticInfoOptimizationBase *> {
static void mapping(IO &io, DiagnosticInfoOptimizationBase *&OptDiag) {
assert(io.outputting() && "input not yet implemented");
- if (io.mapTag("!Missed", OptDiag->getKind() == DK_OptimizationRemarkMissed))
+ if (io.mapTag("!Passed", OptDiag->getKind() == DK_OptimizationRemark))
+ ;
+ else if (io.mapTag("!Missed",
+ OptDiag->getKind() == DK_OptimizationRemarkMissed))
+ ;
+ else if (io.mapTag("!Analysis",
+ OptDiag->getKind() == DK_OptimizationRemarkAnalysis))
;
else
llvm_unreachable("todo");
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp
index 181958a1f73..301a1d53fad 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -180,6 +180,13 @@ void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const {
DP << " (hotness: " << *Hotness << ")";
}
+OptimizationRemark::OptimizationRemark(const char *PassName,
+ StringRef RemarkName,
+ const DebugLoc &DLoc, Value *CodeRegion)
+ : DiagnosticInfoOptimizationBase(
+ DK_OptimizationRemark, DS_Remark, PassName, RemarkName,
+ *cast<BasicBlock>(CodeRegion)->getParent(), DLoc, CodeRegion) {}
+
bool OptimizationRemark::isEnabled() const {
return PassRemarksOptLoc.Pattern &&
PassRemarksOptLoc.Pattern->match(getPassName());
@@ -187,6 +194,14 @@ bool OptimizationRemark::isEnabled() const {
OptimizationRemarkMissed::OptimizationRemarkMissed(const char *PassName,
StringRef RemarkName,
+ const DebugLoc &DLoc,
+ Value *CodeRegion)
+ : DiagnosticInfoOptimizationBase(
+ DK_OptimizationRemarkMissed, DS_Remark, PassName, RemarkName,
+ *cast<BasicBlock>(CodeRegion)->getParent(), DLoc, CodeRegion) {}
+
+OptimizationRemarkMissed::OptimizationRemarkMissed(const char *PassName,
+ StringRef RemarkName,
Instruction *Inst)
: DiagnosticInfoOptimizationBase(DK_OptimizationRemarkMissed, DS_Remark,
PassName, RemarkName,
@@ -198,6 +213,14 @@ bool OptimizationRemarkMissed::isEnabled() const {
PassRemarksMissedOptLoc.Pattern->match(getPassName());
}
+OptimizationRemarkAnalysis::OptimizationRemarkAnalysis(const char *PassName,
+ StringRef RemarkName,
+ Instruction *Inst)
+ : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkAnalysis, DS_Remark,
+ PassName, RemarkName,
+ *Inst->getParent()->getParent(),
+ Inst->getDebugLoc(), Inst->getParent()) {}
+
bool OptimizationRemarkAnalysis::isEnabled() const {
return shouldAlwaysPrint() ||
(PassRemarksAnalysisOptLoc.Pattern &&
diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp
index 3ffb7544310..7aa1e187d31 100644
--- a/llvm/lib/Transforms/IPO/Inliner.cpp
+++ b/llvm/lib/Transforms/IPO/Inliner.cpp
@@ -255,11 +255,6 @@ static bool InlineCallIfPossible(
return true;
}
-static void emitAnalysis(CallSite CS, OptimizationRemarkEmitter &ORE,
- const Twine &Msg) {
- ORE.emitOptimizationRemarkAnalysis(DEBUG_TYPE, CS.getInstruction(), Msg);
-}
-
/// Return true if inlining of CS can block the caller from being
/// inlined which is proved to be more beneficial. \p IC is the
/// estimated inline cost associated with callsite \p CS.
@@ -341,21 +336,26 @@ shouldBeDeferred(Function *Caller, CallSite CS, InlineCost IC,
static bool shouldInline(CallSite CS,
function_ref<InlineCost(CallSite CS)> GetInlineCost,
OptimizationRemarkEmitter &ORE) {
+ using namespace ore;
InlineCost IC = GetInlineCost(CS);
+ Instruction *Call = CS.getInstruction();
+ Function *Callee = CS.getCalledFunction();
if (IC.isAlways()) {
DEBUG(dbgs() << " Inlining: cost=always"
<< ", Call: " << *CS.getInstruction() << "\n");
- emitAnalysis(CS, ORE, Twine(CS.getCalledFunction()->getName()) +
- " should always be inlined (cost=always)");
+ ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AlwaysInline", Call)
+ << NV("Callee", Callee)
+ << " should always be inlined (cost=always)");
return true;
}
if (IC.isNever()) {
DEBUG(dbgs() << " NOT Inlining: cost=never"
<< ", Call: " << *CS.getInstruction() << "\n");
- emitAnalysis(CS, ORE, Twine(CS.getCalledFunction()->getName() +
- " should never be inlined (cost=never)"));
+ ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "NeverInline", Call)
+ << NV("Callee", Callee)
+ << " should never be inlined (cost=never)");
return false;
}
@@ -364,10 +364,10 @@ static bool shouldInline(CallSite CS,
DEBUG(dbgs() << " NOT Inlining: cost=" << IC.getCost()
<< ", thres=" << (IC.getCostDelta() + IC.getCost())
<< ", Call: " << *CS.getInstruction() << "\n");
- emitAnalysis(CS, ORE, Twine(CS.getCalledFunction()->getName() +
- " too costly to inline (cost=") +
- Twine(IC.getCost()) + ", threshold=" +
- Twine(IC.getCostDelta() + IC.getCost()) + ")");
+ ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "TooCostly", Call)
+ << NV("Callee", Callee) << " too costly to inline (cost="
+ << NV("Cost", IC.getCost()) << ", threshold="
+ << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")");
return false;
}
@@ -376,22 +376,22 @@ static bool shouldInline(CallSite CS,
DEBUG(dbgs() << " NOT Inlining: " << *CS.getInstruction()
<< " Cost = " << IC.getCost()
<< ", outer Cost = " << TotalSecondaryCost << '\n');
- emitAnalysis(CS, ORE,
- Twine("Not inlining. Cost of inlining " +
- CS.getCalledFunction()->getName() +
- " increases the cost of inlining " +
- CS.getCaller()->getName() + " in other contexts"));
+ ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE,
+ "IncreaseCostInOtherContexts", Call)
+ << "Not inlining. Cost of inlining " << NV("Callee", Callee)
+ << " increases the cost of inlining " << NV("Caller", Caller)
+ << " in other contexts");
return false;
}
DEBUG(dbgs() << " Inlining: cost=" << IC.getCost()
<< ", thres=" << (IC.getCostDelta() + IC.getCost())
<< ", Call: " << *CS.getInstruction() << '\n');
- emitAnalysis(CS, ORE, CS.getCalledFunction()->getName() +
- Twine(" can be inlined into ") +
- CS.getCaller()->getName() + " with cost=" +
- Twine(IC.getCost()) + " (threshold=" +
- Twine(IC.getCostDelta() + IC.getCost()) + ")");
+ ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "CanBeInlined", Call)
+ << NV("Callee", Callee) << " can be inlined into "
+ << NV("Caller", Caller) << " with cost=" << NV("Cost", IC.getCost())
+ << " (threshold="
+ << NV("Threshold", IC.getCostDelta() + IC.getCost()) << ")");
return true;
}
@@ -550,11 +550,12 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
// If the policy determines that we should inline this function,
// try to do so.
+ using namespace ore;
if (!shouldInline(CS, GetInlineCost, ORE)) {
- ORE.emitOptimizationRemarkMissed(DEBUG_TYPE, DLoc, Block,
- Twine(Callee->getName() +
- " will not be inlined into " +
- Caller->getName()));
+ ORE.emit(
+ OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
+ << NV("Callee", Callee) << " will not be inlined into "
+ << NV("Caller", Caller));
continue;
}
@@ -562,18 +563,18 @@ inlineCallsImpl(CallGraphSCC &SCC, CallGraph &CG,
if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas,
InlineHistoryID, InsertLifetime, AARGetter,
ImportedFunctionsStats)) {
- ORE.emitOptimizationRemarkMissed(DEBUG_TYPE, DLoc, Block,
- Twine(Callee->getName() +
- " will not be inlined into " +
- Caller->getName()));
+ ORE.emit(
+ OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc, Block)
+ << NV("Callee", Callee) << " will not be inlined into "
+ << NV("Caller", Caller));
continue;
}
++NumInlined;
// Report the inline decision.
- ORE.emitOptimizationRemark(
- DEBUG_TYPE, DLoc, Block,
- Twine(Callee->getName() + " inlined into " + Caller->getName()));
+ ORE.emit(OptimizationRemark(DEBUG_TYPE, "Inlined", DLoc, Block)
+ << NV("Callee", Callee) << " inlined into "
+ << NV("Caller", Caller));
// If inlining this function gave us any new call sites, throw them
// onto our worklist to process. They are useful inline candidates.
OpenPOWER on IntegriCloud