]> granicus.if.org Git - llvm/commitdiff
[OptRemarkEmitter] Port to new PM
authorAdam Nemet <anemet@apple.com>
Mon, 18 Jul 2016 16:29:21 +0000 (16:29 +0000)
committerAdam Nemet <anemet@apple.com>
Mon, 18 Jul 2016 16:29:21 +0000 (16:29 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275810 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 04e49a78e26eed49e387930d0ccadf3428e1ada0..b455a6527bf661d56115bf347507fe661347ad0e 100644 (file)
@@ -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
index f8ec8586d7302b381d626dddfe891bb2d0340395..86ea80eeba10fc60f9615515c3dccae7b33545aa 100644 (file)
@@ -243,7 +243,7 @@ void initializeObjCARCAPElimPass(PassRegistry&);
 void initializeObjCARCContractPass(PassRegistry&);
 void initializeObjCARCExpandPass(PassRegistry&);
 void initializeObjCARCOptPass(PassRegistry&);
-void initializeOptimizationRemarkEmitterPass(PassRegistry&);
+void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry&);
 void initializeOptimizePHIsPass(PassRegistry&);
 void initializePAEvalPass(PassRegistry &);
 void initializePEIPass(PassRegistry&);
index 105a9fda3e2c4af92659d2c30529b20272074859..c04447ca58c99c4743b205b0015368fe64d0ab74 100644 (file)
@@ -64,7 +64,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
   initializeModuleDebugInfoPrinterPass(Registry);
   initializeModuleSummaryIndexWrapperPassPass(Registry);
   initializeObjCARCAAWrapperPassPass(Registry);
-  initializeOptimizationRemarkEmitterPass(Registry);
+  initializeOptimizationRemarkEmitterWrapperPassPass(Registry);
   initializePostDominatorTreeWrapperPassPass(Registry);
   initializeRegionInfoPassPass(Registry);
   initializeRegionViewerPass(Registry);
index 9a22633b6e4b464fa97692ee21a69ebb2855afc8..e979ba2531e4e08fdb1d7597b793f0125a0a9e0b 100644 (file)
 
 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::emitOptimizationRemarkMissed(
   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)
index d5162bf326a41f860e97a8d06404608b6309f53f..aa276be9d355af47a1220f6d921706ed321129c3 100644 (file)
@@ -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"
index cfe2dc5b6ab5c251d9d0baf8c1f02e7042e27aa3..96f6cb810bd9aa8db9e960c983fd5371eae89dcc 100644 (file)
@@ -101,6 +101,7 @@ FUNCTION_ANALYSIS("memdep", MemoryDependenceAnalysis())
 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",
index e09b33b29f7f7dbd1cdcb7fb7ef4388a8e7581c8..f1e0ec40530128b11c6693a2613152e41c072f32 100644 (file)
@@ -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(LoopInfoWrapperPass)
 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 {