diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h | 15 | ||||
| -rw-r--r-- | llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | 13 | ||||
| -rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp | 11 | ||||
| -rw-r--r-- | llvm/lib/Passes/PassBuilder.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/Passes/PassRegistry.def | 1 | ||||
| -rw-r--r-- | llvm/test/Bitcode/thinlto-summary-globalvar.ll | 2 | ||||
| -rw-r--r-- | llvm/tools/opt/NewPMDriver.cpp | 7 | ||||
| -rw-r--r-- | llvm/tools/opt/NewPMDriver.h | 3 | ||||
| -rw-r--r-- | llvm/tools/opt/opt.cpp | 3 |
9 files changed, 45 insertions, 11 deletions
diff --git a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h index 9f03610ba5b..161fe18e6e9 100644 --- a/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h +++ b/llvm/include/llvm/Analysis/ModuleSummaryAnalysis.h @@ -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; diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index e457f1c00f4..d4081918d35 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -174,6 +174,19 @@ ModuleSummaryIndexBuilder::ModuleSummaryIndexBuilder( } } +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) diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp index 3e89ade424a..e8e0b103d09 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp @@ -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(); } diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 19239ba98ce..32aa87bde3c 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -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" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 76672227540..2e897b37088 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -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()) diff --git a/llvm/test/Bitcode/thinlto-summary-globalvar.ll b/llvm/test/Bitcode/thinlto-summary-globalvar.ll index 56f9c078875..f7928303e75 100644 --- a/llvm/test/Bitcode/thinlto-summary-globalvar.ll +++ b/llvm/test/Bitcode/thinlto-summary-globalvar.ll @@ -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 diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp index f7b2f18d09d..223d9605a02 100644 --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -52,7 +52,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, 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 Arg0, LLVMContext &Context, Module &M, PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder)); break; case OK_OutputBitcode: - MPM.addPass( - BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder)); + MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder, + EmitSummaryIndex, EmitModuleHash)); break; } diff --git a/llvm/tools/opt/NewPMDriver.h b/llvm/tools/opt/NewPMDriver.h index 66a470d49ba..5cf2afc53bd 100644 --- a/llvm/tools/opt/NewPMDriver.h +++ b/llvm/tools/opt/NewPMDriver.h @@ -52,7 +52,8 @@ bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M, StringRef PassPipeline, opt_tool::OutputKind OK, opt_tool::VerifierKind VK, bool ShouldPreserveAssemblyUseListOrder, - bool ShouldPreserveBitcodeUseListOrder); + bool ShouldPreserveBitcodeUseListOrder, + bool EmitSummaryIndex, bool EmitModuleHash); } #endif diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp index 66dc5637eb5..4aa21db98fb 100644 --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -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; } |

