OSDN Git Service

[VPlanRecipeBase] Add eraseFromParent().
authorFlorian Hahn <florian.hahn@arm.com>
Mon, 18 Jun 2018 15:18:48 +0000 (15:18 +0000)
committerFlorian Hahn <florian.hahn@arm.com>
Mon, 18 Jun 2018 15:18:48 +0000 (15:18 +0000)
Reviewers: dcaballe, hsaito, mkuper, hfinkel

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D48081

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334951 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Vectorize/VPlan.cpp
lib/Transforms/Vectorize/VPlan.h
unittests/Transforms/Vectorize/VPlanTest.cpp

index ea9ad19..1f58bed 100644 (file)
@@ -225,6 +225,10 @@ void VPRecipeBase::insertBefore(VPRecipeBase *InsertPos) {
   Parent->getRecipeList().insert(InsertPos->getIterator(), this);
 }
 
+iplist<VPRecipeBase>::iterator VPRecipeBase::eraseFromParent() {
+  return getParent()->getRecipeList().erase(getIterator());
+}
+
 void VPInstruction::generateInstruction(VPTransformState &State,
                                         unsigned Part) {
   IRBuilder<> &Builder = State.Builder;
index c19fbe2..0eefa0c 100644 (file)
@@ -556,6 +556,11 @@ public:
   /// Insert an unlinked recipe into a basic block immediately before
   /// the specified recipe.
   void insertBefore(VPRecipeBase *InsertPos);
+
+  /// This method unlinks 'this' from the containing basic block and deletes it.
+  ///
+  /// \returns an iterator pointing to the element after the erased one
+  iplist<VPRecipeBase>::iterator eraseFromParent();
 };
 
 /// This is a concrete Recipe that models a single VPlan-level instruction.
index 761f7d7..67712a7 100644 (file)
@@ -40,5 +40,25 @@ TEST(VPInstructionTest, insertBefore) {
   CHECK_ITERATOR(VPBB1, I3, I2, I1);
 }
 
+TEST(VPInstructionTest, eraseFromParent) {
+  VPInstruction *I1 = new VPInstruction(0, {});
+  VPInstruction *I2 = new VPInstruction(1, {});
+  VPInstruction *I3 = new VPInstruction(2, {});
+
+  VPBasicBlock VPBB1;
+  VPBB1.appendRecipe(I1);
+  VPBB1.appendRecipe(I2);
+  VPBB1.appendRecipe(I3);
+
+  I2->eraseFromParent();
+  CHECK_ITERATOR(VPBB1, I1, I3);
+
+  I1->eraseFromParent();
+  CHECK_ITERATOR(VPBB1, I3);
+
+  I3->eraseFromParent();
+  EXPECT_TRUE(VPBB1.empty());
+}
+
 } // namespace
 } // namespace llvm