12TEST(TopDownTraverserTests, testInitialization)
21 auto constant = TestOperation::createNode(&graph.
GetRootRegion(), {}, { vtype });
22 auto unary = TestOperation::createNode(&graph.
GetRootRegion(), { i }, { vtype });
24 TestOperation::createNode(&graph.
GetRootRegion(), { i, unary->output(0) }, { vtype });
30 bool unary_visited =
false;
31 bool binary_visited =
false;
32 bool constant_visited =
false;
38 constant_visited =
true;
39 if (node == binary && unary_visited)
40 binary_visited =
true;
43 EXPECT_TRUE(unary_visited);
44 EXPECT_TRUE(binary_visited);
45 EXPECT_TRUE(constant_visited);
74TEST(TopDownTraverserTests, testOrderEnforcement)
81 auto n1 = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type, type });
82 auto n2 = TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0) }, { type });
84 TestOperation::createNode(&graph.
GetRootRegion(), { n2->output(0), n1->output(1) }, { type });
97 EXPECT_EQ(tmp,
nullptr);
101TEST(TopDownTraverserTests, testInsertion)
140 auto n1 = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type, type });
142 TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0), n1->output(1) }, { type });
143 auto n3 = TestOperation::createNode(&graph.
GetRootRegion(), { n2->output(0) }, { type });
156 auto nX = TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0) }, { type });
157 n3->input(0)->divert_to(n1->output(1));
158 auto nY = TestOperation::createNode(&graph.
GetRootRegion(), { n3->output(0) }, { type });
160 n2->input(0)->divert_to(nX->output(0));
161 n2->input(1)->divert_to(nY->output(0));
163 graphExport.divert_to(n2->output(0));
172 EXPECT_EQ(node,
nullptr);
176TEST(TopDownTraverserTests, testInsertingTopNode)
194 auto n1 = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type });
195 auto n2 = TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0) }, { type });
201 auto node = trav.
next();
204 auto nX = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type });
205 n1->output(0)->divert_users(nX->output(0));
211 EXPECT_EQ(node,
nullptr);
214TEST(TopDownTraverserTests, testMutating)
223 bool seen_n1 =
false;
224 bool seen_n2 =
false;
225 bool seen_n3 =
false;
229 seen_n1 = seen_n1 || (tmp == n1);
230 seen_n2 = seen_n2 || (tmp == n2);
231 seen_n3 = seen_n3 || (tmp == n3);
232 if (n3->input(0)->origin() == n1->output(0))
233 n3->input(0)->divert_to(n2->output(0));
235 n3->input(0)->divert_to(n1->output(0));
238 EXPECT_TRUE(seen_n1);
239 EXPECT_TRUE(seen_n2);
240 EXPECT_TRUE(seen_n3);
245 auto n1 = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type });
246 auto n2 = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type });
247 auto n3 = TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0) }, {});
249 test(&graph, n1, n2, n3);
250 test(&graph, n1, n2, n3);
253TEST(TopDownTraverserTests, testReplacement)
273 auto n1 = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type });
274 auto n2 = TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0) }, { type });
275 auto n3 = TestOperation::createNode(&graph.
GetRootRegion(), { n2->output(0) }, { type });
276 auto n4 = TestOperation::createNode(&graph.
GetRootRegion(), { n3->output(0) }, { type });
277 auto n5 = TestOperation::createNode(&graph.
GetRootRegion(), { n2->output(0) }, { type });
283 auto node = trav.
next();
288 auto nX = TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0) }, { type });
289 auto nY = TestOperation::createNode(&graph.
GetRootRegion(), { nX->output(0) }, { type });
290 n3->output(0)->divert_users(nY->output(0));
291 n5->input(0)->divert_to(nX->output(0));
293 auto next1 = trav.
next();
294 auto next2 = trav.
next();
295 auto next3 = trav.
next();
296 EXPECT_TRUE(n3 == next1 || n3 == next2 || n3 == next3);
297 EXPECT_TRUE(n4 == next1 || n4 == next2 || n4 == next3);
298 EXPECT_TRUE(n5 == next1 || n5 == next2 || n5 == next3);
300 auto next4 = trav.
next();
301 EXPECT_EQ(next4,
nullptr);
353TEST(BottomUpTraverserTests, testOrderEnforcement)
359 auto n1 = TestOperation::createNode(&graph.
GetRootRegion(), {}, { type, type });
360 auto n2 = TestOperation::createNode(&graph.
GetRootRegion(), { n1->output(0) }, { type });
362 TestOperation::createNode(&graph.
GetRootRegion(), { n2->output(0), n1->output(1) }, { type });
375 EXPECT_EQ(tmp,
nullptr);