diff options
Diffstat (limited to 'llvm/lib/Transforms/Coroutines/CoroElide.cpp')
-rw-r--r-- | llvm/lib/Transforms/Coroutines/CoroElide.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Coroutines/CoroElide.cpp b/llvm/lib/Transforms/Coroutines/CoroElide.cpp index f032c568449b..d78ab1c1ea28 100644 --- a/llvm/lib/Transforms/Coroutines/CoroElide.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroElide.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/InstructionSimplify.h" +#include "llvm/Analysis/OptimizationRemarkEmitter.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/InstIterator.h" #include "llvm/Support/ErrorHandling.h" @@ -46,7 +47,8 @@ struct Lowerer : coro::LowererBase { AAResults &AA); bool shouldElide(Function *F, DominatorTree &DT) const; void collectPostSplitCoroIds(Function *F); - bool processCoroId(CoroIdInst *, AAResults &AA, DominatorTree &DT); + bool processCoroId(CoroIdInst *, AAResults &AA, DominatorTree &DT, + OptimizationRemarkEmitter &ORE); bool hasEscapePath(const CoroBeginInst *, const SmallPtrSetImpl<BasicBlock *> &) const; }; @@ -299,7 +301,7 @@ void Lowerer::collectPostSplitCoroIds(Function *F) { } bool Lowerer::processCoroId(CoroIdInst *CoroId, AAResults &AA, - DominatorTree &DT) { + DominatorTree &DT, OptimizationRemarkEmitter &ORE) { CoroBegins.clear(); CoroAllocs.clear(); ResumeAddr.clear(); @@ -343,6 +345,24 @@ bool Lowerer::processCoroId(CoroIdInst *CoroId, AAResults &AA, replaceWithConstant(ResumeAddrConstant, ResumeAddr); bool ShouldElide = shouldElide(CoroId->getFunction(), DT); + if (!ShouldElide) + ORE.emit([&]() { + if (auto FrameSizeAndAlign = + getFrameLayout(cast<Function>(ResumeAddrConstant))) + return OptimizationRemarkMissed(DEBUG_TYPE, "CoroElide", CoroId) + << "'" << ore::NV("callee", CoroId->getCoroutine()->getName()) + << "' not elided in '" + << ore::NV("caller", CoroId->getFunction()->getName()) + << "' (frame_size=" + << ore::NV("frame_size", FrameSizeAndAlign->first) << ", align=" + << ore::NV("align", FrameSizeAndAlign->second.value()) << ")"; + else + return OptimizationRemarkMissed(DEBUG_TYPE, "CoroElide", CoroId) + << "'" << ore::NV("callee", CoroId->getCoroutine()->getName()) + << "' not elided in '" + << ore::NV("caller", CoroId->getFunction()->getName()) + << "' (frame_size=unknown, align=unknown)"; + }); auto *DestroyAddrConstant = Resumers->getAggregateElement( ShouldElide ? CoroSubFnInst::CleanupIndex : CoroSubFnInst::DestroyIndex); @@ -363,6 +383,23 @@ bool Lowerer::processCoroId(CoroIdInst *CoroId, AAResults &AA, << "Elide " << CoroId->getCoroutine()->getName() << " in " << CoroId->getFunction()->getName() << "\n"; #endif + ORE.emit([&]() { + return OptimizationRemark(DEBUG_TYPE, "CoroElide", CoroId) + << "'" << ore::NV("callee", CoroId->getCoroutine()->getName()) + << "' elided in '" + << ore::NV("caller", CoroId->getFunction()->getName()) + << "' (frame_size=" + << ore::NV("frame_size", FrameSizeAndAlign->first) << ", align=" + << ore::NV("align", FrameSizeAndAlign->second.value()) << ")"; + }); + } else { + ORE.emit([&]() { + return OptimizationRemarkMissed(DEBUG_TYPE, "CoroElide", CoroId) + << "'" << ore::NV("callee", CoroId->getCoroutine()->getName()) + << "' not elided in '" + << ore::NV("caller", CoroId->getFunction()->getName()) + << "' (frame_size=unknown, align=unknown)"; + }); } } @@ -387,10 +424,11 @@ PreservedAnalyses CoroElidePass::run(Function &F, FunctionAnalysisManager &AM) { AAResults &AA = AM.getResult<AAManager>(F); DominatorTree &DT = AM.getResult<DominatorTreeAnalysis>(F); + auto &ORE = AM.getResult<OptimizationRemarkEmitterAnalysis>(F); bool Changed = false; for (auto *CII : L.CoroIds) - Changed |= L.processCoroId(CII, AA, DT); + Changed |= L.processCoroId(CII, AA, DT, ORE); return Changed ? PreservedAnalyses::none() : PreservedAnalyses::all(); } |