69
69
#include " llvm/Support/Compiler.h"
70
70
#include " llvm/Support/Debug.h"
71
71
#include " llvm/Support/raw_ostream.h"
72
- #include " llvm/Transforms/Utils/AssumeBundleBuilder.h"
73
72
#include " llvm/Transforms/Utils/BasicBlockUtils.h"
74
73
#include " llvm/Transforms/Utils/Local.h"
75
74
#include " llvm/Transforms/Utils/SSAUpdater.h"
@@ -728,8 +727,9 @@ void GVNPass::ValueTable::erase(Value *V) {
728
727
// / verifyRemoved - Verify that the value is removed from all internal data
729
728
// / structures.
730
729
void GVNPass::ValueTable::verifyRemoved (const Value *V) const {
731
- assert (!ValueNumbering.contains (V) &&
732
- " Inst still occurs in value numbering map!" );
730
+ if (V != nullptr )
731
+ assert (!ValueNumbering.contains (V) &&
732
+ " Inst still occurs in value numbering map!" );
733
733
}
734
734
735
735
// ===----------------------------------------------------------------------===//
@@ -1572,11 +1572,11 @@ void GVNPass::eliminatePartiallyRedundantLoad(
1572
1572
I->setDebugLoc (Load->getDebugLoc ());
1573
1573
if (V->getType ()->isPtrOrPtrVectorTy ())
1574
1574
MD->invalidateCachedPointerInfo (V);
1575
- markInstructionForDeletion (Load);
1576
1575
ORE->emit ([&]() {
1577
1576
return OptimizationRemark (DEBUG_TYPE, " LoadPRE" , Load)
1578
1577
<< " load eliminated by PRE" ;
1579
1578
});
1579
+ doInstructionDeletion (Load);
1580
1580
}
1581
1581
1582
1582
bool GVNPass::PerformLoadPRE (LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
@@ -1795,7 +1795,7 @@ bool GVNPass::PerformLoadPRE(LoadInst *Load, AvailValInBlkVect &ValuesPerBlock,
1795
1795
// Erase instructions generated by the failed PHI translation before
1796
1796
// trying to number them. PHI translation might insert instructions
1797
1797
// in basic blocks other than the current one, and we delete them
1798
- // directly, as markInstructionForDeletion only allows removing from the
1798
+ // directly, as doInstructionDeletion only allows removing from the
1799
1799
// current basic block.
1800
1800
NewInsts.pop_back_val ()->eraseFromParent ();
1801
1801
}
@@ -1994,7 +1994,7 @@ bool GVNPass::processNonLocalLoad(LoadInst *Load) {
1994
1994
I->setDebugLoc (Load->getDebugLoc ());
1995
1995
if (V->getType ()->isPtrOrPtrVectorTy ())
1996
1996
MD->invalidateCachedPointerInfo (V);
1997
- markInstructionForDeletion (Load);
1997
+ doInstructionDeletion (Load);
1998
1998
++NumGVNLoad;
1999
1999
reportLoadElim (Load, V, ORE);
2000
2000
return true ;
@@ -2064,7 +2064,7 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {
2064
2064
}
2065
2065
}
2066
2066
if (isAssumeWithEmptyBundle (*IntrinsicI)) {
2067
- markInstructionForDeletion (IntrinsicI);
2067
+ doInstructionDeletion (IntrinsicI);
2068
2068
return true ;
2069
2069
}
2070
2070
return false ;
@@ -2175,7 +2175,7 @@ bool GVNPass::processLoad(LoadInst *L) {
2175
2175
return false ;
2176
2176
2177
2177
if (L->use_empty ()) {
2178
- markInstructionForDeletion (L);
2178
+ doInstructionDeletion (L);
2179
2179
return true ;
2180
2180
}
2181
2181
@@ -2205,13 +2205,13 @@ bool GVNPass::processLoad(LoadInst *L) {
2205
2205
// MaterializeAdjustedValue is responsible for combining metadata.
2206
2206
ICF->removeUsersOf (L);
2207
2207
L->replaceAllUsesWith (AvailableValue);
2208
- markInstructionForDeletion (L);
2209
2208
if (MSSAU)
2210
2209
MSSAU->removeMemoryAccess (L);
2211
2210
++NumGVNLoad;
2212
2211
reportLoadElim (L, AvailableValue, ORE);
2213
2212
// Tell MDA to reexamine the reused pointer since we might have more
2214
2213
// information after forwarding it.
2214
+ doInstructionDeletion (L);
2215
2215
if (MD && AvailableValue->getType ()->isPtrOrPtrVectorTy ())
2216
2216
MD->invalidateCachedPointerInfo (AvailableValue);
2217
2217
return true ;
@@ -2601,7 +2601,7 @@ bool GVNPass::processInstruction(Instruction *I) {
2601
2601
Changed = true ;
2602
2602
}
2603
2603
if (isInstructionTriviallyDead (I, TLI)) {
2604
- markInstructionForDeletion (I);
2604
+ doInstructionDeletion (I);
2605
2605
Changed = true ;
2606
2606
}
2607
2607
if (Changed) {
@@ -2718,7 +2718,7 @@ bool GVNPass::processInstruction(Instruction *I) {
2718
2718
patchAndReplaceAllUsesWith (I, Repl);
2719
2719
if (MD && Repl->getType ()->isPtrOrPtrVectorTy ())
2720
2720
MD->invalidateCachedPointerInfo (Repl);
2721
- markInstructionForDeletion (I);
2721
+ doInstructionDeletion (I);
2722
2722
return true ;
2723
2723
}
2724
2724
@@ -2794,10 +2794,6 @@ bool GVNPass::runImpl(Function &F, AssumptionCache &RunAC, DominatorTree &RunDT,
2794
2794
}
2795
2795
2796
2796
bool GVNPass::processBlock (BasicBlock *BB) {
2797
- // FIXME: Kill off InstrsToErase by doing erasing eagerly in a helper function
2798
- // (and incrementing BI before processing an instruction).
2799
- assert (InstrsToErase.empty () &&
2800
- " We expect InstrsToErase to be empty across iterations" );
2801
2797
if (DeadBlocks.count (BB))
2802
2798
return false ;
2803
2799
@@ -2815,41 +2811,11 @@ bool GVNPass::processBlock(BasicBlock *BB) {
2815
2811
VN.erase (PN);
2816
2812
removeInstruction (PN);
2817
2813
}
2818
-
2819
- for (BasicBlock::iterator BI = BB->begin (), BE = BB->end ();
2820
- BI != BE;) {
2814
+ for (Instruction &Inst : make_early_inc_range (*BB)) {
2821
2815
if (!ReplaceOperandsWithMap.empty ())
2822
- ChangedFunction |= replaceOperandsForInBlockEquality (&*BI);
2823
- ChangedFunction |= processInstruction (&*BI);
2824
-
2825
- if (InstrsToErase.empty ()) {
2826
- ++BI;
2827
- continue ;
2828
- }
2829
-
2830
- // If we need some instructions deleted, do it now.
2831
- NumGVNInstr += InstrsToErase.size ();
2832
-
2833
- // Avoid iterator invalidation.
2834
- bool AtStart = BI == BB->begin ();
2835
- if (!AtStart)
2836
- --BI;
2837
-
2838
- for (auto *I : InstrsToErase) {
2839
- assert (I->getParent () == BB && " Removing instruction from wrong block?" );
2840
- LLVM_DEBUG (dbgs () << " GVN removed: " << *I << ' \n ' );
2841
- salvageKnowledge (I, AC);
2842
- salvageDebugInfo (*I);
2843
- removeInstruction (I);
2844
- }
2845
- InstrsToErase.clear ();
2846
-
2847
- if (AtStart)
2848
- BI = BB->begin ();
2849
- else
2850
- ++BI;
2816
+ ChangedFunction |= replaceOperandsForInBlockEquality (&Inst);
2817
+ ChangedFunction |= processInstruction (&Inst);
2851
2818
}
2852
-
2853
2819
return ChangedFunction;
2854
2820
}
2855
2821
0 commit comments