blob: 67712a7cae2e35ff9feb18868794ebb5d6badbed [file] [log] [blame]
Florian Hahn7591e4e2018-06-18 11:34:17 +00001//===- 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//===----------------------------------------------------------------------===//
10
11#include "../lib/Transforms/Vectorize/VPlan.h"
12#include "llvm/IR/Instruction.h"
13#include "llvm/IR/Instructions.h"
14#include "gtest/gtest.h"
15
16namespace llvm {
17namespace {
18
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)
27
28TEST(VPInstructionTest, insertBefore) {
29 VPInstruction *I1 = new VPInstruction(0, {});
30 VPInstruction *I2 = new VPInstruction(1, {});
31 VPInstruction *I3 = new VPInstruction(2, {});
32
33 VPBasicBlock VPBB1;
34 VPBB1.appendRecipe(I1);
35
36 I2->insertBefore(I1);
37 CHECK_ITERATOR(VPBB1, I2, I1);
38
39 I3->insertBefore(I2);
40 CHECK_ITERATOR(VPBB1, I3, I2, I1);
41}
42
Florian Hahn63cbcf92018-06-18 15:18:48 +000043TEST(VPInstructionTest, eraseFromParent) {
44 VPInstruction *I1 = new VPInstruction(0, {});
45 VPInstruction *I2 = new VPInstruction(1, {});
46 VPInstruction *I3 = new VPInstruction(2, {});
47
48 VPBasicBlock VPBB1;
49 VPBB1.appendRecipe(I1);
50 VPBB1.appendRecipe(I2);
51 VPBB1.appendRecipe(I3);
52
53 I2->eraseFromParent();
54 CHECK_ITERATOR(VPBB1, I1, I3);
55
56 I1->eraseFromParent();
57 CHECK_ITERATOR(VPBB1, I3);
58
59 I3->eraseFromParent();
60 EXPECT_TRUE(VPBB1.empty());
61}
62
Florian Hahn7591e4e2018-06-18 11:34:17 +000063} // namespace
64} // namespace llvm