27 const std::pair<uint64_t, uint64_t> & gammaSubregionControlConstants)
32 auto bitType32 = BitType::Create(32);
33 auto controlType = ControlType::Create(2);
37 auto dummy = TestOperation::createNode(thetaNode->subregion(), {}, { bitType32 })->output(0);
38 auto predicate = MatchOperation::Create(*dummy, { { 1, 1 } }, 0, 2);
40 auto gammaNode = GammaNode::create(predicate, 2);
42 auto controlConstant0 = &ControlConstantOperation::create(
43 *gammaNode->subregion(0),
45 gammaSubregionControlConstants.first);
46 auto controlConstant1 = &ControlConstantOperation::create(
47 *gammaNode->subregion(1),
49 gammaSubregionControlConstants.second);
51 auto controlExitVar = gammaNode->AddExitVar({ controlConstant0, controlConstant1 });
53 thetaNode->predicate()->divert_to(controlExitVar.output);
57 *TryGetOwnerNode<Node>(*predicate),
58 { TryGetOwnerNode<Node>(*controlConstant0), TryGetOwnerNode<Node>(*controlConstant1) } };
71 const std::pair<int64_t, int64_t> & gammaSubregionAlternatives)
76 auto bitType32 = BitType::Create(32);
77 auto controlType = ControlType::Create(2);
82 TestOperation::createNode(thetaNode->subregion(), {}, { controlType })->output(0);
83 auto gammaNode = GammaNode::create(predicate, 2);
85 auto constant0 = &BitConstantOperation::create(
86 *gammaNode->subregion(0),
87 { 64, gammaSubregionAlternatives.first });
88 auto constant1 = &BitConstantOperation::create(
89 *gammaNode->subregion(1),
90 { 64, gammaSubregionAlternatives.second });
92 auto exitVar = gammaNode->AddExitVar({ constant0, constant1 });
94 auto & matchNode = MatchOperation::CreateNode(*exitVar.output, { { 1, 1 } }, 0, 2);
96 thetaNode->predicate()->divert_to(matchNode.output(0));
98 return { *gammaNode, *thetaNode, matchNode };
114 auto bitType32 = BitType::Create(32);
115 auto controlType = ControlType::Create(2);
119 auto constantNode = TestOperation::createNode(thetaNode->subregion(), {}, { bitType32 });
120 auto & matchNode = MatchOperation::CreateNode(*constantNode->output(0), { { 1, 1 } }, 0, 2);
122 auto gammaNode = GammaNode::create(matchNode.output(0), 2);
124 thetaNode->predicate()->divert_to(matchNode.output(0));
126 return { *gammaNode, *thetaNode, matchNode };
129TEST(PredicateCorrelationTests, testControlConstantCorrelation)
136 auto & rvsdg = rvsdgModule->Rvsdg();
138 auto [gammaNode, thetaNode, matchNode, controlConstants] =
148 thetaNode.subregion()->prune(
true);
153 EXPECT_EQ(thetaNode.subregion()->numNodes(), 2u);
154 EXPECT_EQ(thetaNode.predicate()->origin(), matchNode.output(0));
157TEST(PredicateCorrelationTests, testMatchConstantCorrelationDetection)
163 const std::vector<std::pair<uint64_t, uint64_t>> gammaSubregionAlternatives = { { 0, 1 },
165 for (
auto alternatives : gammaSubregionAlternatives)
169 auto & rvsdg = rvsdgModule->Rvsdg();
176 const auto correlationOpt = computeThetaGammaPredicateCorrelation(thetaNode);
179 EXPECT_NE(correlationOpt.value(),
nullptr);
180 EXPECT_EQ(correlationOpt.value()->type(), CorrelationType::MatchConstantCorrelation);
181 EXPECT_EQ(&correlationOpt.value()->thetaNode(), &thetaNode);
182 EXPECT_EQ(&correlationOpt.value()->gammaNode(), &gammaNode);
184 const auto correlationData =
185 std::get<ThetaGammaPredicateCorrelation::MatchConstantCorrelationData>(
186 correlationOpt.value()->data());
187 EXPECT_EQ(correlationData.matchNode, &matchNode);
188 EXPECT_EQ(correlationData.alternatives.size(), 2u);
189 EXPECT_EQ(correlationData.alternatives[0], alternatives.first);
190 EXPECT_EQ(correlationData.alternatives[1], alternatives.second);
194TEST(PredicateCorrelationTests, testMatchConstantCorrelation_Success)
201 auto & rvsdg = rvsdgModule->Rvsdg();
204 auto gammaPredicate = gammaNode.predicate()->origin();
212 thetaNode.subregion()->prune(
true);
217 EXPECT_EQ(thetaNode.subregion()->numNodes(), 1u);
218 EXPECT_EQ(thetaNode.predicate()->origin(), gammaPredicate);
221TEST(PredicateCorrelationTests, testMatchConstantCorrelation_Failure)
228 auto & rvsdg = rvsdgModule->Rvsdg();
230 auto gammaSubregionAlternatives = std::make_pair(1, 0);
231 auto [gammaNode, thetaNode, _] =
233 auto gammaPredicate = gammaNode.predicate()->origin();
241 thetaNode.subregion()->prune(
true);
250 EXPECT_NE(thetaNode.predicate()->origin(), gammaPredicate);
253TEST(PredicateCorrelationTests, testThetaGammaMatchCorrelationDetection)
260 auto & rvsdg = rvsdgModule->Rvsdg();
267 const auto correlationOpt = computeThetaGammaPredicateCorrelation(thetaNode);
270 EXPECT_NE(correlationOpt.value(),
nullptr);
271 EXPECT_EQ(correlationOpt.value()->type(), CorrelationType::MatchCorrelation);
272 EXPECT_EQ(&correlationOpt.value()->thetaNode(), &thetaNode);
273 EXPECT_EQ(&correlationOpt.value()->gammaNode(), &gammaNode);
275 const auto correlationData = std::get<ThetaGammaPredicateCorrelation::MatchCorrelationData>(
276 correlationOpt.value()->data());
277 EXPECT_EQ(correlationData.matchNode, &matchNode);
280TEST(PredicateCorrelationTests, testThetaGammaCorrelationFixPoint)
286 auto bitType32 = BitType::Create(32);
287 auto controlType = ControlType::Create(2);
290 auto & rvsdg = rvsdgModule->Rvsdg();
292 auto thetaNode = ThetaNode::create(&rvsdg.GetRootRegion());
296 TestOperation::createNode(thetaNode->subregion(), {}, { controlType })->output(0);
297 auto gammaNode1 = GammaNode::create(predicate, 2);
299 auto constant0 = &BitConstantOperation::create(*gammaNode1->subregion(0), { 64, 0 });
300 auto constant1 = &BitConstantOperation::create(*gammaNode1->subregion(1), { 64, 1 });
302 auto exitVar = gammaNode1->AddExitVar({ constant0, constant1 });
303 auto & matchNode = MatchOperation::CreateNode(*exitVar.output, { { 1, 1 } }, 0, 2);
306 auto gammaNode2 = GammaNode::create(matchNode.output(0), 2);
308 auto controlConstant0 = &ControlConstantOperation::create(*gammaNode2->subregion(0), 2, 0);
309 auto controlConstant1 = &ControlConstantOperation::create(*gammaNode2->subregion(1), 2, 1);
311 auto controlExitVar = gammaNode2->AddExitVar({ controlConstant0, controlConstant1 });
313 thetaNode->predicate()->divert_to(controlExitVar.output);
320 thetaNode->subregion()->prune(
true);
325 EXPECT_EQ(thetaNode->subregion()->numNodes(), 1u);
326 EXPECT_EQ(thetaNode->predicate()->origin(), predicate);
329TEST(PredicateCorrelationTests, testDetermineGammaSubregionRoles_ControlConstantCorrelation)
337 auto & rvsdg = rvsdgModule->Rvsdg();
339 constexpr std::pair<uint64_t, uint64_t> controlAlternatives = { 0, 1 };
340 auto [gammaNode, thetaNode, matchNode, controlConstants] =
343 const auto correlation = ThetaGammaPredicateCorrelation::CreateControlConstantCorrelation(
346 { controlAlternatives.first, controlAlternatives.second });
349 const auto gammaSubregionRoles = determineGammaSubregionRoles(*correlation);
352 EXPECT_EQ(gammaSubregionRoles->exitSubregion, gammaNode.subregion(0));
353 EXPECT_EQ(gammaSubregionRoles->repetitionSubregion, gammaNode.subregion(1));
359 auto & rvsdg = rvsdgModule->Rvsdg();
361 constexpr std::pair<uint64_t, uint64_t> controlAlternatives = { 1, 0 };
362 auto [gammaNode, thetaNode, matchNode, controlConstants] =
365 const auto correlation = ThetaGammaPredicateCorrelation::CreateControlConstantCorrelation(
368 { controlAlternatives.first, controlAlternatives.second });
371 const auto gammaSubregionRoles = determineGammaSubregionRoles(*correlation);
374 EXPECT_EQ(gammaSubregionRoles->exitSubregion, gammaNode.subregion(1));
375 EXPECT_EQ(gammaSubregionRoles->repetitionSubregion, gammaNode.subregion(0));
379TEST(PredicateCorrelationTests, testDetermineGammaSubregionRoles_MatchConstantCorrelation)
387 auto & rvsdg = rvsdgModule->Rvsdg();
389 constexpr std::pair<uint64_t, uint64_t> gammaSubregionAlternatives = { 0, 1 };
390 auto [gammaNode, thetaNode, matchNode] =
393 const auto correlation = ThetaGammaPredicateCorrelation::CreateMatchConstantCorrelation(
396 { &matchNode, { gammaSubregionAlternatives.first, gammaSubregionAlternatives.second } });
399 const auto gammaSubregionRoles = determineGammaSubregionRoles(*correlation);
402 EXPECT_EQ(gammaSubregionRoles->exitSubregion, gammaNode.subregion(0));
403 EXPECT_EQ(gammaSubregionRoles->repetitionSubregion, gammaNode.subregion(1));
409 auto & rvsdg = rvsdgModule->Rvsdg();
411 constexpr std::pair<uint64_t, uint64_t> gammaSubregionAlternatives = { 1, 0 };
412 auto [gammaNode, thetaNode, matchNode] =
415 const auto correlation = ThetaGammaPredicateCorrelation::CreateMatchConstantCorrelation(
418 { &matchNode, { gammaSubregionAlternatives.first, gammaSubregionAlternatives.second } });
421 const auto gammaSubregionRoles = determineGammaSubregionRoles(*correlation);
424 EXPECT_EQ(gammaSubregionRoles->exitSubregion, gammaNode.subregion(1));
425 EXPECT_EQ(gammaSubregionRoles->repetitionSubregion, gammaNode.subregion(0));
429TEST(PredicateCorrelationTests, testDetermineGammaSubregionRoles_MatchCorrelation)
435 auto & rvsdg = rvsdgModule->Rvsdg();
439 const auto correlation =
440 ThetaGammaPredicateCorrelation::CreateMatchCorrelation(thetaNode, gammaNode, { &matchNode });
443 const auto gammaSubregionRoles = determineGammaSubregionRoles(*correlation);
446 EXPECT_EQ(gammaSubregionRoles->exitSubregion, gammaNode.subregion(0));
447 EXPECT_EQ(gammaSubregionRoles->repetitionSubregion, gammaNode.subregion(1));
450TEST(PredicateCorrelationTests, testGammaGammaMatchCorrelationDetection)
456 auto bitType32 = BitType::Create(32);
457 auto controlType = ControlType::Create(2);
460 auto & rvsdg = rvsdgModule->Rvsdg();
462 auto constantNode = TestOperation::createNode(&rvsdg.GetRootRegion(), {}, { bitType32 });
463 auto & matchNode = MatchOperation::CreateNode(*constantNode->output(0), { { 1, 1 } }, 0, 2);
465 auto gammaNode1 = GammaNode::create(matchNode.output(0), 2);
467 auto gammaNode2 = GammaNode::create(matchNode.output(0), 2);
475 EXPECT_NE(correlationOpt.value(),
nullptr);
476 EXPECT_EQ(correlationOpt.value()->type(), CorrelationType::MatchCorrelation);
477 EXPECT_EQ(&correlationOpt.value()->gammaNode1(), gammaNode1);
478 EXPECT_EQ(&correlationOpt.value()->gammaNode2(), gammaNode2);
480 const auto correlationData = std::get<GammaGammaPredicateCorrelation::MatchCorrelationData>(
481 correlationOpt.value()->correlationData());
482 EXPECT_EQ(correlationData.matchNode, &matchNode);