[llvm] r334933 - [VPlanRecipeBase] Add insertBefore helper.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 18 04:34:17 PDT 2018
Author: fhahn
Date: Mon Jun 18 04:34:17 2018
New Revision: 334933
URL: http://llvm.org/viewvc/llvm-project?rev=334933&view=rev
Log:
[VPlanRecipeBase] Add insertBefore helper.
Reviewers: dcaballe, mkuper, hfinkel, hsaito, mssimpso
Reviewed By: dcaballe
Differential Revision: https://reviews.llvm.org/D48080
Added:
llvm/trunk/unittests/Transforms/Vectorize/
llvm/trunk/unittests/Transforms/Vectorize/CMakeLists.txt
llvm/trunk/unittests/Transforms/Vectorize/VPlanTest.cpp
Modified:
llvm/trunk/lib/Transforms/Vectorize/VPlan.cpp
llvm/trunk/lib/Transforms/Vectorize/VPlan.h
llvm/trunk/unittests/Transforms/CMakeLists.txt
Modified: llvm/trunk/lib/Transforms/Vectorize/VPlan.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/VPlan.cpp?rev=334933&r1=334932&r2=334933&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/VPlan.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/VPlan.cpp Mon Jun 18 04:34:17 2018
@@ -220,6 +220,11 @@ void VPRegionBlock::execute(VPTransformS
State->Instance.reset();
}
+void VPRecipeBase::insertBefore(VPRecipeBase *InsertPos) {
+ InsertPos->getParent()->getRecipeList().insert(InsertPos->getIterator(),
+ this);
+}
+
void VPInstruction::generateInstruction(VPTransformState &State,
unsigned Part) {
IRBuilder<> &Builder = State.Builder;
Modified: llvm/trunk/lib/Transforms/Vectorize/VPlan.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/VPlan.h?rev=334933&r1=334932&r2=334933&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/VPlan.h (original)
+++ llvm/trunk/lib/Transforms/Vectorize/VPlan.h Mon Jun 18 04:34:17 2018
@@ -552,6 +552,10 @@ public:
/// Each recipe prints itself.
virtual void print(raw_ostream &O, const Twine &Indent) const = 0;
+
+ /// Insert an unlinked recipe into a basic block immediately before
+ /// the specified recipe.
+ void insertBefore(VPRecipeBase *InsertPos);
};
/// This is a concrete Recipe that models a single VPlan-level instruction.
@@ -923,6 +927,9 @@ public:
inline const VPRecipeBase &back() const { return Recipes.back(); }
inline VPRecipeBase &back() { return Recipes.back(); }
+ /// Returns a reference to the list of recipes.
+ RecipeListTy &getRecipeList() { return Recipes; }
+
/// Returns a pointer to a member of the recipe list.
static RecipeListTy VPBasicBlock::*getSublistAccess(VPRecipeBase *) {
return &VPBasicBlock::Recipes;
Modified: llvm/trunk/unittests/Transforms/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/CMakeLists.txt?rev=334933&r1=334932&r2=334933&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Transforms/CMakeLists.txt Mon Jun 18 04:34:17 2018
@@ -1,3 +1,4 @@
add_subdirectory(IPO)
add_subdirectory(Scalar)
add_subdirectory(Utils)
+add_subdirectory(Vectorize)
Added: llvm/trunk/unittests/Transforms/Vectorize/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Vectorize/CMakeLists.txt?rev=334933&view=auto
==============================================================================
--- llvm/trunk/unittests/Transforms/Vectorize/CMakeLists.txt (added)
+++ llvm/trunk/unittests/Transforms/Vectorize/CMakeLists.txt Mon Jun 18 04:34:17 2018
@@ -0,0 +1,7 @@
+set(LLVM_LINK_COMPONENTS
+ Vectorize
+ )
+
+add_llvm_unittest(VectorizeTests
+ VPlanTest.cpp
+ )
Added: llvm/trunk/unittests/Transforms/Vectorize/VPlanTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Vectorize/VPlanTest.cpp?rev=334933&view=auto
==============================================================================
--- llvm/trunk/unittests/Transforms/Vectorize/VPlanTest.cpp (added)
+++ llvm/trunk/unittests/Transforms/Vectorize/VPlanTest.cpp Mon Jun 18 04:34:17 2018
@@ -0,0 +1,44 @@
+//===- llvm/unittests/Transforms/Vectorize/VPlanTest.cpp - VPlan tests ----===//
+//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../lib/Transforms/Vectorize/VPlan.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Instructions.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace {
+
+#define CHECK_ITERATOR(Range1, ...) \
+ do { \
+ std::vector<VPInstruction *> Tmp = {__VA_ARGS__}; \
+ EXPECT_EQ((size_t)std::distance(Range1.begin(), Range1.end()), \
+ Tmp.size()); \
+ for (auto Pair : zip(Range1, make_range(Tmp.begin(), Tmp.end()))) \
+ EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
+ } while (0)
+
+TEST(VPInstructionTest, insertBefore) {
+ VPInstruction *I1 = new VPInstruction(0, {});
+ VPInstruction *I2 = new VPInstruction(1, {});
+ VPInstruction *I3 = new VPInstruction(2, {});
+
+ VPBasicBlock VPBB1;
+ VPBB1.appendRecipe(I1);
+
+ I2->insertBefore(I1);
+ CHECK_ITERATOR(VPBB1, I2, I1);
+
+ I3->insertBefore(I2);
+ CHECK_ITERATOR(VPBB1, I3, I2, I1);
+}
+
+} // namespace
+} // namespace llvm
More information about the llvm-commits
mailing list