VPlanTest.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. TEST(VPInstructionTest, moveAfter) {
  50. VPInstruction *I1 = new VPInstruction(0, {});
  51. VPInstruction *I2 = new VPInstruction(1, {});
  52. VPInstruction *I3 = new VPInstruction(2, {});
  53. VPBasicBlock VPBB1;
  54. VPBB1.appendRecipe(I1);
  55. VPBB1.appendRecipe(I2);
  56. VPBB1.appendRecipe(I3);
  57. I1->moveAfter(I2);
  58. CHECK_ITERATOR(VPBB1, I2, I1, I3);
  59. VPInstruction *I4 = new VPInstruction(4, {});
  60. VPInstruction *I5 = new VPInstruction(5, {});
  61. VPBasicBlock VPBB2;
  62. VPBB2.appendRecipe(I4);
  63. VPBB2.appendRecipe(I5);
  64. I3->moveAfter(I4);
  65. CHECK_ITERATOR(VPBB1, I2, I1);
  66. CHECK_ITERATOR(VPBB2, I4, I3, I5);
  67. }
  68. } // namespace
  69. } // namespace llvm