16 : type_(std::move(
type))
32 std::unique_ptr<rvsdg::Operation>
35 return std::make_unique<LambdaOperation>(*
this);
42 Operation_(std::move(op))
56 [[nodiscard]] std::vector<rvsdg::Output *>
59 std::vector<rvsdg::Output *> arguments;
61 for (std::size_t n = 0; n <
type->Arguments().size(); ++n)
63 arguments.push_back(
subregion()->argument(n));
68 [[nodiscard]] std::vector<rvsdg::Input *>
71 std::vector<rvsdg::Input *> results;
82 JLM_ASSERT(rvsdg::TryGetOwnerNode<LambdaNode>(input) ==
this);
84 subregion()->argument(GetOperation().Type()->NumArguments() + input.index()) };
87 [[nodiscard]] std::optional<LambdaNode::ContextVar>
91 auto numArguments = GetOperation().Type()->NumArguments();
92 if (output.index() >= numArguments)
94 return ContextVar{ input(output.index() - GetOperation().
Type()->NumArguments()),
103 std::variant<LambdaNode::ArgumentVar, LambdaNode::ContextVar>
118 [[nodiscard]] std::vector<LambdaNode::ContextVar>
121 std::vector<ContextVar> vars;
122 for (
size_t n = 0; n <
ninputs(); ++n)
134 addInput(std::make_unique<StructuralInput>(
this, &origin, origin.
Type()),
true);
142 return new LambdaNode(parent, std::move(operation));
158 for (
size_t n = 0; n < results.size(); n++)
161 auto & received = *results[n]->
Type();
163 throw util::Error(
"Expected " + expected.debug_string() +
", got " + received.debug_string());
169 for (
const auto & origin : results)
193 std::unique_ptr<LambdaOperation>(util::assertedCast<LambdaOperation>(op.copy().release())));
199 auto origin = &smap.
lookup(*cv.input->origin());
200 subregionmap.
insert(cv.inner, lambda->AddContextVar(*origin).inner);
205 auto newArgs = lambda->GetFunctionArguments();
207 for (std::size_t n = 0; n < args.size(); ++n)
209 subregionmap.
insert(args[n], newArgs[n]);
216 std::vector<jlm::rvsdg::Output *> results;
218 results.push_back(&subregionmap.
lookup(*result->origin()));
221 auto o = lambda->finalize(results);
238 std::vector<Output *>
261 const std::vector<jlm::rvsdg::Output *> & results,
262 std::unique_ptr<LambdaOperation> op)
281 throw std::logic_error(
"node was not in a lambda");
const jlm::rvsdg::Type & ResultType(size_t index) const noexcept
Output & Finalize(const std::vector< jlm::rvsdg::Output * > &results, std::unique_ptr< LambdaOperation > op)
Verifies well-formedness of lambda node and completes it.
LambdaNode::ContextVar AddContextVar(jlm::rvsdg::Output &origin)
Adds a context/free variable to the lambda node.
rvsdg::Region * GetRegion() noexcept
Returns region to place nodes in.
LambdaBuilder(Region ®ion, std::vector< std::shared_ptr< const Type >> argtypes)
Creates builder for a lambda construct.
std::vector< Output * > Arguments()
Obtains definition points of parameters to the function.
LambdaNode * copy(rvsdg::Region *region, const std::vector< jlm::rvsdg::Output * > &operands) const override
rvsdg::Output * finalize(const std::vector< jlm::rvsdg::Output * > &results)
std::variant< ArgumentVar, ContextVar > MapArgument(const rvsdg::Output &output) const
Maps region argument to its disposition (formal argument or context var).
std::vector< rvsdg::Output * > GetFunctionArguments() const
rvsdg::Region * subregion() const noexcept
ContextVar MapInputContextVar(const rvsdg::Input &input) const noexcept
Maps input to context variable.
std::optional< ContextVar > MapBinderContextVar(const rvsdg::Output &output) const noexcept
Maps bound variable reference to context variable.
ContextVar AddContextVar(jlm::rvsdg::Output &origin)
Adds a context/free variable to the lambda node.
LambdaNode(rvsdg::Region &parent, std::unique_ptr< LambdaOperation > op)
std::unique_ptr< LambdaOperation > Operation_
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
LambdaOperation(std::shared_ptr< const FunctionType > type)
bool operator==(const Operation &other) const noexcept override
const FunctionType & type() const noexcept
const std::shared_ptr< const FunctionType > & Type() const noexcept
std::unique_ptr< Operation > copy() const override
~LambdaOperation() override
std::string debug_string() const override
rvsdg::Region * region() const noexcept
size_t ninputs() const noexcept
size_t noutputs() const noexcept
virtual Node * copy(rvsdg::Region *region, const std::vector< jlm::rvsdg::Output * > &operands) const
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
size_t index() const noexcept
static RegionArgument & Create(rvsdg::Region ®ion, StructuralInput *input, std::shared_ptr< const rvsdg::Type > type)
Creates region entry argument.
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.
RegionResult * result(size_t index) const noexcept
void copy(Region *target, SubstitutionMap &smap) const
Copy a region with substitutions.
rvsdg::StructuralNode * node() const noexcept
size_t nresults() const noexcept
RegionArgument * argument(size_t index) const noexcept
StructuralInput * addInput(std::unique_ptr< StructuralInput > input, bool notifyRegion)
StructuralOutput * addOutput(std::unique_ptr< StructuralOutput > input)
StructuralOutput * output(size_t index) const noexcept
StructuralInput * input(size_t index) const noexcept
void insert(const Output *original, Output *substitute)
Output & lookup(const Output &original) const
constexpr Type() noexcept
static std::string type(const Node *n)
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
Region * TryGetOwnerRegion(const rvsdg::Input &input) noexcept
rvsdg::LambdaNode & getSurroundingLambdaNode(rvsdg::Node &node)
static std::string strfmt(Args... args)
Formal argument variable.