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