[Alignment] Migrate Attribute::getWith(Stack)Alignment
[llvm-core.git] / unittests / Transforms / Vectorize / VPlanTest.cpp
blob57567e7d8434b5a238e486bc8e1d35da20329b2b
1 //===- llvm/unittests/Transforms/Vectorize/VPlanTest.cpp - VPlan tests ----===//
2 //
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #include "../lib/Transforms/Vectorize/VPlan.h"
11 #include "llvm/IR/Instruction.h"
12 #include "llvm/IR/Instructions.h"
13 #include "gtest/gtest.h"
15 namespace llvm {
16 namespace {
18 #define CHECK_ITERATOR(Range1, ...) \
19 do { \
20 std::vector<VPInstruction *> Tmp = {__VA_ARGS__}; \
21 EXPECT_EQ((size_t)std::distance(Range1.begin(), Range1.end()), \
22 Tmp.size()); \
23 for (auto Pair : zip(Range1, make_range(Tmp.begin(), Tmp.end()))) \
24 EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
25 } while (0)
27 TEST(VPInstructionTest, insertBefore) {
28 VPInstruction *I1 = new VPInstruction(0, {});
29 VPInstruction *I2 = new VPInstruction(1, {});
30 VPInstruction *I3 = new VPInstruction(2, {});
32 VPBasicBlock VPBB1;
33 VPBB1.appendRecipe(I1);
35 I2->insertBefore(I1);
36 CHECK_ITERATOR(VPBB1, I2, I1);
38 I3->insertBefore(I2);
39 CHECK_ITERATOR(VPBB1, I3, I2, I1);
42 TEST(VPInstructionTest, eraseFromParent) {
43 VPInstruction *I1 = new VPInstruction(0, {});
44 VPInstruction *I2 = new VPInstruction(1, {});
45 VPInstruction *I3 = new VPInstruction(2, {});
47 VPBasicBlock VPBB1;
48 VPBB1.appendRecipe(I1);
49 VPBB1.appendRecipe(I2);
50 VPBB1.appendRecipe(I3);
52 I2->eraseFromParent();
53 CHECK_ITERATOR(VPBB1, I1, I3);
55 I1->eraseFromParent();
56 CHECK_ITERATOR(VPBB1, I3);
58 I3->eraseFromParent();
59 EXPECT_TRUE(VPBB1.empty());
62 TEST(VPInstructionTest, moveAfter) {
63 VPInstruction *I1 = new VPInstruction(0, {});
64 VPInstruction *I2 = new VPInstruction(1, {});
65 VPInstruction *I3 = new VPInstruction(2, {});
67 VPBasicBlock VPBB1;
68 VPBB1.appendRecipe(I1);
69 VPBB1.appendRecipe(I2);
70 VPBB1.appendRecipe(I3);
72 I1->moveAfter(I2);
74 CHECK_ITERATOR(VPBB1, I2, I1, I3);
76 VPInstruction *I4 = new VPInstruction(4, {});
77 VPInstruction *I5 = new VPInstruction(5, {});
78 VPBasicBlock VPBB2;
79 VPBB2.appendRecipe(I4);
80 VPBB2.appendRecipe(I5);
82 I3->moveAfter(I4);
84 CHECK_ITERATOR(VPBB1, I2, I1);
85 CHECK_ITERATOR(VPBB2, I4, I3, I5);
88 } // namespace
89 } // namespace llvm