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