summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/IPO/Attributor.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index a6e8e528fd0..a2d470affc0 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2641,6 +2641,26 @@ ChangeStatus Attributor::run() {
assert(
NumFinalAAs == AllAbstractAttributes.size() &&
"Expected the final number of abstract attributes to remain unchanged!");
+
+ // Delete stuff at the end to avoid invalid references and a nice order.
+ LLVM_DEBUG(dbgs() << "\n[Attributor] Delete " << ToBeDeletedFunctions.size()
+ << " functions and " << ToBeDeletedBlocks.size()
+ << " blocks and " << ToBeDeletedInsts.size()
+ << " instructions\n");
+ for (Instruction *I : ToBeDeletedInsts) {
+ if (I->hasNUsesOrMore(1))
+ I->replaceAllUsesWith(UndefValue::get(I->getType()));
+ I->eraseFromParent();
+ }
+ for (BasicBlock *BB : ToBeDeletedBlocks) {
+ // TODO: Check if we need to replace users (PHIs, indirect branches?)
+ BB->eraseFromParent();
+ }
+ for (Function *Fn : ToBeDeletedFunctions) {
+ Fn->replaceAllUsesWith(UndefValue::get(Fn->getType()));
+ Fn->eraseFromParent();
+ }
+
return ManifestChange;
}
OpenPOWER on IntegriCloud