30static std::optional<std::vector<uint64_t>>
35 std::vector<uint64_t> alternatives;
36 auto [branchResults, _] = gammaNode.MapOutputExitVar(gammaOutput);
37 for (
const auto branchResult : branchResults)
40 auto [constantNode, constantOperation] =
42 *branchResult->origin());
43 if (constantOperation)
45 alternatives.push_back(constantOperation->value().alternative());
51 auto [constantNode, constantOperation] =
53 *branchResult->origin());
54 if (constantOperation)
56 alternatives.push_back(constantOperation->value().to_uint());
62 auto [constantNode, constantOperation] =
64 if (constantOperation)
66 alternatives.push_back(constantOperation->Representation().to_uint());
77static std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
88 if (!controlAlternativesOpt.has_value())
92 const auto controlAlternatives = controlAlternativesOpt.value();
100static std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
103 auto [matchNode, matchOperation] =
110 const auto & gammaOutput = *matchNode->input(0)->origin();
118 if (!alternativesOpt.has_value())
122 const auto alternatives = alternativesOpt.value();
127 { matchNode, alternatives });
130static std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
133 auto [matchNode, matchOperation] =
140 for (
auto & user : matchNode->output(0)->Users())
154std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
159 return correlationOpt;
164 return correlationOpt;
169 return correlationOpt;
175static std::optional<std::unique_ptr<GammaGammaPredicateCorrelation>>
185 for (
auto & user : matchNode->output(0)->Users())
188 gammaNode2 != &gammaNode1)
200std::optional<std::unique_ptr<GammaGammaPredicateCorrelation>>
205 return correlationOpt;
211std::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
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateMatchCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, MatchCorrelationData data)
CorrelationType type() const noexcept
rvsdg::GammaNode & gammaNode() const noexcept
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateMatchConstantCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, MatchConstantCorrelationData data)
rvsdg::ThetaNode & thetaNode() const noexcept
const CorrelationData & data() const noexcept
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateControlConstantCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, ControlConstantCorrelationData 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.
rvsdg::Region * subregion(size_t index) const noexcept
size_t nsubregions() const noexcept
RegionResult * predicate() const noexcept
Global memory state passed between functions.
static std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeControlConstantCorrelation(rvsdg::ThetaNode &thetaNode)
std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeThetaGammaPredicateCorrelation(rvsdg::ThetaNode &thetaNode)
static std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeMatchConstantCorrelation(rvsdg::ThetaNode &thetaNode)
std::optional< std::unique_ptr< GammaGammaPredicateCorrelation > > computeGammaGammaPredicateCorrelation(rvsdg::GammaNode &gammaNode)
std::optional< GammaSubregionRoles > determineGammaSubregionRoles(const ThetaGammaPredicateCorrelation &correlation)
static std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeMatchCorrelation(rvsdg::ThetaNode &thetaNode)
@ ControlConstantCorrelation
@ MatchConstantCorrelation
static std::optional< std::vector< uint64_t > > extractConstantAlternatives(const rvsdg::Output &gammaOutput)
void MatchTypeOrFail(T &obj, const Fns &... fns)
Pattern match over subclass type of given object.
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
rvsdg::Region * exitSubregion
rvsdg::Region * repetitionSubregion