[llvm] r275810 - [OptRemarkEmitter] Port to new PM

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 09:29:21 PDT 2016


Author: anemet
Date: Mon Jul 18 11:29:21 2016
New Revision: 275810

URL: http://llvm.org/viewvc/llvm-project?rev=275810&view=rev
Log:
[OptRemarkEmitter] Port to new PM

Summary:
The main goal is to able to start using the new OptRemarkEmitter
analysis from the LoopVectorizer.  Since the vectorizer was recently
converted to the new PM, it makes sense to convert this analysis as
well.

This pass is currently tested through the LoopDistribution pass, so I am
also porting LoopDistribution to get coverage for this analysis with the
new PM.

Reviewers: davidxl, silvas

Subscribers: llvm-commits, mzolotukhin

Differential Revision: https://reviews.llvm.org/D22436

Modified:
    llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h
    llvm/trunk/include/llvm/InitializePasses.h
    llvm/trunk/lib/Analysis/Analysis.cpp
    llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
    llvm/trunk/lib/Passes/PassBuilder.cpp
    llvm/trunk/lib/Passes/PassRegistry.def
    llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp

Modified: llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h?rev=275810&r1=275809&r2=275810&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/OptimizationDiagnosticInfo.h Mon Jul 18 11:29:21 2016
@@ -16,6 +16,7 @@
 #define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
 
 #include "llvm/ADT/Optional.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 
 namespace llvm {
@@ -28,9 +29,19 @@ class Pass;
 class Twine;
 class Value;
 
-class OptimizationRemarkEmitter : public FunctionPass {
+class OptimizationRemarkEmitter {
 public:
-  OptimizationRemarkEmitter();
+  OptimizationRemarkEmitter(Function *F, BlockFrequencyInfo *BFI)
+      : F(F), BFI(BFI) {}
+
+  OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg)
+      : F(Arg.F), BFI(Arg.BFI) {}
+
+  OptimizationRemarkEmitter &operator=(OptimizationRemarkEmitter &&RHS) {
+    F = RHS.F;
+    BFI = RHS.BFI;
+    return *this;
+  }
 
   /// Emit an optimization-missed message.
   ///
@@ -48,19 +59,46 @@ public:
   void emitOptimizationRemarkMissed(const char *PassName, Loop *L,
                                     const Twine &Msg);
 
+private:
+  Function *F;
+
+  BlockFrequencyInfo *BFI;
+
+  Optional<uint64_t> computeHotness(Value *V);
+
+  OptimizationRemarkEmitter(const OptimizationRemarkEmitter &) = delete;
+  void operator=(const OptimizationRemarkEmitter &) = delete;
+};
+
+class OptimizationRemarkEmitterWrapperPass : public FunctionPass {
+  std::unique_ptr<OptimizationRemarkEmitter> ORE;
+
+public:
+  OptimizationRemarkEmitterWrapperPass();
+
   bool runOnFunction(Function &F) override;
 
   void getAnalysisUsage(AnalysisUsage &AU) const override;
 
+  OptimizationRemarkEmitter &getORE() {
+    assert(ORE && "pass not run yet");
+    return *ORE;
+  }
+
   static char ID;
+};
 
-private:
-  Function *F;
+class OptimizationRemarkEmitterAnalysis
+    : public AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis> {
+  friend AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis>;
+  static char PassID;
 
-  BlockFrequencyInfo *BFI;
+public:
+  /// \brief Provide the result typedef for this analysis pass.
+  typedef OptimizationRemarkEmitter Result;
 
-  Optional<uint64_t> computeHotness(Value *V);
+  /// \brief Run the analysis pass over a function and produce BFI.
+  Result run(Function &F, AnalysisManager<Function> &AM);
 };
 }
-
 #endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H

Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=275810&r1=275809&r2=275810&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Mon Jul 18 11:29:21 2016
@@ -243,7 +243,7 @@ void initializeObjCARCAPElimPass(PassReg
 void initializeObjCARCContractPass(PassRegistry&);
 void initializeObjCARCExpandPass(PassRegistry&);
 void initializeObjCARCOptPass(PassRegistry&);
-void initializeOptimizationRemarkEmitterPass(PassRegistry&);
+void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry&);
 void initializeOptimizePHIsPass(PassRegistry&);
 void initializePAEvalPass(PassRegistry &);
 void initializePEIPass(PassRegistry&);

Modified: llvm/trunk/lib/Analysis/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Analysis.cpp?rev=275810&r1=275809&r2=275810&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Analysis.cpp (original)
+++ llvm/trunk/lib/Analysis/Analysis.cpp Mon Jul 18 11:29:21 2016
@@ -64,7 +64,7 @@ void llvm::initializeAnalysis(PassRegist
   initializeModuleDebugInfoPrinterPass(Registry);
   initializeModuleSummaryIndexWrapperPassPass(Registry);
   initializeObjCARCAAWrapperPassPass(Registry);
-  initializeOptimizationRemarkEmitterPass(Registry);
+  initializeOptimizationRemarkEmitterWrapperPassPass(Registry);
   initializePostDominatorTreeWrapperPassPass(Registry);
   initializeRegionInfoPassPass(Registry);
   initializeRegionViewerPass(Registry);

Modified: llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp?rev=275810&r1=275809&r2=275810&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp Mon Jul 18 11:29:21 2016
@@ -20,10 +20,6 @@
 
 using namespace llvm;
 
-OptimizationRemarkEmitter::OptimizationRemarkEmitter() : FunctionPass(ID) {
-  initializeOptimizationRemarkEmitterPass(*PassRegistry::getPassRegistry());
-}
-
 Optional<uint64_t> OptimizationRemarkEmitter::computeHotness(Value *V) {
   if (!BFI)
     return None;
@@ -43,27 +39,50 @@ void OptimizationRemarkEmitter::emitOpti
   emitOptimizationRemarkMissed(PassName, L->getStartLoc(), L->getHeader(), Msg);
 }
 
-bool OptimizationRemarkEmitter::runOnFunction(Function &Fn) {
-  F = &Fn;
+OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
+    : FunctionPass(ID) {
+  initializeOptimizationRemarkEmitterWrapperPassPass(
+      *PassRegistry::getPassRegistry());
+}
+
+bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
+  BlockFrequencyInfo *BFI;
 
   if (Fn.getContext().getDiagnosticHotnessRequested())
     BFI = &getAnalysis<LazyBlockFrequencyInfoPass>().getBFI();
   else
     BFI = nullptr;
 
+  ORE = llvm::make_unique<OptimizationRemarkEmitter>(&Fn, BFI);
   return false;
 }
 
-void OptimizationRemarkEmitter::getAnalysisUsage(AnalysisUsage &AU) const {
+void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
+    AnalysisUsage &AU) const {
   LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
   AU.setPreservesAll();
 }
 
-char OptimizationRemarkEmitter::ID = 0;
+char OptimizationRemarkEmitterAnalysis::PassID;
+
+OptimizationRemarkEmitter
+OptimizationRemarkEmitterAnalysis::run(Function &F, AnalysisManager<Function> &AM) {
+  BlockFrequencyInfo *BFI;
+
+  if (F.getContext().getDiagnosticHotnessRequested())
+    BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
+  else
+    BFI = nullptr;
+
+  return OptimizationRemarkEmitter(&F, BFI);
+}
+
+char OptimizationRemarkEmitterWrapperPass::ID = 0;
 static const char ore_name[] = "Optimization Remark Emitter";
 #define ORE_NAME "opt-remark-emitter"
 
-INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitter, ORE_NAME, ore_name, false,
-                      true)
+INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
+                      false, true)
 INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
-INITIALIZE_PASS_END(OptimizationRemarkEmitter, ORE_NAME, ore_name, false, true)
+INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
+                    false, true)

Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=275810&r1=275809&r2=275810&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Mon Jul 18 11:29:21 2016
@@ -38,6 +38,7 @@
 #include "llvm/Analysis/LoopAccessAnalysis.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
+#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"
 #include "llvm/Analysis/RegionInfo.h"

Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=275810&r1=275809&r2=275810&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Mon Jul 18 11:29:21 2016
@@ -101,6 +101,7 @@ FUNCTION_ANALYSIS("memdep", MemoryDepend
 FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis())
 FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
 FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
+FUNCTION_ANALYSIS("opt-remark-emit", OptimizationRemarkEmitterAnalysis())
 FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
 FUNCTION_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())
 FUNCTION_ANALYSIS("targetir",

Modified: llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp?rev=275810&r1=275809&r2=275810&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp Mon Jul 18 11:29:21 2016
@@ -883,7 +883,7 @@ public:
     auto *LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
     auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
     auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
-    auto *ORE = &getAnalysis<OptimizationRemarkEmitter>();
+    auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
 
     // Build up a worklist of inner-loops to vectorize. This is necessary as the
     // act of distributing a loop creates new loops and can invalidate iterators
@@ -918,7 +918,7 @@ public:
     AU.addRequired<LoopAccessLegacyAnalysis>();
     AU.addRequired<DominatorTreeWrapperPass>();
     AU.addPreserved<DominatorTreeWrapperPass>();
-    AU.addRequired<OptimizationRemarkEmitter>();
+    AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
   }
 
   static char ID;
@@ -938,7 +938,7 @@ INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapp
 INITIALIZE_PASS_DEPENDENCY(LoopAccessLegacyAnalysis)
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitter)
+INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
 INITIALIZE_PASS_END(LoopDistribute, LDIST_NAME, ldist_name, false, false)
 
 namespace llvm {




More information about the llvm-commits mailing list