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