23 return no && no->
node() == node;
36 if (no->node() == node)
40 for (
size_t i = 0; i < no->node()->
ninputs(); ++i)
42 if (
depends_on(no->node()->input(i)->origin(), node))
53 for (
auto & user : origin->
Users())
55 if (rvsdg::TryGetOwnerNode<rvsdg::GammaNode>(user) == gamma)
57 auto rolevar = gamma->
MapInput(user);
58 if (
auto entryvar = std::get_if<rvsdg::GammaNode::EntryVar>(&rolevar))
72 auto other_gamma = rvsdg::TryGetOwnerNode<rvsdg::GammaNode>(user);
73 if (other_gamma && gamma != other_gamma)
77 bool can_merge =
true;
82 can_merge &=
is_output_of(ev.input->origin(), other_gamma)
83 || !
depends_on(ev.input->origin(), other_gamma);
85 for (
const auto & oev : other_gamma->GetEntryVars())
88 can_merge &= !
depends_on(oev.input->origin(), gamma);
92 std::vector<rvsdg::SubstitutionMap> rmap(gamma->
nsubregions());
96 if (rvsdg::TryGetOwnerNode<rvsdg::GammaNode>(*ev.input->origin()) == other_gamma)
98 auto oex = other_gamma->MapOutputExitVar(*ev.input->origin());
101 rmap[j].insert(ev.branchArgument[j], oex.branchResult[j]->origin());
106 auto oev =
get_entryvar(ev.input->origin(), other_gamma);
109 rmap[j].insert(ev.branchArgument[j], oev.branchArgument[j]);
116 gamma->
subregion(j)->
copy(other_gamma->subregion(j), rmap[j]);
121 std::vector<jlm::rvsdg::Output *>
operands;
122 for (
size_t j = 0; j < ex.branchResult.size(); j++)
124 operands.push_back(&rmap[j].lookup(*ex.branchResult[j]->origin()));
126 auto oex = other_gamma->AddExitVar(
operands).output;
127 ex.output->divert_users(oex);
148 for (
size_t n = 0; n < structnode->nsubregions(); n++)
void Run(rvsdg::RvsdgModule &rvsdgModule, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
~GammaMerge() noexcept override
Conditional operator / pattern matching.
std::variant< MatchVar, EntryVar > MapInput(const rvsdg::Input &input) const
Maps gamma input to its role (match variable or entry variable).
EntryVar AddEntryVar(rvsdg::Output *origin)
Routes a variable into the gamma branches.
std::vector< ExitVar > GetExitVars() const
Gets all exit variables for this gamma.
std::vector< EntryVar > GetEntryVars() const
Gets all entry variables for this gamma.
rvsdg::Input * predicate() const noexcept
Region & GetRootRegion() const noexcept
Node * node() const noexcept
Represents the argument of a region.
Represent acyclic RVSDG subgraphs.
void copy(Region *target, SubstitutionMap &smap) const
Copy a region with substitutions.
size_t nsubregions() const noexcept
rvsdg::Region * subregion(size_t index) const noexcept
bool merge_gamma(rvsdg::GammaNode *gamma)
bool is_output_of(jlm::rvsdg::Output *output, rvsdg::Node *node)
rvsdg::GammaNode::EntryVar get_entryvar(jlm::rvsdg::Output *origin, rvsdg::GammaNode *gamma)
bool depends_on(jlm::rvsdg::Output *output, rvsdg::Node *node)
static void remove(Node *node)
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
size_t ninputs(const rvsdg::Region *region) noexcept
A variable routed into all gamma regions.