From 63cbcf98a547ed16f89b5c80f7e401849abad3b2 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Mon, 18 Jun 2018 15:18:48 +0000 Subject: [PATCH] [VPlanRecipeBase] Add eraseFromParent(). Reviewers: dcaballe, hsaito, mkuper, hfinkel Reviewed By: dcaballe Differential Revision: https://reviews.llvm.org/D48081 llvm-svn: 334951 --- llvm/lib/Transforms/Vectorize/VPlan.cpp | 4 ++++ llvm/lib/Transforms/Vectorize/VPlan.h | 5 +++++ .../Transforms/Vectorize/VPlanTest.cpp | 20 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp index ea9ad199907a..1f58bed5257d 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -225,6 +225,10 @@ void VPRecipeBase::insertBefore(VPRecipeBase *InsertPos) { Parent->getRecipeList().insert(InsertPos->getIterator(), this); } +iplist::iterator VPRecipeBase::eraseFromParent() { + return getParent()->getRecipeList().erase(getIterator()); +} + void VPInstruction::generateInstruction(VPTransformState &State, unsigned Part) { IRBuilder<> &Builder = State.Builder; diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h index c19fbe28196b..0eefa0cea42b 100644 --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -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::iterator eraseFromParent(); }; /// This is a concrete Recipe that models a single VPlan-level instruction. diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp index 761f7d796643..67712a7cae2e 100644 --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -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