Recommit "[DSE] Preserve basic block ordering using OrderedBasicBlock."
Updated to use DenseMap::insert instead of [] operator for insertion, to
avoid a crash caused by epoch checks.
This reverts commit 2b85de438326f9d27bc96dc934ec98b98abdb337.
llvm-svn: 357257
diff --git a/llvm/lib/Analysis/OrderedBasicBlock.cpp b/llvm/lib/Analysis/OrderedBasicBlock.cpp
index 3cc6319..48f2a40 100644
--- a/llvm/lib/Analysis/OrderedBasicBlock.cpp
+++ b/llvm/lib/Analysis/OrderedBasicBlock.cpp
@@ -85,3 +85,27 @@
return comesBefore(A, B);
}
+
+void OrderedBasicBlock::eraseInstruction(const Instruction *I) {
+ if (LastInstFound != BB->end() && I == &*LastInstFound) {
+ if (LastInstFound == BB->begin()) {
+ LastInstFound = BB->end();
+ NextInstPos = 0;
+ } else
+ LastInstFound--;
+ }
+
+ NumberedInsts.erase(I);
+}
+
+void OrderedBasicBlock::replaceInstruction(const Instruction *Old,
+ const Instruction *New) {
+ auto OI = NumberedInsts.find(Old);
+ if (OI == NumberedInsts.end())
+ return;
+
+ NumberedInsts.insert({New, OI->second});
+ if (LastInstFound != BB->end() && Old == &*LastInstFound)
+ LastInstFound = New->getIterator();
+ NumberedInsts.erase(Old);
+}