llvm.org GIT mirror llvm / 04d2814
PM: Port DCE to the new pass manager Also add a very basic test, since apparently there aren't any tests for DCE whatsoever to add the new pass version to. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267196 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 3 years ago
8 changed file(s) with 81 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
103103 void initializeCrossDSOCFIPass(PassRegistry&);
104104 void initializeDAEPass(PassRegistry&);
105105 void initializeDAHPass(PassRegistry&);
106 void initializeDCEPass(PassRegistry&);
106 void initializeDCELegacyPassPass(PassRegistry&);
107107 void initializeDSEPass(PassRegistry&);
108108 void initializeDeadInstEliminationPass(PassRegistry&);
109109 void initializeDeadMachineInstructionElimPass(PassRegistry&);
0 //===- DCE.h - Dead code elimination ----------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides the interface for the Dead Code Elimination pass.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_TRANSFORMS_SCALAR_DCE_H
14 #define LLVM_TRANSFORMS_SCALAR_DCE_H
15
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/PassManager.h"
18
19 namespace llvm {
20
21 /// Basic Dead Code Elimination pass.
22 class DCEPass : public PassInfoMixin {
23 public:
24 PreservedAnalyses run(Function &F, AnalysisManager &AM);
25 };
26 }
27
28 #endif // LLVM_TRANSFORMS_SCALAR_DCE_H
116116 initializeMergedLoadStoreMotionPass(R);
117117 initializeGVNLegacyPassPass(R);
118118 initializeMemCpyOptPass(R);
119 initializeDCEPass(R);
119 initializeDCELegacyPassPass(R);
120120 initializeCFGSimplifyPassPass(R);
121121 }
122122
5151 #include "llvm/Transforms/InstCombine/InstCombine.h"
5252 #include "llvm/Transforms/InstrProfiling.h"
5353 #include "llvm/Transforms/Scalar/ADCE.h"
54 #include "llvm/Transforms/Scalar/DCE.h"
5455 #include "llvm/Transforms/Scalar/EarlyCSE.h"
5556 #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
5657 #include "llvm/Transforms/Scalar/GVN.h"
9595 #endif
9696 FUNCTION_PASS("aa-eval", AAEvaluator())
9797 FUNCTION_PASS("adce", ADCEPass())
98 FUNCTION_PASS("dce", DCEPass())
9899 FUNCTION_PASS("early-cse", EarlyCSEPass())
99100 FUNCTION_PASS("instcombine", InstCombinePass())
100101 FUNCTION_PASS("invalidate", InvalidateAllAnalysesPass())
1515 //
1616 //===----------------------------------------------------------------------===//
1717
18 #include "llvm/Transforms/Scalar.h"
18 #include "llvm/Transforms/Scalar/DCE.h"
1919 #include "llvm/ADT/SetVector.h"
2020 #include "llvm/ADT/Statistic.h"
2121 #include "llvm/IR/InstIterator.h"
2222 #include "llvm/IR/Instruction.h"
2323 #include "llvm/Pass.h"
2424 #include "llvm/Analysis/TargetLibraryInfo.h"
25 #include "llvm/Transforms/Scalar.h"
2526 #include "llvm/Transforms/Utils/Local.h"
2627 using namespace llvm;
2728
7071 return new DeadInstElimination();
7172 }
7273
73
74 namespace {
75 //===--------------------------------------------------------------------===//
76 // DeadCodeElimination pass implementation
77 //
78 struct DCE : public FunctionPass {
79 static char ID; // Pass identification, replacement for typeid
80 DCE() : FunctionPass(ID) {
81 initializeDCEPass(*PassRegistry::getPassRegistry());
82 }
83
84 bool runOnFunction(Function &F) override;
85
86 void getAnalysisUsage(AnalysisUsage &AU) const override {
87 AU.setPreservesCFG();
88 }
89 };
90 }
91
92 char DCE::ID = 0;
93 INITIALIZE_PASS(DCE, "dce", "Dead Code Elimination", false, false)
94
9574 static bool DCEInstruction(Instruction *I,
9675 SmallSetVector &WorkList,
9776 const TargetLibraryInfo *TLI) {
12099 return false;
121100 }
122101
123 bool DCE::runOnFunction(Function &F) {
124 if (skipOptnoneFunction(F))
125 return false;
126
127 auto *TLIP = getAnalysisIfAvailable();
128 TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI() : nullptr;
129
102 bool eliminateDeadCode(Function &F, TargetLibraryInfo *TLI) {
130103 bool MadeChange = false;
131104 SmallSetVector WorkList;
132105 // Iterate over the original function, only adding insts to the worklist
149122 return MadeChange;
150123 }
151124
152 FunctionPass *llvm::createDeadCodeEliminationPass() {
153 return new DCE();
125 PreservedAnalyses DCEPass::run(Function &F, AnalysisManager &AM) {
126 if (eliminateDeadCode(F, AM.getCachedResult(F)))
127 return PreservedAnalyses::none();
128 return PreservedAnalyses::all();
154129 }
155130
131 namespace {
132 struct DCELegacyPass : public FunctionPass {
133 static char ID; // Pass identification, replacement for typeid
134 DCELegacyPass() : FunctionPass(ID) {
135 initializeDCELegacyPassPass(*PassRegistry::getPassRegistry());
136 }
137
138 bool runOnFunction(Function &F) override {
139 if (skipOptnoneFunction(F))
140 return false;
141
142 auto *TLIP = getAnalysisIfAvailable();
143 TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI() : nullptr;
144
145 return eliminateDeadCode(F, TLI);
146 }
147
148 void getAnalysisUsage(AnalysisUsage &AU) const override {
149 AU.setPreservesCFG();
150 }
151 };
152 }
153
154 char DCELegacyPass::ID = 0;
155 INITIALIZE_PASS(DCELegacyPass, "dce", "Dead Code Elimination", false, false)
156
157 FunctionPass *llvm::createDeadCodeEliminationPass() {
158 return new DCELegacyPass();
159 }
3636 initializeConstantHoistingPass(Registry);
3737 initializeConstantPropagationPass(Registry);
3838 initializeCorrelatedValuePropagationPass(Registry);
39 initializeDCEPass(Registry);
39 initializeDCELegacyPassPass(Registry);
4040 initializeDeadInstEliminationPass(Registry);
4141 initializeScalarizerPass(Registry);
4242 initializeDSEPass(Registry);
0 ; RUN: opt -dce -S < %s | FileCheck %s
1 ; RUN: opt -passes=dce -S < %s | FileCheck %s
2
3 ; CHECK-LABEL: @test
4 define void @test() {
5 ; CHECK-NOT: add
6 %add = add i32 1, 2
7 ; CHECK-NOT: sub
8 %sub = sub i32 %add, 1
9 ret void
10 }