Skip to content

Commit adf1eae

Browse files
committed
Bring in DominanceInfo and DeadEndBlocks to DCE
1 parent 867cf28 commit adf1eae

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/SILOptimizer/Transforms/DeadCodeElimination.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/SIL/SILFunction.h"
2424
#include "swift/SIL/SILUndef.h"
2525
#include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
26+
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
2627
#include "swift/SILOptimizer/PassManager/Passes.h"
2728
#include "swift/SILOptimizer/PassManager/Transforms.h"
2829
#include "swift/SILOptimizer/Utils/BasicBlockOptUtils.h"
@@ -126,6 +127,8 @@ class DCE {
126127
BasicBlockSet LiveBlocks;
127128
llvm::SmallVector<SILInstruction *, 64> Worklist;
128129
PostDominanceInfo *PDT;
130+
DominanceInfo *DT;
131+
DeadEndBlocks *deadEndBlocks;
129132
llvm::DenseMap<SILBasicBlock *, ControllingInfo> ControllingInfoMap;
130133

131134
// Maps instructions which produce a failing condition (like overflow
@@ -194,8 +197,10 @@ class DCE {
194197
void endLifetimeOfLiveValue(Operand *op, SILInstruction *insertPt);
195198

196199
public:
197-
DCE(SILFunction *F, PostDominanceInfo *PDT)
198-
: F(F), LiveArguments(F), LiveInstructions(F), LiveBlocks(F), PDT(PDT) {}
200+
DCE(SILFunction *F, PostDominanceInfo *PDT, DominanceInfo *DT,
201+
DeadEndBlocks *deadEndBlocks)
202+
: F(F), LiveArguments(F), LiveInstructions(F), LiveBlocks(F), PDT(PDT),
203+
DT(DT), deadEndBlocks(deadEndBlocks) {}
199204

200205
/// The entry point to the transformation.
201206
bool run() {
@@ -977,8 +982,11 @@ class DCEPass : public SILFunctionTransform {
977982
LLVM_DEBUG(llvm::dbgs() << "*** DCE on function: " << F->getName()
978983
<< " ***\n");
979984

980-
auto *DA = PM->getAnalysis<PostDominanceAnalysis>();
981-
PostDominanceInfo *PDT = DA->get(F);
985+
auto *PDA = PM->getAnalysis<PostDominanceAnalysis>();
986+
PostDominanceInfo *PDT = PDA->get(F);
987+
988+
auto *DA = PM->getAnalysis<DominanceAnalysis>();
989+
auto *DEA = getAnalysis<DeadEndBlocksAnalysis>();
982990

983991
// If we have a function that consists of nothing but a
984992
// structurally infinite loop like:
@@ -987,7 +995,7 @@ class DCEPass : public SILFunctionTransform {
987995
if (!PDT->getRootNode())
988996
return;
989997

990-
DCE dce(F, PDT);
998+
DCE dce(F, PDT, DA->get(F), DEA->get(F));
991999
if (dce.run()) {
9921000
using InvalidationKind = SILAnalysis::InvalidationKind;
9931001
unsigned Inv = InvalidationKind::Instructions;

0 commit comments

Comments
 (0)