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 &TLI
= AM
.getResult
<TargetLibraryAnalysis
>(M
);
13 auto &FAM
= AM
.getResult
<FunctionAnalysisManagerModuleProxy
>(M
).getManager();
14 auto getAnalysis
= [&FAM
](Function
&F
) -> AnalysisResultsForFn
{
15 DominatorTree
&DT
= FAM
.getResult
<DominatorTreeAnalysis
>(F
);
17 std::make_unique
<PredicateInfo
>(F
, DT
, FAM
.getResult
<AssumptionAnalysis
>(F
)),
18 &DT
, FAM
.getCachedResult
<PostDominatorTreeAnalysis
>(F
)};
21 if (!runIPSCCP(M
, DL
, &TLI
, getAnalysis
))
22 return PreservedAnalyses::all();
25 PA
.preserve
<DominatorTreeAnalysis
>();
26 PA
.preserve
<PostDominatorTreeAnalysis
>();
27 PA
.preserve
<FunctionAnalysisManagerModuleProxy
>();
33 //===--------------------------------------------------------------------===//
35 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
36 /// Constant Propagation.
38 class IPSCCPLegacyPass
: public ModulePass
{
42 IPSCCPLegacyPass() : ModulePass(ID
) {
43 initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
46 bool runOnModule(Module
&M
) override
{
49 const DataLayout
&DL
= M
.getDataLayout();
50 const TargetLibraryInfo
*TLI
=
51 &getAnalysis
<TargetLibraryInfoWrapperPass
>().getTLI();
53 auto getAnalysis
= [this](Function
&F
) -> AnalysisResultsForFn
{
55 this->getAnalysis
<DominatorTreeWrapperPass
>(F
).getDomTree();
57 std::make_unique
<PredicateInfo
>(
59 this->getAnalysis
<AssumptionCacheTracker
>().getAssumptionCache(
61 nullptr, // We cannot preserve the DT or PDT with the legacy pass
62 nullptr}; // manager, so set them to nullptr.
65 return runIPSCCP(M
, DL
, TLI
, getAnalysis
);
68 void getAnalysisUsage(AnalysisUsage
&AU
) const override
{
69 AU
.addRequired
<AssumptionCacheTracker
>();
70 AU
.addRequired
<DominatorTreeWrapperPass
>();
71 AU
.addRequired
<TargetLibraryInfoWrapperPass
>();
75 } // end anonymous namespace
77 char IPSCCPLegacyPass::ID
= 0;
79 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass
, "ipsccp",
80 "Interprocedural Sparse Conditional Constant Propagation",
82 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker
)
83 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass
)
84 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass
)
85 INITIALIZE_PASS_END(IPSCCPLegacyPass
, "ipsccp",
86 "Interprocedural Sparse Conditional Constant Propagation",
89 // createIPSCCPPass - This is the public interface to this file.
90 ModulePass
*llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }