28 if (argument.
nusers() != 1)
33 return rvsdg::is<rvsdg::RegionResult>(*argument.
Users().
begin());
40 return argument !=
nullptr;
47 auto & oldFunctionType = op.
type();
49 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> newArgumentTypes;
50 for (
size_t i = 0; i < oldFunctionType.NumArguments(); ++i)
53 auto argumentType = oldFunctionType.Arguments()[i];
54 JLM_ASSERT(*argumentType == *argument->Type());
58 newArgumentTypes.push_back(argumentType);
62 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> newResultTypes;
63 for (
size_t i = 0; i < oldFunctionType.NumResults(); ++i)
66 auto resultType = oldFunctionType.Results()[i];
71 newResultTypes.push_back(resultType);
82 op.callingConvention(),
88 auto oldArgument = ctxvar.inner;
89 auto origin = ctxvar.input->origin();
91 auto newArgument = newLambda->AddContextVar(*origin).inner;
92 substitutionMap.
insert(oldArgument, newArgument);
96 auto newArgs = newLambda->GetFunctionArguments();
101 substitutionMap.
insert(argument, newArgs[new_i]);
105 lambdaNode.
subregion()->
copy(newLambda->subregion(), substitutionMap);
107 std::vector<jlm::rvsdg::Output *> newResults;
112 newResults.push_back(&substitutionMap.
lookup(*result->origin()));
115 auto newLambdaOutput = newLambda->finalize(newResults);
132 static std::optional<rvsdg::GammaNode::ExitVar>
135 if (argument.
nusers() == 1)
138 if (rvsdg::TryGetRegionParentNode<rvsdg::GammaNode>(*user) == &gammaNode)
149 std::vector<rvsdg::GammaNode::EntryVar> deadEntryVars;
150 std::vector<rvsdg::Output *> deadGammaOutputs;
154 std::optional<rvsdg::GammaNode::ExitVar> exitvar0 =
157 bool shouldRemove = exitvar0
159 entryvar.branchArgument.begin(),
160 entryvar.branchArgument.end(),
163 auto exitvar = TryGetSingleUserExitVar(gammaNode, *argument);
164 return exitvar && exitvar->output == exitvar0->output;
169 exitvar0->output->divert_users(entryvar.input->origin());
170 deadEntryVars.push_back(entryvar);
171 deadGammaOutputs.push_back(exitvar0->output);
182 std::vector<rvsdg::ThetaNode::LoopVar> passthroughLoopVars;
187 loopVar.output->divert_users(loopVar.input->origin());
188 passthroughLoopVars.emplace_back(loopVar);
202 for (
size_t n = 0; n < structuralNode.
nsubregions(); n++)
211 else if (
auto thetaNode =
dynamic_cast<rvsdg::ThetaNode *
>(&structuralNode))
~UnusedStateRemoval() noexcept override
void Run(rvsdg::RvsdgModule &rvsdgModule, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
rvsdg::GraphExport * GetRvsdgExport() const noexcept
static std::unique_ptr< LlvmLambdaOperation > Create(std::shared_ptr< const jlm::rvsdg::FunctionType > type, std::string name, const jlm::llvm::Linkage &linkage, jlm::llvm::CallingConvention callingConvention, jlm::llvm::AttributeSet attributes)
static std::shared_ptr< const FunctionType > Create(std::vector< std::shared_ptr< const jlm::rvsdg::Type >> argumentTypes, std::vector< std::shared_ptr< const jlm::rvsdg::Type >> resultTypes)
Conditional operator / pattern matching.
void RemoveEntryVars(const std::vector< EntryVar > &entryVars)
Removes the given entry variables.
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.
static GraphExport & Create(Output &origin, std::string name)
Region & GetRootRegion() const noexcept
std::vector< rvsdg::Output * > GetFunctionArguments() const
rvsdg::Region * subregion() const noexcept
static LambdaNode * Create(rvsdg::Region &parent, std::unique_ptr< LambdaOperation > operation)
std::vector< rvsdg::Input * > GetFunctionResults() const
rvsdg::Output * output() const noexcept
std::vector< ContextVar > GetContextVars() const noexcept
Gets all bound context variables.
LambdaOperation & GetOperation() const noexcept override
const FunctionType & type() const noexcept
rvsdg::Region * region() const noexcept
size_t nusers() const noexcept
Represents the argument of a region.
Represent acyclic RVSDG subgraphs.
RegionResult * result(size_t index) const noexcept
size_t RemoveResults(const util::HashSet< size_t > &indices)
void copy(Region *target, SubstitutionMap &smap) const
Copy a region with substitutions.
Graph * graph() const noexcept
RegionArgument * argument(size_t index) const noexcept
size_t nsubregions() const noexcept
rvsdg::Region * subregion(size_t index) const noexcept
void insert(const Output *original, Output *substitute)
Output & lookup(const Output &original) const
void RemoveLoopVars(std::vector< LoopVar > loopVars)
Removes loop variables.
std::vector< LoopVar > GetLoopVars() const
Returns all loop variables.
static bool IsPassthroughResult(const rvsdg::Input &result)
static void RemoveUnusedStatesInRegion(rvsdg::Region ®ion)
static std::optional< rvsdg::GammaNode::ExitVar > TryGetSingleUserExitVar(rvsdg::GammaNode &gammaNode, rvsdg::Output &argument)
static void RemoveUnusedStatesFromThetaNode(rvsdg::ThetaNode &thetaNode)
static bool IsPassthroughArgument(const rvsdg::Output &argument)
static void RemoveUnusedStatesFromGammaNode(rvsdg::GammaNode &gammaNode)
static bool IsPassthroughLoopVar(const rvsdg::ThetaNode::LoopVar &loopVar)
static void RemoveUnusedStatesInStructuralNode(rvsdg::StructuralNode &structuralNode)
static void RemoveUnusedStatesFromLambda(rvsdg::LambdaNode &lambdaNode)
CallSummary ComputeCallSummary(const rvsdg::LambdaNode &lambdaNode)
static bool ThetaLoopVarIsInvariant(const ThetaNode::LoopVar &loopVar) noexcept
static void remove(Node *node)
Description of a loop-carried variable.
rvsdg::Output * pre
Variable before iteration (input argument to subregion).