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" 7 8 using namespace llvm; 9 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); 16 return { 17 make_unique<PredicateInfo>(F, DT, FAM.getResult<AssumptionAnalysis>(F)), 18 &DT, FAM.getCachedResult<PostDominatorTreeAnalysis>(F)}; 19 }; 20 21 if (!runIPSCCP(M, DL, &TLI, getAnalysis)) 22 return PreservedAnalyses::all(); 23 24 PreservedAnalyses PA; 25 PA.preserve<DominatorTreeAnalysis>(); 26 PA.preserve<PostDominatorTreeAnalysis>(); 27 PA.preserve<FunctionAnalysisManagerModuleProxy>(); 28 return PA; 29 } 30 31 namespace { 32 33 //===--------------------------------------------------------------------===// 34 // 35 /// IPSCCP Class - This class implements interprocedural Sparse Conditional 36 /// Constant Propagation. 37 /// 38 class IPSCCPLegacyPass : public ModulePass { 39 public: 40 static char ID; 41 42 IPSCCPLegacyPass() : ModulePass(ID) { 43 initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry()); 44 } 45 46 bool runOnModule(Module &M) override { 47 if (skipModule(M)) 48 return false; 49 const DataLayout &DL = M.getDataLayout(); 50 const TargetLibraryInfo *TLI = 51 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); 52 53 auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn { 54 DominatorTree &DT = 55 this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree(); 56 return { 57 make_unique<PredicateInfo>( 58 F, DT, 59 this->getAnalysis<AssumptionCacheTracker>().getAssumptionCache( 60 F)), 61 nullptr, // We cannot preserve the DT or PDT with the legacy pass 62 nullptr}; // manager, so set them to nullptr. 63 }; 64 65 return runIPSCCP(M, DL, TLI, getAnalysis); 66 } 67 68 void getAnalysisUsage(AnalysisUsage &AU) const override { 69 AU.addRequired<AssumptionCacheTracker>(); 70 AU.addRequired<DominatorTreeWrapperPass>(); 71 AU.addRequired<TargetLibraryInfoWrapperPass>(); 72 } 73 }; 74 75 } // end anonymous namespace 76 77 char IPSCCPLegacyPass::ID = 0; 78 79 INITIALIZE_PASS_BEGIN(IPSCCPLegacyPass, "ipsccp", 80 "Interprocedural Sparse Conditional Constant Propagation", 81 false, false) 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", 87 false, false) 88 89 // createIPSCCPPass - This is the public interface to this file. 90 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); } 91