[llvm-exegesis][NFC] Return many CodeTemplates instead of one.
[llvm-complete.git] / unittests / Transforms / Vectorize / VPlanTest.cpp
blob67712a7cae2e35ff9feb18868794ebb5d6badbed
1 //===- llvm/unittests/Transforms/Vectorize/VPlanTest.cpp - VPlan tests ----===//
2 //
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
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"
16 namespace llvm {
17 namespace {
19 #define CHECK_ITERATOR(Range1, ...) \
20 do { \
21 std::vector<VPInstruction *> Tmp = {__VA_ARGS__}; \
22 EXPECT_EQ((size_t)std::distance(Range1.begin(), Range1.end()), \
23 Tmp.size()); \
24 for (auto Pair : zip(Range1, make_range(Tmp.begin(), Tmp.end()))) \
25 EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
26 } while (0)
28 TEST(VPInstructionTest, insertBefore) {
29 VPInstruction *I1 = new VPInstruction(0, {});
30 VPInstruction *I2 = new VPInstruction(1, {});
31 VPInstruction *I3 = new VPInstruction(2, {});
33 VPBasicBlock VPBB1;
34 VPBB1.appendRecipe(I1);
36 I2->insertBefore(I1);
37 CHECK_ITERATOR(VPBB1, I2, I1);
39 I3->insertBefore(I2);
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, {});
48 VPBasicBlock VPBB1;
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());
63 } // namespace
64 } // namespace llvm