[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

llvm-svn: 278508
This commit is contained in:
Teresa Johnson 2016-08-12 13:53:02 +00:00
parent 565bdd9fed
commit f93b246f8b
9 changed files with 45 additions and 11 deletions

View File

@ -16,6 +16,7 @@
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/IR/ModuleSummaryIndex.h" #include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
namespace llvm { namespace llvm {
@ -55,6 +56,20 @@ private:
void computeVariableSummary(const GlobalVariable &V); 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. /// Legacy wrapper pass to provide the ModuleSummaryIndex object.
class ModuleSummaryIndexWrapperPass : public ModulePass { class ModuleSummaryIndexWrapperPass : public ModulePass {
std::unique_ptr<ModuleSummaryIndexBuilder> IndexBuilder; std::unique_ptr<ModuleSummaryIndexBuilder> IndexBuilder;

View File

@ -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; char ModuleSummaryIndexWrapperPass::ID = 0;
INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis", INITIALIZE_PASS_BEGIN(ModuleSummaryIndexWrapperPass, "module-summary-analysis",
"Module Summary Analysis", false, true) "Module Summary Analysis", false, true)

View File

@ -19,12 +19,11 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
using namespace llvm; using namespace llvm;
PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &) { PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
std::unique_ptr<ModuleSummaryIndex> Index; const ModuleSummaryIndex *Index =
if (EmitSummaryIndex) EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
Index = ModuleSummaryIndexBuilder(&M).takeIndex(); : nullptr;
WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index.get(), WriteBitcodeToFile(&M, OS, ShouldPreserveUseListOrder, Index, EmitModuleHash);
EmitModuleHash);
return PreservedAnalyses::all(); return PreservedAnalyses::all();
} }

View File

@ -38,6 +38,7 @@
#include "llvm/Analysis/LoopAccessAnalysis.h" #include "llvm/Analysis/LoopAccessAnalysis.h"
#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h" #include "llvm/Analysis/MemoryDependenceAnalysis.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
#include "llvm/Analysis/OptimizationDiagnosticInfo.h" #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/PostDominators.h" #include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/Analysis/ProfileSummaryInfo.h"

View File

@ -21,6 +21,7 @@
#endif #endif
MODULE_ANALYSIS("callgraph", CallGraphAnalysis()) MODULE_ANALYSIS("callgraph", CallGraphAnalysis())
MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis()) MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
MODULE_ANALYSIS("module-summary", ModuleSummaryIndexAnalysis())
MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis()) MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis())
MODULE_ANALYSIS("profile-summary", ProfileSummaryAnalysis()) MODULE_ANALYSIS("profile-summary", ProfileSummaryAnalysis())
MODULE_ANALYSIS("targetlibinfo", TargetLibraryAnalysis()) MODULE_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())

View File

@ -1,4 +1,6 @@
; RUN: opt -module-summary %s -o - | llvm-bcanalyzer -dump | FileCheck %s ; 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 ; CHECK: <GLOBALVAL_SUMMARY_BLOCK

View File

@ -52,7 +52,8 @@ bool llvm::runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
StringRef PassPipeline, OutputKind OK, StringRef PassPipeline, OutputKind OK,
VerifierKind VK, VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder) { bool ShouldPreserveBitcodeUseListOrder,
bool EmitSummaryIndex, bool EmitModuleHash) {
PassBuilder PB(TM); PassBuilder PB(TM);
// Specially handle the alias analysis manager so that we can register // 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)); PrintModulePass(Out->os(), "", ShouldPreserveAssemblyUseListOrder));
break; break;
case OK_OutputBitcode: case OK_OutputBitcode:
MPM.addPass( MPM.addPass(BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder,
BitcodeWriterPass(Out->os(), ShouldPreserveBitcodeUseListOrder)); EmitSummaryIndex, EmitModuleHash));
break; break;
} }

View File

@ -52,7 +52,8 @@ bool runPassPipeline(StringRef Arg0, LLVMContext &Context, Module &M,
StringRef PassPipeline, opt_tool::OutputKind OK, StringRef PassPipeline, opt_tool::OutputKind OK,
opt_tool::VerifierKind VK, opt_tool::VerifierKind VK,
bool ShouldPreserveAssemblyUseListOrder, bool ShouldPreserveAssemblyUseListOrder,
bool ShouldPreserveBitcodeUseListOrder); bool ShouldPreserveBitcodeUseListOrder,
bool EmitSummaryIndex, bool EmitModuleHash);
} }
#endif #endif

View File

@ -490,7 +490,8 @@ int main(int argc, char **argv) {
// layer. // layer.
return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(), return runPassPipeline(argv[0], Context, *M, TM.get(), Out.get(),
PassPipeline, OK, VK, PreserveAssemblyUseListOrder, PassPipeline, OK, VK, PreserveAssemblyUseListOrder,
PreserveBitcodeUseListOrder) PreserveBitcodeUseListOrder, EmitSummaryIndex,
EmitModuleHash)
? 0 ? 0
: 1; : 1;
} }