/// 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.
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;
--- /dev/null
+//===- 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