1 #include "llvm/Transforms/IPO/SCCP.h" 2 #include "llvm/Analysis/AssumptionCache.h" 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); 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)) 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(); 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); 55 } 56 57 void getAnalysisUsage(AnalysisUsage &AU) const override { 58 AU.addRequired<AssumptionCacheTracker>(); 59 AU.addRequired<DominatorTreeWrapperPass>(); 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) 71 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) 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(); } 79