From d138c45c40fa7fadafa5f1b9fd993785b0dc5e59 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Fri, 26 Aug 2016 15:58:34 +0000 Subject: [PATCH] [LoopUnroll] Use OptimizationRemarkEmitter directly not via the analysis pass We can't mark ORE (a function pass) preserved as required by the loop passes because that is how we ensure that the required passes like LazyBFI are all available any time ORE is used. See the new comments in the patch. Instead we use it directly just like the inliner does in D22694. As expected there is some additional overhead after removing the caching provided by analysis passes. The worst case, I measured was LNT/CINT2006_ref/401.bzip2 which regresses by 12%. As before, this only affects -Rpass-with-hotness and not default compilation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279829 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/OptimizationDiagnosticInfo.h | 5 +++++ lib/Transforms/Scalar/LoopUnrollPass.cpp | 5 ++++- lib/Transforms/Utils/LoopUtils.cpp | 4 ---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/llvm/Analysis/OptimizationDiagnosticInfo.h b/include/llvm/Analysis/OptimizationDiagnosticInfo.h index 0ba66aea2cf..2d0ff4e8c20 100644 --- a/include/llvm/Analysis/OptimizationDiagnosticInfo.h +++ b/include/llvm/Analysis/OptimizationDiagnosticInfo.h @@ -177,6 +177,11 @@ private: void operator=(const OptimizationRemarkEmitter &) = delete; }; +/// OptimizationRemarkEmitter legacy analysis pass +/// +/// Note that this pass shouldn't generally be marked as preserved by other +/// passes. It's holding onto BFI, so if the pass does not preserve BFI, BFI +/// could be freed. class OptimizationRemarkEmitterWrapperPass : public FunctionPass { std::unique_ptr ORE; diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp index 1018b61b330..1a8c626e6b5 100644 --- a/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -1018,7 +1018,10 @@ public: const TargetTransformInfo &TTI = getAnalysis().getTTI(F); auto &AC = getAnalysis().getAssumptionCache(F); - auto &ORE = getAnalysis().getORE(); + // For the old PM, we can't use OptimizationRemarkEmitter as an analysis + // pass. Function analyses need to be preserved across loop transformations + // but ORE cannot be preserved (see comment before the pass definition). + OptimizationRemarkEmitter ORE(&F); bool PreserveLCSSA = mustPreserveAnalysisID(LCSSAID); return tryToUnrollLoop(L, DT, LI, SE, TTI, AC, ORE, PreserveLCSSA, diff --git a/lib/Transforms/Utils/LoopUtils.cpp b/lib/Transforms/Utils/LoopUtils.cpp index 624db3ca7c6..88786899848 100644 --- a/lib/Transforms/Utils/LoopUtils.cpp +++ b/lib/Transforms/Utils/LoopUtils.cpp @@ -17,7 +17,6 @@ #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/GlobalsModRef.h" #include "llvm/Analysis/LoopInfo.h" -#include "llvm/Analysis/OptimizationDiagnosticInfo.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" #include "llvm/Analysis/ScalarEvolutionExpander.h" @@ -962,8 +961,6 @@ void llvm::getLoopAnalysisUsage(AnalysisUsage &AU) { AU.addPreserved(); AU.addRequired(); AU.addPreserved(); - AU.addRequired(); - AU.addPreserved(); } /// Manually defined generic "LoopPass" dependency initialization. This is used @@ -984,7 +981,6 @@ void llvm::initializeLoopPassPass(PassRegistry &Registry) { INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass) INITIALIZE_PASS_DEPENDENCY(SCEVAAWrapperPass) INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass) - INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass) } /// \brief Find string metadata for loop -- 2.11.0