30 static std::optional<std::vector<uint64_t>>
33 const auto & gammaNode = rvsdg::AssertGetOwnerNode<rvsdg::GammaNode>(gammaOutput);
35 std::vector<uint64_t> alternatives;
36 auto [branchResults, _] = gammaNode.MapOutputExitVar(gammaOutput);
37 for (
const auto branchResult : branchResults)
40 auto [constantNode, constantOperation] =
41 rvsdg::TryGetSimpleNodeAndOptionalOp<rvsdg::ControlConstantOperation>(
42 *branchResult->origin());
43 if (constantOperation)
45 alternatives.push_back(constantOperation->value().alternative());
51 auto [constantNode, constantOperation] =
52 rvsdg::TryGetSimpleNodeAndOptionalOp<rvsdg::BitConstantOperation>(
53 *branchResult->origin());
54 if (constantOperation)
56 alternatives.push_back(constantOperation->value().to_uint());
62 auto [constantNode, constantOperation] =
63 rvsdg::TryGetSimpleNodeAndOptionalOp<IntegerConstantOperation>(*branchResult->origin());
64 if (constantOperation)
66 alternatives.push_back(constantOperation->Representation().to_uint());
77 static std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
81 auto gammaNode = rvsdg::TryGetOwnerNode<rvsdg::GammaNode>(thetaPredicateOperand);
88 if (!controlAlternativesOpt.has_value())
92 const auto controlAlternatives = controlAlternativesOpt.value();
100 static std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
103 auto [matchNode, matchOperation] =
104 rvsdg::TryGetSimpleNodeAndOptionalOp<rvsdg::MatchOperation>(*thetaNode.
predicate()->
origin());
110 const auto & gammaOutput = *matchNode->input(0)->origin();
111 const auto gammaNode = rvsdg::TryGetOwnerNode<rvsdg::GammaNode>(gammaOutput);
118 if (!alternativesOpt.has_value())
122 const auto alternatives = alternativesOpt.value();
127 { matchNode, alternatives });
130 static std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
133 auto [matchNode, matchOperation] =
134 rvsdg::TryGetSimpleNodeAndOptionalOp<rvsdg::MatchOperation>(*thetaNode.
predicate()->
origin());
140 for (
auto & user : matchNode->output(0)->Users())
142 if (
const auto gammaNode = rvsdg::TryGetOwnerNode<rvsdg::GammaNode>(user))
154 std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
159 return correlationOpt;
164 return correlationOpt;
169 return correlationOpt;
175 static std::optional<std::unique_ptr<GammaGammaPredicateCorrelation>>
178 auto [matchNode, matchOperation] = rvsdg::TryGetSimpleNodeAndOptionalOp<rvsdg::MatchOperation>(
185 for (
auto & user : matchNode->output(0)->Users())
187 if (
const auto gammaNode2 = rvsdg::TryGetOwnerNode<rvsdg::GammaNode>(user);
188 gammaNode2 != &gammaNode1)
200 std::optional<std::unique_ptr<GammaGammaPredicateCorrelation>>
205 return correlationOpt;
211 std::optional<GammaSubregionRoles>
214 switch (correlation.
type())
218 const auto controlAlternatives =
219 std::get<ThetaGammaPredicateCorrelation::ControlConstantCorrelationData>(
221 if (controlAlternatives.size() != 2)
227 if (controlAlternatives[0] == 0)
242 const auto [matchNode, alternatives] =
243 std::get<ThetaGammaPredicateCorrelation::MatchConstantCorrelationData>(correlation.
data());
245 if (alternatives.size() != 2)
251 const auto matchOperation =
252 util::assertedCast<const rvsdg::MatchOperation>(&matchNode->GetOperation());
253 if (matchOperation->alternative(alternatives[0]) == 0)
285 for (
auto & node : region.Nodes())
291 correlatePredicatesInRegion(*lambdaNode.
subregion());
295 correlatePredicatesInRegion(*phiNode.subregion());
304 correlatePredicatesInRegion(*thetaNode.subregion());
306 correlatePredicatesInTheta(thetaNode);
310 for (
auto & subregion : gammaNode.Subregions())
312 correlatePredicatesInRegion(subregion);
329 bool predicateWasRedirected =
false;
332 predicateWasRedirected =
false;
335 if (!correlationOpt.has_value())
339 const auto & correlation = correlationOpt.value();
341 switch (correlation->type())
350 predicateWasRedirected =
false;
353 throw std::logic_error(
"Unhandled theta-gamma predicate correlation.");
355 }
while (predicateWasRedirected);
363 const auto & gammaNode = correlation.
gammaNode();
364 const auto & thetaNode = correlation.
thetaNode();
366 const auto controlAlternatives =
367 std::get<ThetaGammaPredicateCorrelation::ControlConstantCorrelationData>(correlation.
data());
368 if (controlAlternatives.size() != 2 || controlAlternatives[0] != 0 || controlAlternatives[1] != 1)
373 thetaNode.predicate()->divert_to(gammaNode.predicate()->origin());
382 const auto & gammaNode = correlation.
gammaNode();
383 const auto & thetaNode = correlation.
thetaNode();
385 const auto [matchNode, alternatives] =
386 std::get<ThetaGammaPredicateCorrelation::MatchConstantCorrelationData>(correlation.
data());
388 if (alternatives.size() != 2)
393 const auto matchOperation =
394 util::assertedCast<const rvsdg::MatchOperation>(&matchNode->GetOperation());
395 if (matchOperation->alternative(alternatives[0]) != 0
396 || matchOperation->alternative(alternatives[1]) != 1)
401 thetaNode.predicate()->divert_to(gammaNode.predicate()->origin());
static std::unique_ptr< GammaGammaPredicateCorrelation > CreateMatchCorrelation(rvsdg::GammaNode &gammaNode1, rvsdg::GammaNode &gammaNode2, MatchCorrelationData correlationData)
static bool handleMatchConstantCorrelation(const ThetaGammaPredicateCorrelation &correlation)
static void correlatePredicatesInRegion(rvsdg::Region ®ion)
void Run(rvsdg::RvsdgModule &rvsdgModule, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
static bool handleControlConstantCorrelation(const ThetaGammaPredicateCorrelation &correlation)
static void correlatePredicatesInTheta(rvsdg::ThetaNode &thetaNode)
~PredicateCorrelation() noexcept override
const CorrelationData & data() const noexcept
CorrelationType type() const noexcept
rvsdg::GammaNode & gammaNode() const noexcept
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateControlConstantCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, ControlConstantCorrelationData data)
rvsdg::ThetaNode & thetaNode() const noexcept
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateMatchConstantCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, MatchConstantCorrelationData data)
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateMatchCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, MatchCorrelationData data)
Conditional operator / pattern matching.
rvsdg::Input * predicate() const noexcept
Region & GetRootRegion() const noexcept
rvsdg::Region * subregion() const noexcept
A phi node represents the fixpoint of mutually recursive definitions.
size_t nsubregions() const noexcept
rvsdg::Region * subregion(size_t index) const noexcept
RegionResult * predicate() const noexcept
Global memory state passed between functions.
static std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeMatchCorrelation(rvsdg::ThetaNode &thetaNode)
std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeThetaGammaPredicateCorrelation(rvsdg::ThetaNode &thetaNode)
static std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeControlConstantCorrelation(rvsdg::ThetaNode &thetaNode)
static std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeMatchConstantCorrelation(rvsdg::ThetaNode &thetaNode)
std::optional< std::unique_ptr< GammaGammaPredicateCorrelation > > computeGammaGammaPredicateCorrelation(rvsdg::GammaNode &gammaNode)
static std::optional< std::vector< uint64_t > > extractConstantAlternatives(const rvsdg::Output &gammaOutput)
std::optional< GammaSubregionRoles > determineGammaSubregionRoles(const ThetaGammaPredicateCorrelation &correlation)
@ ControlConstantCorrelation
@ MatchConstantCorrelation
void MatchTypeOrFail(T &obj, const Fns &... fns)
Pattern match over subclass type of given object.
rvsdg::Region * exitSubregion
rvsdg::Region * repetitionSubregion