[ASan] Make insertion of version mismatch guard configurable
[llvm-core.git] / lib / Transforms / IPO / SCCP.cpp
blob1393befe77b8e81786e470250b243334f12bed9e
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 &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 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();
24 PreservedAnalyses PA;
25 PA.preserve<DominatorTreeAnalysis>();
26 PA.preserve<PostDominatorTreeAnalysis>();
27 PA.preserve<FunctionAnalysisManagerModuleProxy>();
28 return PA;
31 namespace {
33 //===--------------------------------------------------------------------===//
35 /// IPSCCP Class - This class implements interprocedural Sparse Conditional
36 /// Constant Propagation.
37 ///
38 class IPSCCPLegacyPass : public ModulePass {
39 public:
40 static char ID;
42 IPSCCPLegacyPass() : ModulePass(ID) {
43 initializeIPSCCPLegacyPassPass(*PassRegistry::getPassRegistry());
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();
53 auto getAnalysis = [this](Function &F) -> AnalysisResultsForFn {
54 DominatorTree &DT =
55 this->getAnalysis<DominatorTreeWrapperPass>(F).getDomTree();
56 return {
57 std::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.
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",
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)
89 // createIPSCCPPass - This is the public interface to this file.
90 ModulePass *llvm::createIPSCCPPass() { return new IPSCCPLegacyPass(); }