47 auto theta = ThetaNode::create(&graph->GetRootRegion());
48 auto subregion = theta->subregion();
49 auto idv = theta->AddLoopVar(init);
50 auto lvs = theta->AddLoopVar(step);
51 auto lve = theta->AddLoopVar(end);
53 auto arm = SimpleNode::Create(*subregion, aop.
copy(), { idv.pre, lvs.pre }).output(0);
54 auto cmp = SimpleNode::Create(*subregion, cop.
copy(), { arm, lve.pre }).output(0);
55 auto & matchNode = MatchOperation::CreateNode(*cmp, { { 1, 1 } }, 0, 2);
57 idv.post->divert_to(arm);
58 theta->set_predicate(matchNode.output(0));
63TEST(LoopUnrollingTests, test_unrollinfo)
82 EXPECT_NE(ui,
nullptr);
83 EXPECT_TRUE(ui->is_additive());
84 EXPECT_FALSE(ui->is_subtractive());
85 EXPECT_FALSE(ui->is_known());
86 EXPECT_FALSE(ui->niterations());
87 EXPECT_EQ(ui->theta(), theta);
88 EXPECT_EQ(theta->MapPreLoopVar(*ui->idv()).input->origin(), x);
107 auto theta =
create_theta(ult, add, init0, step1, end100);
109 EXPECT_TRUE(ui && *ui->niterations() == 100);
113 EXPECT_TRUE(ui && *ui->niterations() == 101);
117 EXPECT_TRUE(ui && *ui->niterations() == 100);
121 EXPECT_TRUE(ui && *ui->niterations() == 101);
125 EXPECT_TRUE(ui && !ui->niterations());
129 EXPECT_TRUE(ui && *ui->niterations() == 101);
133 EXPECT_TRUE(ui && !ui->niterations());
277TEST(LoopUnrollingTests, test_nested_theta)
280 auto & graph = rm.
Rvsdg();
289 auto lvo_init = otheta->AddLoopVar(init);
290 auto lvo_step = otheta->AddLoopVar(step);
291 auto lvo_end = otheta->AddLoopVar(end);
296 otheta->set_predicate(matchNode.output(0));
297 lvo_init.post->divert_to(add);
303 auto lvi_init = inner_theta->AddLoopVar(inner_init);
304 auto lvi_step = inner_theta->AddLoopVar(lvo_step.pre);
305 auto lvi_end = inner_theta->AddLoopVar(lvo_end.pre);
309 auto & innerMatchNode =
311 inner_theta->set_predicate(innerMatchNode.output(0));
312 lvi_init.post->divert_to(inner_add);
317 auto inner_nested_init =
319 auto lvi_nested_init = inner_nested_theta->AddLoopVar(inner_nested_init);
320 auto lvi_nested_step = inner_nested_theta->AddLoopVar(lvi_step.pre);
321 auto lvi_nested_end = inner_nested_theta->AddLoopVar(lvi_end.pre);
323 auto inner_nested_add =
325 auto inner_nested_compare =
327 auto & innerNestedMatchNode =
329 inner_nested_theta->set_predicate(innerNestedMatchNode.output(0));
330 lvi_nested_init.post->divert_to(inner_nested_add);
336 auto lvi2_init = inner2_theta->AddLoopVar(inner2_init);
337 auto lvi2_step = inner2_theta->AddLoopVar(lvo_step.pre);
338 auto lvi2_end = inner2_theta->AddLoopVar(lvo_end.pre);
342 auto & inner2MatchNode =
344 inner2_theta->set_predicate(inner2MatchNode.output(0));
345 lvi2_init.post->divert_to(inner2_add);
353 EXPECT_EQ(
nthetas(otheta->subregion()), 2u);
362 EXPECT_LE(otheta->subregion()->numNodes(), 20u);
371 EXPECT_LE(inner_theta->subregion()->numNodes(), 15u);
380 auto thetas =
find_thetas(inner_theta->subregion());
381 EXPECT_EQ(thetas.size(), 1u);
382 EXPECT_GE(thetas[0]->subregion()->numNodes(), 7u);
392 EXPECT_EQ(thetas.size(), 2u);
393 EXPECT_GE(thetas[1]->subregion()->numNodes(), 7u);
402 EXPECT_EQ(thetas.size(), 3u);
403 EXPECT_EQ(
nthetas(thetas[0]->subregion()), 8u);