[Alignment][NFC] Convert StoreInst to MaybeAlign
[llvm-complete.git] / lib / Transforms / IPO / SCCP.cpp
blob307690729b14186e6a947a9d580f02117cf3df5c
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"
8 using namespace llvm;
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);
18 return {
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();
26 PreservedAnalyses PA;
27 PA.preserve<DominatorTreeAnalysis>();
28 PA.preserve<PostDominatorTreeAnalysis>();
29 PA.preserve<FunctionAnalysisManagerModuleProxy>();
30 return PA;
33 namespace {
35 //===--------------------------------------------------------------------===//
37 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
38 /// Constant Propagation.
39 ///
40 class IPSCCPLegacyPass : public ModulePass {
41 public:
42 static char ID;
44 IPSCCPLegacyPass() : ModulePass(ID) {
45 initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
48 bool runOnModule(Module &M) override {
49 if (skipModule(M))
50 return false;
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 {
56 DominatorTree &DT =
57 this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
58 return {
59 std::make_unique<PredicateInfo>(
60 F, DT,
61 this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
62 F)),
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",
83 false, false)
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",
89 false, false)
91 // createIPSCCPPass - This is the public interface to this file.
92 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }