diff options
author | Kirill Naumov <knaumov@azul.com> | 2020-06-11 22:24:10 +0000 |
---|---|---|
committer | Kirill Naumov <knaumov@azul.com> | 2020-06-24 21:27:07 +0000 |
commit | 6a5d7d498c0b16b13ace802f422b223eb510c303 (patch) | |
tree | 3afb3b6da3bee397cd01ab676870bf0ef0d42a11 /llvm/lib/Analysis/InlineCost.cpp | |
parent | a61c73dbe320f1caf9940717090548df8ee30f8b (diff) | |
download | llvm-6a5d7d498c0b16b13ace802f422b223eb510c303.zip llvm-6a5d7d498c0b16b13ace802f422b223eb510c303.tar.gz llvm-6a5d7d498c0b16b13ace802f422b223eb510c303.tar.bz2 |
[InlineCost] InlineCostAnnotationWriterPass introduced
This class allows to see the inliner's decisions for better
optimization verifications and tests. To use, use flag
"-passes="print<inline-cost>"".
This is the second attempt to integrate the patch.
The problem from the first try has been discussed and
fixed in D82205.
Reviewers: apilipenko, mtrofin, davidxl, fedor.sergeev
Reviewed By: mtrofin
Differential revision: https://reviews.llvm.org/D81743
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index cb57011..5054427 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -2518,3 +2518,40 @@ InlineParams llvm::getInlineParams(unsigned OptLevel, unsigned SizeOptLevel) { Params.LocallyHotCallSiteThreshold = LocallyHotCallSiteThreshold; return Params; } + +PreservedAnalyses +InlineCostAnnotationPrinterPass::run(Function &F, + FunctionAnalysisManager &FAM) { + PrintInstructionComments = true; + std::function<AssumptionCache &(Function &)> GetAssumptionCache = [&]( + Function &F) -> AssumptionCache & { + return FAM.getResult<AssumptionAnalysis>(F); + }; + Module *M = F.getParent(); + ProfileSummaryInfo PSI(*M); + DataLayout DL(M); + TargetTransformInfo TTI(DL); + // FIXME: Redesign the usage of InlineParams to expand the scope of this pass. + // In the current implementation, the type of InlineParams doesn't matter as + // the pass serves only for verification of inliner's decisions. + // We can add a flag which determines InlineParams for this run. Right now, + // the default InlineParams are used. + const InlineParams Params = llvm::getInlineParams(); + for (BasicBlock &BB : F) { + for (Instruction &I : BB) { + if (CallInst *CI = dyn_cast<CallInst>(&I)) { + Function *CalledFunction = CI->getCalledFunction(); + if (!CalledFunction || CalledFunction->isDeclaration()) + continue; + OptimizationRemarkEmitter ORE(CalledFunction); + InlineCostCallAnalyzer ICCA(*CalledFunction, *CI, Params, TTI, + GetAssumptionCache, nullptr, &PSI, &ORE); + ICCA.analyze(); + OS << " Analyzing call of " << CalledFunction->getName() + << "... (caller:" << CI->getCaller()->getName() << ")\n"; + ICCA.print(); + } + } + } + return PreservedAnalyses::all(); +} |