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 
18*cc9edaceSDuncan P. N. Exon Smith struct MyBundledInstr
19*cc9edaceSDuncan 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;
25f197b1f7SDuncan P. N. Exon Smith 
26f197b1f7SDuncan P. N. Exon Smith #ifdef GTEST_HAS_DEATH_TEST
27f197b1f7SDuncan P. N. Exon Smith #ifndef NDEBUG
28f197b1f7SDuncan P. N. Exon Smith TEST(MachineInstrBundleIteratorTest, CheckForBundles) {
29f197b1f7SDuncan P. N. Exon Smith   MyBundledInstr MBI;
30f197b1f7SDuncan P. N. Exon Smith 
31f197b1f7SDuncan P. N. Exon Smith   // Confirm that MBI is always considered bundled.
32f197b1f7SDuncan P. N. Exon Smith   EXPECT_TRUE(MBI.isBundledWithPred());
33f197b1f7SDuncan P. N. Exon Smith   EXPECT_TRUE(MBI.isBundledWithSucc());
34f197b1f7SDuncan P. N. Exon Smith 
35f197b1f7SDuncan P. N. Exon Smith   // Confirm that iterators check in their constructor for bundled iterators.
36f197b1f7SDuncan P. N. Exon Smith   EXPECT_DEATH((void)static_cast<bundled_iterator>(MBI),
37f197b1f7SDuncan P. N. Exon Smith                "not legal to initialize");
38f197b1f7SDuncan P. N. Exon Smith   EXPECT_DEATH((void)static_cast<bundled_iterator>(&MBI),
39f197b1f7SDuncan P. N. Exon Smith                "not legal to initialize");
40f197b1f7SDuncan P. N. Exon Smith   EXPECT_DEATH((void)static_cast<const_bundled_iterator>(MBI),
41f197b1f7SDuncan P. N. Exon Smith                "not legal to initialize");
42f197b1f7SDuncan P. N. Exon Smith   EXPECT_DEATH((void)static_cast<const_bundled_iterator>(&MBI),
43f197b1f7SDuncan P. N. Exon Smith                "not legal to initialize");
44f197b1f7SDuncan P. N. Exon Smith }
45f197b1f7SDuncan P. N. Exon Smith #endif
46f197b1f7SDuncan P. N. Exon Smith #endif
47f197b1f7SDuncan P. N. Exon Smith 
48f197b1f7SDuncan P. N. Exon Smith TEST(MachineInstrBundleIteratorTest, CompareToBundledMI) {
49f197b1f7SDuncan P. N. Exon Smith   MyBundledInstr MBI;
50f197b1f7SDuncan P. N. Exon Smith   const MyBundledInstr &CMBI = MBI;
51f197b1f7SDuncan P. N. Exon Smith   bundled_iterator I;
52f197b1f7SDuncan P. N. Exon Smith   const_bundled_iterator CI;
53f197b1f7SDuncan P. N. Exon Smith 
54f197b1f7SDuncan P. N. Exon Smith   // Confirm that MBI is always considered bundled.
55f197b1f7SDuncan P. N. Exon Smith   EXPECT_TRUE(MBI.isBundledWithPred());
56f197b1f7SDuncan P. N. Exon Smith   EXPECT_TRUE(MBI.isBundledWithSucc());
57f197b1f7SDuncan P. N. Exon Smith 
58f197b1f7SDuncan P. N. Exon Smith   // These invocations will crash when !NDEBUG if a conversion is taking place.
59f197b1f7SDuncan P. N. Exon Smith   // These checks confirm that comparison operators don't use any conversion
60f197b1f7SDuncan P. N. Exon Smith   // operators.
61f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(MBI == I);
62f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(&MBI == I);
63f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(CMBI == I);
64f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(&CMBI == I);
65f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(I == MBI);
66f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(I == &MBI);
67f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(I == CMBI);
68f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(I == &CMBI);
69f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(MBI == CI);
70f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(&MBI == CI);
71f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(CMBI == CI);
72f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(&CMBI == CI);
73f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(CI == MBI);
74f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(CI == &MBI);
75f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(CI == CMBI);
76f197b1f7SDuncan P. N. Exon Smith   ASSERT_FALSE(CI == &CMBI);
77f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(MBI != I);
78f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(&MBI != I);
79f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(CMBI != I);
80f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(&CMBI != I);
81f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(I != MBI);
82f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(I != &MBI);
83f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(I != CMBI);
84f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(I != &CMBI);
85f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(MBI != CI);
86f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(&MBI != CI);
87f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(CMBI != CI);
88f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(&CMBI != CI);
89f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(CI != MBI);
90f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(CI != &MBI);
91f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(CI != CMBI);
92f197b1f7SDuncan P. N. Exon Smith   ASSERT_TRUE(CI != &CMBI);
93f197b1f7SDuncan P. N. Exon Smith }
94f197b1f7SDuncan P. N. Exon Smith 
95f197b1f7SDuncan P. N. Exon Smith } // end namespace
96