[llvm] r278508 - [PM] Port ModuleSummaryIndex analysis to new pass manager

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 06:53:02 PDT 2016


Author: tejohnson
Date: Fri Aug 12 08:53:02 2016
New Revision: 278508

URL: http://llvm.org/viewvc/llvm-project?rev=278508&view=rev
Log:
[PM] Port ModuleSummaryIndex analysis to new pass manager

Summary:
Port the ModuleSummaryAnalysisWrapperPass to the new pass manager.
Use it in the ported BitcodeWriterPass (similar to how we use the
legacy ModuleSummaryAnalysisWrapperPass in the legacy WriteBitcodePass).

Also, pass the -module-summary opt flag through to the new pass
manager pipeline and through to the bitcode writer pass, and add
a test that uses it.

Reviewers: mehdi_amini

Subscribers: llvm-commits, mehdi_amini

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

Modified:
    llvm/trunk/include/llvm/Analysis/ModuleSummaryAnalysis.h
    llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriterPass.cpp
    llvm/trunk/lib/Passes/PassBuilder.cpp
    llvm/trunk/lib/Passes/PassRegistry.def
    llvm/trunk/test/Bitcode/thinlto-summary-globalvar.ll
    llvm/trunk/tools/opt/NewPMDriver.cpp
    llvm/trunk/tools/opt/NewPMDriver.h
    llvm/trunk/tools/opt/opt.cpp

Modified: llvm/trunk/include/llvm/Analysis/ModuleSummaryAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ModuleSummaryAnalysis.h?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ModuleSummaryAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/ModuleSummaryAnalysis.h Fri Aug 12 08:53:02 2016
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/IR/ModuleSummaryIndex.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 
 namespace llvm {
@@ -55,6 +56,20 @@ private:
   void computeVariableSummary(const GlobalVariable &V);
 };
 
+/// Analysis pass to provide the ModuleSummaryIndex object.
+class ModuleSummaryIndexAnalysis
+    : public AnalysisInfoMixin<ModuleSummaryIndexAnalysis> {
+  friend AnalysisInfoMixin<ModuleSummaryIndexAnalysis>;
+  static char PassID;
+
+  std::unique_ptr<ModuleSummaryIndexBuilder> IndexBuilder;
+
+public:
+  typedef const ModuleSummaryIndex &Result;
+
+  const ModuleSummaryIndex &run(Module &M, ModuleAnalysisManager &AM);
+};
+
 /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
 class ModuleSummaryIndexWrapperPass : public ModulePass {
   std::unique_ptr<ModuleSummaryIndexBuilder> IndexBuilder;

Modified: llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/ModuleSummaryAnalysis.cpp Fri Aug 12 08:53:02 2016
@@ -174,6 +174,19 @@ ModuleSummaryIndexBuilder::ModuleSummary
   }
 }
 
+char ModuleSummaryIndexAnalysis::PassID;
+
+const ModuleSummaryIndex &
+ModuleSummaryIndexAnalysis::run(Module &M, ModuleAnalysisManager &AM) {
+  auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
+  IndexBuilder = llvm::make_unique<ModuleSummaryIndexBuilder>(
+      &M, [&FAM](const Function &F) {
+        return &(
+            FAM.getResult<BlockFrequencyAnalysis>(*const_cast<Function *>(&F)));
+      });
+  return IndexBuilder->getIndex();
+}
+
 char ModuleSummaryIndexWrapperPass::ID = 0;
 INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
                       "Module Summary Analysis", false, true)

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriterPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriterPass.cpp?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriterPass.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriterPass.cpp Fri Aug 12 08:53:02 2016
@@ -19,12 +19,11 @@
 #include "llvm/Pass.h"
 using namespace llvm;
 
-PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &) {
-  std::unique_ptr<ModuleSummaryIndex> Index;
-  if (EmitSummaryIndex)
-    Index = ModuleSummaryIndexBuilder(&M).takeIndex();
-  WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index.get(),
-                     EmitModuleHash);
+PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
+  const ModuleSummaryIndex *Index =
+      EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
+                       : nullptr;
+  WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
   return PreservedAnalyses::all();
 }
 

Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Fri Aug 12 08:53:02 2016
@@ -38,6 +38,7 @@
 #include "llvm/Analysis/LoopAccessAnalysis.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
+#include "llvm/Analysis/ModuleSummaryAnalysis.h"
 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
 #include "llvm/Analysis/PostDominators.h"
 #include "llvm/Analysis/ProfileSummaryInfo.h"

Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Fri Aug 12 08:53:02 2016
@@ -21,6 +21,7 @@
 #endif
 MODULE_ANALYSIS("callgraph", CallGraphAnalysis())
 MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
+MODULE_ANALYSIS("module-summary", ModuleSummaryIndexAnalysis())
 MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis())
 MODULE_ANALYSIS("profile-summary", ProfileSummaryAnalysis())
 MODULE_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())

Modified: llvm/trunk/test/Bitcode/thinlto-summary-globalvar.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-summary-globalvar.ll?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-summary-globalvar.ll (original)
+++ llvm/trunk/test/Bitcode/thinlto-summary-globalvar.ll Fri Aug 12 08:53:02 2016
@@ -1,4 +1,6 @@
 ; RUN: opt -module-summary %s -o - | llvm-bcanalyzer -dump | FileCheck %s
+; Check with new pass manager (by enabling a random pass in the new pipeline).
+; RUN: opt -passes=gvn -module-summary %s -o - | llvm-bcanalyzer -dump | FileCheck %s
 
 ; CHECK: <GLOBALVAL_SUMMARY_BLOCK
 

Modified: llvm/trunk/tools/opt/NewPMDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/NewPMDriver.cpp?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/tools/opt/NewPMDriver.cpp (original)
+++ llvm/trunk/tools/opt/NewPMDriver.cpp Fri Aug 12 08:53:02 2016
@@ -52,7 +52,8 @@ bool llvm::runPassPipeline(StringRef Arg
                            StringRef PassPipeline, OutputKind OK,
                            VerifierKind VK,
                            bool ShouldPreserveAssemblyUseListOrder,
-                           bool ShouldPreserveBitcodeUseListOrder) {
+                           bool ShouldPreserveBitcodeUseListOrder,
+                           bool EmitSummaryIndex, bool EmitModuleHash) {
   PassBuilder PB(TM);
 
   // Specially handle the alias analysis manager so that we can register
@@ -100,8 +101,8 @@ bool llvm::runPassPipeline(StringRef Arg
         PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder));
     break;
   case OK_OutputBitcode:
-    MPM.addPass(
-        BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder));
+    MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder,
+                                  EmitSummaryIndex, EmitModuleHash));
     break;
   }
 

Modified: llvm/trunk/tools/opt/NewPMDriver.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/NewPMDriver.h?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/tools/opt/NewPMDriver.h (original)
+++ llvm/trunk/tools/opt/NewPMDriver.h Fri Aug 12 08:53:02 2016
@@ -52,7 +52,8 @@ bool runPassPipeline(StringRef Arg0, LLV
                      StringRef PassPipeline, opt_tool::OutputKind OK,
                      opt_tool::VerifierKind VK,
                      bool ShouldPreserveAssemblyUseListOrder,
-                     bool ShouldPreserveBitcodeUseListOrder);
+                     bool ShouldPreserveBitcodeUseListOrder,
+                     bool EmitSummaryIndex, bool EmitModuleHash);
 }
 
 #endif

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=278508&r1=278507&r2=278508&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Fri Aug 12 08:53:02 2016
@@ -490,7 +490,8 @@ int main(int argc, char **argv) {
     // layer.
     return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
                            PassPipeline, OK, VK, PreserveAssemblyUseListOrder,
-                           PreserveBitcodeUseListOrder)
+                           PreserveBitcodeUseListOrder, EmitSummaryIndex,
+                           EmitModuleHash)
                ? 0
                : 1;
   }




More information about the llvm-commits mailing list