1f197b1f7SDuncan P. N. Exon Smith //===- MachineInstrBundleIteratorTest.cpp ---------------------------------===// 2f197b1f7SDuncan P. N. Exon Smith // 3f197b1f7SDuncan P. N. Exon Smith // The LLVM Compiler Infrastructure 4f197b1f7SDuncan P. N. Exon Smith // 5f197b1f7SDuncan P. N. Exon Smith // This file is distributed under the University of Illinois Open Source 6f197b1f7SDuncan P. N. Exon Smith // License. See LICENSE.TXT for details. 7f197b1f7SDuncan P. N. Exon Smith // 8f197b1f7SDuncan P. N. Exon Smith //===----------------------------------------------------------------------===// 9f197b1f7SDuncan P. N. Exon Smith 10f197b1f7SDuncan P. N. Exon Smith #include "llvm/ADT/ilist_node.h" 11f197b1f7SDuncan P. N. Exon Smith #include "llvm/CodeGen/MachineInstrBundleIterator.h" 12f197b1f7SDuncan P. N. Exon Smith #include "gtest/gtest.h" 13f197b1f7SDuncan P. N. Exon Smith 14f197b1f7SDuncan P. N. Exon Smith using namespace llvm; 15f197b1f7SDuncan P. N. Exon Smith 16f197b1f7SDuncan P. N. Exon Smith namespace { 17f197b1f7SDuncan P. N. Exon Smith 18cc9edaceSDuncan P. N. Exon Smith struct MyBundledInstr 19cc9edaceSDuncan P. N. Exon Smith : public ilist_node<MyBundledInstr, ilist_sentinel_tracking<true>> { 20f197b1f7SDuncan P. N. Exon Smith bool isBundledWithPred() const { return true; } 21f197b1f7SDuncan P. N. Exon Smith bool isBundledWithSucc() const { return true; } 22f197b1f7SDuncan P. N. Exon Smith }; 23f197b1f7SDuncan P. N. Exon Smith typedef MachineInstrBundleIterator<MyBundledInstr> bundled_iterator; 24f197b1f7SDuncan P. N. Exon Smith typedef MachineInstrBundleIterator<const MyBundledInstr> const_bundled_iterator; 25*1872096fSDuncan P. N. Exon Smith typedef MachineInstrBundleIterator<MyBundledInstr, true> 26*1872096fSDuncan P. N. Exon Smith reverse_bundled_iterator; 27*1872096fSDuncan P. N. Exon Smith typedef MachineInstrBundleIterator<const MyBundledInstr, true> 28*1872096fSDuncan P. N. Exon Smith const_reverse_bundled_iterator; 29f197b1f7SDuncan P. N. Exon Smith 30f197b1f7SDuncan P. N. Exon Smith #ifdef GTEST_HAS_DEATH_TEST 31f197b1f7SDuncan P. N. Exon Smith #ifndef NDEBUG 32f197b1f7SDuncan P. N. Exon Smith TEST(MachineInstrBundleIteratorTest, CheckForBundles) { 33f197b1f7SDuncan P. N. Exon Smith MyBundledInstr MBI; 34*1872096fSDuncan P. N. Exon Smith auto I = MBI.getIterator(); 35*1872096fSDuncan P. N. Exon Smith auto RI = I.getReverse(); 36f197b1f7SDuncan P. N. Exon Smith 37f197b1f7SDuncan P. N. Exon Smith // Confirm that MBI is always considered bundled. 38f197b1f7SDuncan P. N. Exon Smith EXPECT_TRUE(MBI.isBundledWithPred()); 39f197b1f7SDuncan P. N. Exon Smith EXPECT_TRUE(MBI.isBundledWithSucc()); 40f197b1f7SDuncan P. N. Exon Smith 41f197b1f7SDuncan P. N. Exon Smith // Confirm that iterators check in their constructor for bundled iterators. 42*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<bundled_iterator>(I), 43*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 44f197b1f7SDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<bundled_iterator>(MBI), 45f197b1f7SDuncan P. N. Exon Smith "not legal to initialize"); 46f197b1f7SDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<bundled_iterator>(&MBI), 47f197b1f7SDuncan P. N. Exon Smith "not legal to initialize"); 48*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<const_bundled_iterator>(I), 49*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 50f197b1f7SDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<const_bundled_iterator>(MBI), 51f197b1f7SDuncan P. N. Exon Smith "not legal to initialize"); 52f197b1f7SDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<const_bundled_iterator>(&MBI), 53f197b1f7SDuncan P. N. Exon Smith "not legal to initialize"); 54*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<reverse_bundled_iterator>(RI), 55*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 56*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<reverse_bundled_iterator>(MBI), 57*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 58*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<reverse_bundled_iterator>(&MBI), 59*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 60*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<const_reverse_bundled_iterator>(RI), 61*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 62*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<const_reverse_bundled_iterator>(MBI), 63*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 64*1872096fSDuncan P. N. Exon Smith EXPECT_DEATH((void)static_cast<const_reverse_bundled_iterator>(&MBI), 65*1872096fSDuncan P. N. Exon Smith "not legal to initialize"); 66f197b1f7SDuncan P. N. Exon Smith } 67f197b1f7SDuncan P. N. Exon Smith #endif 68f197b1f7SDuncan P. N. Exon Smith #endif 69f197b1f7SDuncan P. N. Exon Smith 70f197b1f7SDuncan P. N. Exon Smith TEST(MachineInstrBundleIteratorTest, CompareToBundledMI) { 71f197b1f7SDuncan P. N. Exon Smith MyBundledInstr MBI; 72f197b1f7SDuncan P. N. Exon Smith const MyBundledInstr &CMBI = MBI; 73f197b1f7SDuncan P. N. Exon Smith bundled_iterator I; 74f197b1f7SDuncan P. N. Exon Smith const_bundled_iterator CI; 75f197b1f7SDuncan P. N. Exon Smith 76f197b1f7SDuncan P. N. Exon Smith // Confirm that MBI is always considered bundled. 77f197b1f7SDuncan P. N. Exon Smith EXPECT_TRUE(MBI.isBundledWithPred()); 78f197b1f7SDuncan P. N. Exon Smith EXPECT_TRUE(MBI.isBundledWithSucc()); 79f197b1f7SDuncan P. N. Exon Smith 80f197b1f7SDuncan P. N. Exon Smith // These invocations will crash when !NDEBUG if a conversion is taking place. 81f197b1f7SDuncan P. N. Exon Smith // These checks confirm that comparison operators don't use any conversion 82f197b1f7SDuncan P. N. Exon Smith // operators. 83f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(MBI == I); 84f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(&MBI == I); 85f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(CMBI == I); 86f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(&CMBI == I); 87f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(I == MBI); 88f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(I == &MBI); 89f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(I == CMBI); 90f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(I == &CMBI); 91f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(MBI == CI); 92f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(&MBI == CI); 93f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(CMBI == CI); 94f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(&CMBI == CI); 95f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(CI == MBI); 96f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(CI == &MBI); 97f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(CI == CMBI); 98f197b1f7SDuncan P. N. Exon Smith ASSERT_FALSE(CI == &CMBI); 993b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(MBI.getIterator() == I); 1003b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(CMBI.getIterator() == I); 1013b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(I == MBI.getIterator()); 1023b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(I == CMBI.getIterator()); 1033b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(MBI.getIterator() == CI); 1043b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(CMBI.getIterator() == CI); 1053b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(CI == MBI.getIterator()); 1063b22b181SDuncan P. N. Exon Smith ASSERT_FALSE(CI == CMBI.getIterator()); 107f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(MBI != I); 108f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(&MBI != I); 109f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(CMBI != I); 110f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(&CMBI != I); 111f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(I != MBI); 112f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(I != &MBI); 113f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(I != CMBI); 114f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(I != &CMBI); 115f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(MBI != CI); 116f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(&MBI != CI); 117f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(CMBI != CI); 118f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(&CMBI != CI); 119f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(CI != MBI); 120f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(CI != &MBI); 121f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(CI != CMBI); 122f197b1f7SDuncan P. N. Exon Smith ASSERT_TRUE(CI != &CMBI); 1233b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(MBI.getIterator() != I); 1243b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(CMBI.getIterator() != I); 1253b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(I != MBI.getIterator()); 1263b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(I != CMBI.getIterator()); 1273b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(MBI.getIterator() != CI); 1283b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(CMBI.getIterator() != CI); 1293b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(CI != MBI.getIterator()); 1303b22b181SDuncan P. N. Exon Smith ASSERT_TRUE(CI != CMBI.getIterator()); 131f197b1f7SDuncan P. N. Exon Smith } 132f197b1f7SDuncan P. N. Exon Smith 133f197b1f7SDuncan P. N. Exon Smith } // end namespace 134