27
27
#include " llvm/IR/BasicBlock.h"
28
28
#include " llvm/IR/CFG.h"
29
29
#include " llvm/IR/DebugInfoMetadata.h"
30
- #include " llvm/IR/Dominators.h"
31
30
#include " llvm/IR/IRBuilder.h"
32
31
#include " llvm/IR/InstIterator.h"
33
32
#include " llvm/IR/Instructions.h"
@@ -90,10 +89,6 @@ struct BlockInfoType {
90
89
91
90
class AggressiveDeadCodeElimination {
92
91
Function &F;
93
-
94
- // ADCE does not use DominatorTree per se, but it updates it to preserve the
95
- // analysis.
96
- DominatorTree &DT;
97
92
PostDominatorTree &PDT;
98
93
99
94
// / Mapping of blocks to associated information, an element in BlockInfoVec.
@@ -162,10 +157,9 @@ class AggressiveDeadCodeElimination {
162
157
void makeUnconditional (BasicBlock *BB, BasicBlock *Target);
163
158
164
159
public:
165
- AggressiveDeadCodeElimination (Function &F, DominatorTree &DT,
166
- PostDominatorTree &PDT)
167
- : F(F), DT(DT), PDT(PDT) {}
168
- bool performDeadCodeElimination ();
160
+ AggressiveDeadCodeElimination (Function &F, PostDominatorTree &PDT)
161
+ : F(F), PDT(PDT) {}
162
+ bool performDeadCodeElimination ();
169
163
};
170
164
}
171
165
@@ -563,31 +557,14 @@ void AggressiveDeadCodeElimination::updateDeadRegions() {
563
557
}
564
558
assert ((PreferredSucc && PreferredSucc->PostOrder > 0 ) &&
565
559
" Failed to find safe successor for dead branch" );
566
-
567
- // Collect removed successors to update the (Post)DominatorTrees.
568
- SmallPtrSet<BasicBlock *, 4 > RemovedSuccessors;
569
560
bool First = true ;
570
561
for (auto *Succ : successors (BB)) {
571
- if (!First || Succ != PreferredSucc->BB ) {
562
+ if (!First || Succ != PreferredSucc->BB )
572
563
Succ->removePredecessor (BB);
573
- RemovedSuccessors.insert (Succ);
574
- } else
564
+ else
575
565
First = false ;
576
566
}
577
567
makeUnconditional (BB, PreferredSucc->BB );
578
-
579
- // Inform the dominators about the deleted CFG edges.
580
- for (auto *Succ : RemovedSuccessors) {
581
- // It might have happened that the same successor appeared multiple times
582
- // and the CFG edge wasn't really removed.
583
- if (Succ != PreferredSucc->BB ) {
584
- DEBUG (dbgs () << " ADCE: Removing (Post)DomTree edge " << BB->getName ()
585
- << " -> " << Succ->getName () << " \n " );
586
- DT.deleteEdge (BB, Succ);
587
- PDT.deleteEdge (BB, Succ);
588
- }
589
- }
590
-
591
568
NumBranchesRemoved += 1 ;
592
569
}
593
570
}
@@ -632,9 +609,6 @@ void AggressiveDeadCodeElimination::makeUnconditional(BasicBlock *BB,
632
609
InstInfo[NewTerm].Live = true ;
633
610
if (const DILocation *DL = PredTerm->getDebugLoc ())
634
611
NewTerm->setDebugLoc (DL);
635
-
636
- InstInfo.erase (PredTerm);
637
- PredTerm->eraseFromParent ();
638
612
}
639
613
640
614
// ===----------------------------------------------------------------------===//
@@ -643,16 +617,13 @@ void AggressiveDeadCodeElimination::makeUnconditional(BasicBlock *BB,
643
617
//
644
618
// ===----------------------------------------------------------------------===//
645
619
PreservedAnalyses ADCEPass::run (Function &F, FunctionAnalysisManager &FAM) {
646
- auto &DT = FAM.getResult <DominatorTreeAnalysis>(F);
647
620
auto &PDT = FAM.getResult <PostDominatorTreeAnalysis>(F);
648
- if (!AggressiveDeadCodeElimination (F, DT, PDT).performDeadCodeElimination ())
621
+ if (!AggressiveDeadCodeElimination (F, PDT).performDeadCodeElimination ())
649
622
return PreservedAnalyses::all ();
650
623
651
624
PreservedAnalyses PA;
652
625
PA.preserveSet <CFGAnalyses>();
653
626
PA.preserve <GlobalsAA>();
654
- PA.preserve <DominatorTreeAnalysis>();
655
- PA.preserve <PostDominatorTreeAnalysis>();
656
627
return PA;
657
628
}
658
629
@@ -666,22 +637,15 @@ struct ADCELegacyPass : public FunctionPass {
666
637
bool runOnFunction (Function &F) override {
667
638
if (skipFunction (F))
668
639
return false ;
669
-
670
- auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree ();
671
640
auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree ();
672
- return AggressiveDeadCodeElimination (F, DT, PDT)
673
- .performDeadCodeElimination ();
641
+ return AggressiveDeadCodeElimination (F, PDT).performDeadCodeElimination ();
674
642
}
675
643
676
644
void getAnalysisUsage (AnalysisUsage &AU) const override {
677
- // We require DominatorTree here only to update and thus preserve it.
678
- AU.addRequired <DominatorTreeWrapperPass>();
679
645
AU.addRequired <PostDominatorTreeWrapperPass>();
680
646
if (!RemoveControlFlowFlag)
681
647
AU.setPreservesCFG ();
682
648
AU.addPreserved <GlobalsAAWrapperPass>();
683
- AU.addPreserved <DominatorTreeWrapperPass>();
684
- AU.addPreserved <PostDominatorTreeWrapperPass>();
685
649
}
686
650
};
687
651
}
0 commit comments