1 #include "llvm/Transforms/IPO/SCCP.h"
2 #include "llvm/Analysis/AssumptionCache.h"
3 #include "llvm/Analysis/PostDominators.h"
4 #include "llvm/Analysis/TargetLibraryInfo.h"
5 #include "llvm/Transforms/IPO.h"
6 #include "llvm/Transforms/Scalar/SCCP.h"
10 PreservedAnalyses
IPSCCPPass::run(Module
&M
, ModuleAnalysisManager
&AM
) {
11 const DataLayout
&DL
= M
.getDataLayout();
12 auto &FAM
= AM
.getResult
<FunctionAnalysisManagerModuleProxy
>(M
).getManager();
13 auto GetTLI
= [&FAM
](Function
&F
) -> const TargetLibraryInfo
& {
14 return FAM
.getResult
<TargetLibraryAnalysis
>(F
);
16 auto getAnalysis
= [&FAM
](Function
&F
) -> AnalysisResultsForFn
{
17 DominatorTree
&DT
= FAM
.getResult
<DominatorTreeAnalysis
>(F
);
19 std::make_unique
<PredicateInfo
>(F
, DT
, FAM
.getResult
<AssumptionAnalysis
>(F
)),
20 &DT
, FAM
.getCachedResult
<PostDominatorTreeAnalysis
>(F
)};
23 if (!runIPSCCP(M
, DL
, GetTLI
, getAnalysis
))
24 return PreservedAnalyses::all();
27 PA
.preserve
<DominatorTreeAnalysis
>();
28 PA
.preserve
<PostDominatorTreeAnalysis
>();
29 PA
.preserve
<FunctionAnalysisManagerModuleProxy
>();
35 //===--------------------------------------------------------------------===//
37 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
38 /// Constant Propagation.
40 class IPSCCPLegacyPass
: public ModulePass
{
44 IPSCCPLegacyPass() : ModulePass(ID
) {
45 initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
48 bool runOnModule(Module
&M
) override
{
51 const DataLayout
&DL
= M
.getDataLayout();
52 auto GetTLI
= [this](Function
&F
) -> const TargetLibraryInfo
& {
53 return this->getAnalysis
<TargetLibraryInfoWrapperPass
>().getTLI(F
);
55 auto getAnalysis
= [this](Function
&F
) -> AnalysisResultsForFn
{
57 this->getAnalysis
<DominatorTreeWrapperPass
>(F
).getDomTree();
59 std::make_unique
<PredicateInfo
>(
61 this->getAnalysis
<AssumptionCacheTracker
>().getAssumptionCache(
63 nullptr, // We cannot preserve the DT or PDT with the legacy pass
64 nullptr}; // manager, so set them to nullptr.
67 return runIPSCCP(M
, DL
, GetTLI
, getAnalysis
);
70 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
71 AU
.addRequired
<AssumptionCacheTracker
>();
72 AU
.addRequired
<DominatorTreeWrapperPass
>();
73 AU
.addRequired
<TargetLibraryInfoWrapperPass
>();
77 } // end anonymous namespace
79 char IPSCCPLegacyPass::ID
= 0;
81 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass
, "ipsccp",
82 "Interprocedural Sparse Conditional Constant Propagation",
84 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker
)
85 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass
)
86 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass
)
87 INITIALIZE_PASS_END(IPSCCPLegacyPass
, "ipsccp",
88 "Interprocedural Sparse Conditional Constant Propagation",
91 // createIPSCCPPass - This is the public interface to this file.
92 ModulePass
*llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }