1 //===- llvm/unittests/Transforms/Vectorize/VPlanTest.cpp - VPlan tests ----===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #include "../lib/Transforms/Vectorize/VPlan.h"
12 #include "llvm/IR/Instruction.h"
13 #include "llvm/IR/Instructions.h"
14 #include "gtest/gtest.h"
19 #define CHECK_ITERATOR(Range1, ...) \
21 std::vector<VPInstruction *> Tmp = {__VA_ARGS__}; \
22 EXPECT_EQ((size_t)std::distance(Range1.begin(), Range1.end()), \
24 for (auto Pair : zip(Range1, make_range(Tmp.begin(), Tmp.end()))) \
25 EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
28 TEST(VPInstructionTest
, insertBefore
) {
29 VPInstruction
*I1
= new VPInstruction(0, {});
30 VPInstruction
*I2
= new VPInstruction(1, {});
31 VPInstruction
*I3
= new VPInstruction(2, {});
34 VPBB1
.appendRecipe(I1
);
37 CHECK_ITERATOR(VPBB1
, I2
, I1
);
40 CHECK_ITERATOR(VPBB1
, I3
, I2
, I1
);
43 TEST(VPInstructionTest
, eraseFromParent
) {
44 VPInstruction
*I1
= new VPInstruction(0, {});
45 VPInstruction
*I2
= new VPInstruction(1, {});
46 VPInstruction
*I3
= new VPInstruction(2, {});
49 VPBB1
.appendRecipe(I1
);
50 VPBB1
.appendRecipe(I2
);
51 VPBB1
.appendRecipe(I3
);
53 I2
->eraseFromParent();
54 CHECK_ITERATOR(VPBB1
, I1
, I3
);
56 I1
->eraseFromParent();
57 CHECK_ITERATOR(VPBB1
, I3
);
59 I3
->eraseFromParent();
60 EXPECT_TRUE(VPBB1
.empty());