VPlanTest.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. //===----------------------------------------------------------------------===//
  9. #include "../lib/Transforms/Vectorize/VPlan.h"
  10. #include "llvm/IR/Instruction.h"
  11. #include "llvm/IR/Instructions.h"
  12. #include "gtest/gtest.h"
  13. namespace llvm {
  14. namespace {
  15. #define CHECK_ITERATOR(Range1, ...) \
  16. do { \
  17. std::vector<VPInstruction *> Tmp = {__VA_ARGS__}; \
  18. EXPECT_EQ((size_t)std::distance(Range1.begin(), Range1.end()), \
  19. Tmp.size()); \
  20. for (auto Pair : zip(Range1, make_range(Tmp.begin(), Tmp.end()))) \
  21. EXPECT_EQ(&std::get<0>(Pair), std::get<1>(Pair)); \
  22. } while (0)
  23. TEST(VPInstructionTest, insertBefore) {
  24. VPInstruction *I1 = new VPInstruction(0, {});
  25. VPInstruction *I2 = new VPInstruction(1, {});
  26. VPInstruction *I3 = new VPInstruction(2, {});
  27. VPBasicBlock VPBB1;
  28. VPBB1.appendRecipe(I1);
  29. I2->insertBefore(I1);
  30. CHECK_ITERATOR(VPBB1, I2, I1);
  31. I3->insertBefore(I2);
  32. CHECK_ITERATOR(VPBB1, I3, I2, I1);
  33. }
  34. TEST(VPInstructionTest, eraseFromParent) {
  35. VPInstruction *I1 = new VPInstruction(0, {});
  36. VPInstruction *I2 = new VPInstruction(1, {});
  37. VPInstruction *I3 = new VPInstruction(2, {});
  38. VPBasicBlock VPBB1;
  39. VPBB1.appendRecipe(I1);
  40. VPBB1.appendRecipe(I2);
  41. VPBB1.appendRecipe(I3);
  42. I2->eraseFromParent();
  43. CHECK_ITERATOR(VPBB1, I1, I3);
  44. I1->eraseFromParent();
  45. CHECK_ITERATOR(VPBB1, I3);
  46. I3->eraseFromParent();
  47. EXPECT_TRUE(VPBB1.empty());
  48. }
  49. } // namespace
  50. } // namespace llvm