blob: 416f5774f4c68cee0723b083a1a1b52ce0977e74 [file] [log] [blame]
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +00001//===- 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
14using namespace llvm;
15
16namespace {
17
Duncan P. N. Exon Smithcc9edac2016-09-11 16:38:18 +000018struct MyBundledInstr
19 : public ilist_node<MyBundledInstr, ilist_sentinel_tracking<true>> {
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000020 bool isBundledWithPred() const { return true; }
21 bool isBundledWithSucc() const { return true; }
22};
23typedef MachineInstrBundleIterator<MyBundledInstr> bundled_iterator;
24typedef MachineInstrBundleIterator<const MyBundledInstr> const_bundled_iterator;
Duncan P. N. Exon Smith18720962016-09-11 18:51:28 +000025typedef MachineInstrBundleIterator<MyBundledInstr, true>
26 reverse_bundled_iterator;
27typedef MachineInstrBundleIterator<const MyBundledInstr, true>
28 const_reverse_bundled_iterator;
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000029
30#ifdef GTEST_HAS_DEATH_TEST
31#ifndef NDEBUG
32TEST(MachineInstrBundleIteratorTest, CheckForBundles) {
33 MyBundledInstr MBI;
Duncan P. N. Exon Smith18720962016-09-11 18:51:28 +000034 auto I = MBI.getIterator();
35 auto RI = I.getReverse();
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000036
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.
Duncan P. N. Exon Smith18720962016-09-11 18:51:28 +000042 EXPECT_DEATH((void)static_cast<bundled_iterator>(I),
43 "not legal to initialize");
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000044 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");
Duncan P. N. Exon Smith18720962016-09-11 18:51:28 +000048 EXPECT_DEATH((void)static_cast<const_bundled_iterator>(I),
49 "not legal to initialize");
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000050 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");
Duncan P. N. Exon Smith18720962016-09-11 18:51:28 +000054 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");
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000066}
67#endif
68#endif
69
70TEST(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);
Duncan P. N. Exon Smith3b22b182016-09-11 17:12:28 +000099 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());
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +0000107 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);
Duncan P. N. Exon Smith3b22b182016-09-11 17:12:28 +0000123 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());
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +0000131}
132
133} // end namespace