41 exitvar.output->divert_users(&
smap.lookup(*
exitvar.branchResult[alternative]->origin()));
57 auto input = argument->
input();
58 for (
n = 1;
n <
exitvar.branchResult.size();
n++)
62 if (!argument && argument->input() != input)
66 if (
n ==
exitvar.branchResult.size())
76static std::unordered_set<jlm::rvsdg::Output *>
86 std::unordered_set<uint64_t> set({
match_op->default_alternative() });
88 set.insert(
pair.second);
94 std::unordered_set<jlm::rvsdg::Output *>
outputs;
101 for (
n = 0;
n <
exitvar.branchResult.size();
n++)
108 if (
op->value().nalternatives() != 2)
111 if (
n ==
exitvar.branchResult.size())
122 auto origin = gamma.predicate()->origin();
126 std::unordered_map<uint64_t, uint64_t>
map;
130 for (
const auto &
xv : gamma.GetExitVars())
136 size_t nalternatives = 0;
137 std::unordered_map<uint64_t, uint64_t>
new_mapping;
138 for (
size_t n = 0;
n <
xv.branchResult.size();
n++)
140 auto origin =
xv.branchResult[
n]->origin();
144 nalternatives = value.nalternatives();
148 defalt = value.alternative();
151 auto origin = matchNode->input(0)->origin();
153 xv.output->divert_users(matchNode.output(0));
160 auto gammaNode =
dynamic_cast<GammaNode *
>(&node);
173 auto gammaNode =
dynamic_cast<GammaNode *
>(&node);
174 if (gammaNode ==
nullptr)
188 const auto gammaNode =
dynamic_cast<GammaNode *
>(&node);
189 if (gammaNode ==
nullptr)
204std::unique_ptr<Operation>
207 return std::make_unique<GammaOperation>(*
this);
217std::shared_ptr<const Type>
233 std::make_unique<StructuralInput>(
238 for (std::size_t
n = 0;
n < Operation_->nalternatives(); ++
n)
246 size_t nalternatives,
270 ev.branchArgument.push_back(
304std::vector<GammaNode::EntryVar>
307 std::vector<GammaNode::EntryVar>
vars(
ninputs() - 1);
308 for (
size_t n = 0;
n <
vars.size(); ++
n)
315std::variant<GammaNode::MatchVar, GammaNode::EntryVar>
329std::variant<GammaNode::MatchVar, GammaNode::EntryVar>
367 const auto & type =
values[0]->Type();
368 auto output =
addOutput(std::make_unique<StructuralOutput>(
this, type));
380std::vector<GammaNode::ExitVar>
383 std::vector<GammaNode::ExitVar>
vars;
486 auto nev = gamma->AddEntryVar(&
smap.lookup(*
oev.input->origin()));
488 rmap[
n].insert(
oev.branchArgument[
n],
nev.branchArgument[
n]);
498 std::vector<jlm::rvsdg::Output *>
operands;
499 for (
size_t n = 0;
n <
oex.branchResult.size();
n++)
508std::optional<rvsdg::Output *>
540 for (
size_t n = 1;
n <
exitvar.branchResult.size(); ++
n)
const ControlValueRepresentation & value() const noexcept
static std::shared_ptr< const ControlType > Create(std::size_t nalternatives)
Instantiates control type.
size_t alternative() const noexcept
Conditional operator / pattern matching.
void RemoveEntryVars(const std::vector< EntryVar > &entryVars)
Removes the given entry variables.
const GammaOperation & GetOperation() const noexcept override
ExitVar MapOutputExitVar(const rvsdg::Output &output) const
Maps gamma output to exit variable description.
const rvsdg::Input & mapBranchArgumentToInput(const rvsdg::Output &output) const
Maps branch subregion entry argument to its corresponding gamma input.
std::unique_ptr< GammaOperation > Operation_
std::variant< MatchVar, EntryVar > MapInput(const rvsdg::Input &input) const
Maps gamma input to its role (match variable or entry variable).
GammaNode * copy(jlm::rvsdg::Region *region, SubstitutionMap &smap) const override
Copy a node with substitutions.
EntryVar AddEntryVar(rvsdg::Output *origin)
Routes a variable into the gamma branches.
EntryVar GetEntryVar(std::size_t index) const
Gets entry variable by index.
static GammaNode * create(jlm::rvsdg::Output *predicate, size_t nalternatives)
GammaNode(rvsdg::Output &predicate, std::unique_ptr< GammaOperation > op)
std::variant< MatchVar, EntryVar > MapBranchArgument(const rvsdg::Output &output) const
Maps branch subregion entry argument to its role (pattern match or entry variable).
std::vector< ExitVar > GetExitVars() const
Gets all exit variables for this gamma.
const Output & mapBranchResultToOutput(const Input &input) const
Maps branch subregion exit result to its corresponding gamma output.
std::vector< EntryVar > GetEntryVars() const
Gets all entry variables for this gamma.
void RemoveExitVars(const std::vector< Output * > &gammaOutputs)
Removes the exit variables corresponding to the given gammaOutputs.
ExitVar MapBranchResultExitVar(const rvsdg::Input &input) const
Maps gamma region exit result to exit variable description.
rvsdg::Input * predicate() const noexcept
~GammaNode() noexcept override
ExitVar AddExitVar(const std::vector< rvsdg::Output * > &values)
Routes per-branch result of gamma to output.
MatchVar GetMatchVar() const
std::shared_ptr< const Type > GetMatchContentType(std::size_t alternative) const
Returns the type of pattern matching content produced in a branch.
std::unique_ptr< Operation > copy() const override
bool operator==(const Operation &other) const noexcept override
std::vector< std::shared_ptr< const Type > > MatchContentTypes_
std::string debug_string() const override
~GammaOperation() noexcept override
static Node & CreateNode(Output &predicate, const std::unordered_map< uint64_t, uint64_t > &mapping, const uint64_t defaultAlternative, const size_t numAlternatives)
NodeOutput * output(size_t index) const noexcept
size_t RemoveInputs(const util::HashSet< size_t > &indices)
rvsdg::Region * region() const noexcept
size_t ninputs() const noexcept
size_t noutputs() const noexcept
size_t RemoveOutputs(const util::HashSet< size_t > &indices)
size_t index() const noexcept
void divert_users(jlm::rvsdg::Output *new_origin)
bool IsDead() const noexcept
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
Represents the argument of a region.
static RegionArgument & Create(rvsdg::Region ®ion, StructuralInput *input, std::shared_ptr< const rvsdg::Type > type)
Creates region entry argument.
StructuralInput * input() const noexcept
static RegionResult & Create(rvsdg::Region ®ion, rvsdg::Output &origin, StructuralOutput *output, std::shared_ptr< const rvsdg::Type > type)
Create region exit result.
Represent acyclic RVSDG subgraphs.
size_t RemoveResults(const util::HashSet< size_t > &indices)
RegionArgument * argument(size_t index) const noexcept
void copy(Region *target, SubstitutionMap &smap) const
Copy a region with substitutions.
RegionResult * result(size_t index) const noexcept
size_t RemoveArguments(const util::HashSet< size_t > &indices)
StructuralInput * addInput(std::unique_ptr< StructuralInput > input, bool notifyRegion)
StructuralOutput * addOutput(std::unique_ptr< StructuralOutput > input)
SubregionIteratorRange Subregions()
rvsdg::Region * subregion(size_t index) const noexcept
size_t nsubregions() const noexcept
StructuralOutput * output(size_t index) const noexcept
StructuralInput * input(size_t index) const noexcept
void insert(const Output *original, Output *substitute)
static std::shared_ptr< const UnitType > Create()
bool insert(ItemType item)
std::size_t Size() const noexcept
static bool perform_invariant_reduction(GammaNode *gamma)
bool ReduceGammaControlConstant(Node &node)
static void perform_predicate_reduction(GammaNode *gamma)
bool ReduceGammaWithStaticallyKnownPredicate(Node &node)
static bool is_predicate_reducible(const GammaNode *gamma)
static void remove(Node *node)
static void perform_control_constant_reduction(std::unordered_set< jlm::rvsdg::Output * > &outputs)
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
static std::vector< jlm::rvsdg::Output * > outputs(const Node *node)
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
std::optional< rvsdg::Output * > GetGammaInvariantOrigin(const GammaNode &gamma, const GammaNode::ExitVar &exitvar)
Determines whether a gamma exit var is path-invariant.
static std::unordered_set< jlm::rvsdg::Output * > is_control_constant_reducible(GammaNode *gamma)
bool ReduceGammaInvariantVariables(Node &node)
A variable routed into all gamma regions.
rvsdg::Input * input
Variable at entry point (input to gamma node).
A variable routed out of all gamma regions as result.
The match/discriminator variable of this gamma node.
rvsdg::Input * input
The variable matched over (i.e. the "selector" of the gamma branch).