|
38 | 38 | #include "llvm/ADT/Statistic.h" |
39 | 39 | #include "llvm/ADT/StringRef.h" |
40 | 40 | #include "llvm/Analysis/AliasAnalysis.h" |
| 41 | +#include "llvm/Analysis/AssumptionCache.h" |
41 | 42 | #include "llvm/Analysis/CaptureTracking.h" |
42 | 43 | #include "llvm/Analysis/GlobalsModRef.h" |
43 | 44 | #include "llvm/Analysis/LoopInfo.h" |
|
69 | 70 | #include "llvm/IR/PassManager.h" |
70 | 71 | #include "llvm/IR/PatternMatch.h" |
71 | 72 | #include "llvm/IR/Value.h" |
| 73 | +#include "llvm/InitializePasses.h" |
72 | 74 | #include "llvm/Support/Casting.h" |
73 | 75 | #include "llvm/Support/CommandLine.h" |
74 | 76 | #include "llvm/Support/Debug.h" |
@@ -2666,3 +2668,79 @@ PreservedAnalyses DSEPass::run(Function &F, FunctionAnalysisManager &AM) { |
2666 | 2668 | PA.preserve<LoopAnalysis>(); |
2667 | 2669 | return PA; |
2668 | 2670 | } |
| 2671 | + |
| 2672 | +namespace { |
| 2673 | + |
| 2674 | +/// A legacy pass for the legacy pass manager that wraps \c DSEPass. |
| 2675 | +class DSELegacyPass : public FunctionPass { |
| 2676 | +public: |
| 2677 | + static char ID; // Pass identification, replacement for typeid |
| 2678 | + |
| 2679 | + DSELegacyPass() : FunctionPass(ID) { |
| 2680 | + initializeDSELegacyPassPass(*PassRegistry::getPassRegistry()); |
| 2681 | + } |
| 2682 | + |
| 2683 | + bool runOnFunction(Function &F) override { |
| 2684 | + if (skipFunction(F)) |
| 2685 | + return false; |
| 2686 | + |
| 2687 | + AliasAnalysis &AA = getAnalysis<AAResultsWrapperPass>().getAAResults(); |
| 2688 | + DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
| 2689 | + const TargetLibraryInfo &TLI = |
| 2690 | + getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F); |
| 2691 | + MemorySSA &MSSA = getAnalysis<MemorySSAWrapperPass>().getMSSA(); |
| 2692 | + PostDominatorTree &PDT = |
| 2693 | + getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree(); |
| 2694 | + LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
| 2695 | + |
| 2696 | + bool Changed = eliminateDeadStores(F, AA, MSSA, DT, PDT, TLI, LI); |
| 2697 | + |
| 2698 | +#ifdef LLVM_ENABLE_STATS |
| 2699 | + if (AreStatisticsEnabled()) |
| 2700 | + for (auto &I : instructions(F)) |
| 2701 | + NumRemainingStores += isa<StoreInst>(&I); |
| 2702 | +#endif |
| 2703 | + |
| 2704 | + return Changed; |
| 2705 | + } |
| 2706 | + |
| 2707 | + void getAnalysisUsage(AnalysisUsage &AU) const override { |
| 2708 | + AU.setPreservesCFG(); |
| 2709 | + AU.addRequired<AAResultsWrapperPass>(); |
| 2710 | + AU.addRequired<TargetLibraryInfoWrapperPass>(); |
| 2711 | + AU.addPreserved<GlobalsAAWrapperPass>(); |
| 2712 | + AU.addRequired<DominatorTreeWrapperPass>(); |
| 2713 | + AU.addPreserved<DominatorTreeWrapperPass>(); |
| 2714 | + AU.addRequired<PostDominatorTreeWrapperPass>(); |
| 2715 | + AU.addRequired<MemorySSAWrapperPass>(); |
| 2716 | + AU.addPreserved<PostDominatorTreeWrapperPass>(); |
| 2717 | + AU.addPreserved<MemorySSAWrapperPass>(); |
| 2718 | + AU.addRequired<LoopInfoWrapperPass>(); |
| 2719 | + AU.addPreserved<LoopInfoWrapperPass>(); |
| 2720 | + AU.addRequired<AssumptionCacheTracker>(); |
| 2721 | + } |
| 2722 | +}; |
| 2723 | + |
| 2724 | +} // end anonymous namespace |
| 2725 | + |
| 2726 | +char DSELegacyPass::ID = 0; |
| 2727 | + |
| 2728 | +INITIALIZE_PASS_BEGIN(DSELegacyPass, "dse", "Dead Store Elimination", false, |
| 2729 | + false) |
| 2730 | +INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
| 2731 | +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) |
| 2732 | +INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) |
| 2733 | +INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass) |
| 2734 | +INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass) |
| 2735 | +INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass) |
| 2736 | +INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) |
| 2737 | +INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) |
| 2738 | +INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) |
| 2739 | +INITIALIZE_PASS_END(DSELegacyPass, "dse", "Dead Store Elimination", false, |
| 2740 | + false) |
| 2741 | + |
| 2742 | +namespace llvm { |
| 2743 | +LLVM_ABI FunctionPass *createDeadStoreEliminationPass() { |
| 2744 | + return new DSELegacyPass(); |
| 2745 | +} |
| 2746 | +} // namespace llvm |
0 commit comments