David Blaikie | 3bbf5af | 2018-03-22 21:41:29 +0000 | [diff] [blame] | 1 | #include "llvm/Transforms/IPO/SCCP.h" |
Florian Hahn | 3052290 | 2018-08-23 11:04:00 +0000 | [diff] [blame] | 2 | #include "llvm/Analysis/AssumptionCache.h" |
David Blaikie | 3bbf5af | 2018-03-22 21:41:29 +0000 | [diff] [blame] | 3 | #include "llvm/Analysis/TargetLibraryInfo.h" |
| 4 | #include "llvm/Transforms/IPO.h" |
| 5 | #include "llvm/Transforms/Scalar/SCCP.h" |
| 6 | |
| 7 | using namespace llvm; |
| 8 | |
| 9 | PreservedAnalyses IPSCCPPass::run(Module &M, ModuleAnalysisManager &AM) { |
| 10 | const DataLayout &DL = M.getDataLayout(); |
| 11 | auto &TLI = AM.getResult<TargetLibraryAnalysis>(M); |
Florian Hahn | 3052290 | 2018-08-23 11:04:00 +0000 | [diff] [blame] | 12 | auto &FAM = AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); |
| 13 | auto getPredicateInfo = |
| 14 | [&FAM](Function &F) -> std::unique_ptr<PredicateInfo> { |
| 15 | return make_unique<PredicateInfo>(F, |
| 16 | FAM.getResult<DominatorTreeAnalysis>(F), |
| 17 | FAM.getResult<AssumptionAnalysis>(F)); |
| 18 | }; |
| 19 | |
| 20 | if (!runIPSCCP(M, DL, &TLI, getPredicateInfo)) |
David Blaikie | 3bbf5af | 2018-03-22 21:41:29 +0000 | [diff] [blame] | 21 | return PreservedAnalyses::all(); |
| 22 | return PreservedAnalyses::none(); |
| 23 | } |
| 24 | |
| 25 | namespace { |
| 26 | |
| 27 | //===--------------------------------------------------------------------===// |
| 28 | // |
| 29 | /// IPSCCP Class - This class implements interprocedural Sparse Conditional |
| 30 | /// Constant Propagation. |
| 31 | /// |
| 32 | class IPSCCPLegacyPass : public ModulePass { |
| 33 | public: |
| 34 | static char ID; |
| 35 | |
| 36 | IPSCCPLegacyPass() : ModulePass(ID) { |
| 37 | initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry()); |
| 38 | } |
| 39 | |
| 40 | bool runOnModule(Module &M) override { |
| 41 | if (skipModule(M)) |
| 42 | return false; |
| 43 | const DataLayout &DL = M.getDataLayout(); |
| 44 | const TargetLibraryInfo *TLI = |
| 45 | &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); |
Florian Hahn | 3052290 | 2018-08-23 11:04:00 +0000 | [diff] [blame] | 46 | |
| 47 | auto getPredicateInfo = |
| 48 | [this](Function &F) -> std::unique_ptr<PredicateInfo> { |
| 49 | return make_unique<PredicateInfo>( |
| 50 | F, this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree(), |
| 51 | this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F)); |
| 52 | }; |
| 53 | |
| 54 | return runIPSCCP(M, DL, TLI, getPredicateInfo); |
David Blaikie | 3bbf5af | 2018-03-22 21:41:29 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | void getAnalysisUsage(AnalysisUsage &AU) const override { |
Florian Hahn | 3052290 | 2018-08-23 11:04:00 +0000 | [diff] [blame] | 58 | AU.addRequired<AssumptionCacheTracker>(); |
| 59 | AU.addRequired<DominatorTreeWrapperPass>(); |
David Blaikie | 3bbf5af | 2018-03-22 21:41:29 +0000 | [diff] [blame] | 60 | AU.addRequired<TargetLibraryInfoWrapperPass>(); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | } // end anonymous namespace |
| 65 | |
| 66 | char IPSCCPLegacyPass::ID = 0; |
| 67 | |
| 68 | INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp", |
| 69 | "Interprocedural Sparse Conditional Constant Propagation", |
| 70 | false, false) |
Florian Hahn | 3052290 | 2018-08-23 11:04:00 +0000 | [diff] [blame] | 71 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
David Blaikie | 3bbf5af | 2018-03-22 21:41:29 +0000 | [diff] [blame] | 72 | INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) |
| 73 | INITIALIZE_PASS_END(IPSCCPLegacyPass, "ipsccp", |
| 74 | "Interprocedural Sparse Conditional Constant Propagation", |
| 75 | false, false) |
| 76 | |
| 77 | // createIPSCCPPass - This is the public interface to this file. |
| 78 | ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); } |