[PATCH] D74583: Fix Block::eraseArgument when block arg is also a successor operand.

Sean Silva via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 09:32:05 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGe84aa5922b1c: Fix Block::eraseArgument when block arg is also a successor operand. (authored by silvas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74583/new/

https://reviews.llvm.org/D74583

Files:
  mlir/lib/IR/Block.cpp


Index: mlir/lib/IR/Block.cpp
===================================================================
--- mlir/lib/IR/Block.cpp
+++ mlir/lib/IR/Block.cpp
@@ -170,20 +170,21 @@
 void Block::eraseArgument(unsigned index, bool updatePredTerms) {
   assert(index < arguments.size());
 
+  // If requested, update predecessors. We do this first since this block might
+  // be a predecessor of itself and use this block argument as a successor
+  // operand.
+  if (updatePredTerms) {
+    // Erase this argument from each of the predecessor's terminator.
+    for (auto predIt = pred_begin(), predE = pred_end(); predIt != predE;
+         ++predIt) {
+      auto *predTerminator = (*predIt)->getTerminator();
+      predTerminator->eraseSuccessorOperand(predIt.getSuccessorIndex(), index);
+    }
+  }
+
   // Delete the argument.
   arguments[index].destroy();
   arguments.erase(arguments.begin() + index);
-
-  // If we aren't updating predecessors, there is nothing left to do.
-  if (!updatePredTerms)
-    return;
-
-  // Erase this argument from each of the predecessor's terminator.
-  for (auto predIt = pred_begin(), predE = pred_end(); predIt != predE;
-       ++predIt) {
-    auto *predTerminator = (*predIt)->getTerminator();
-    predTerminator->eraseSuccessorOperand(predIt.getSuccessorIndex(), index);
-  }
 }
 
 /// Insert one value to the given position of the argument list. The existing


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74583.245440.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200219/f868d0b3/attachment.bin>


More information about the llvm-commits mailing list