Jlm
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
jlm::rvsdg::LambdaNode Class Referencefinal

Lambda node. More...

#include <lambda.hpp>

Inheritance diagram for jlm::rvsdg::LambdaNode:
Inheritance graph
[legend]
Collaboration diagram for jlm::rvsdg::LambdaNode:
Collaboration graph
[legend]

Classes

struct  ArgumentVar
 Formal argument variable. More...
 
struct  ContextVar
 Bound context variable. More...
 

Public Member Functions

 ~LambdaNode () override
 
std::vector< rvsdg::Output * > GetFunctionArguments () const
 
std::vector< rvsdg::Input * > GetFunctionResults () const
 
rvsdg::Regionsubregion () const noexcept
 
LambdaOperationGetOperation () const noexcept override
 
ContextVar AddContextVar (jlm::rvsdg::Output &origin)
 Adds a context/free variable to the lambda node. More...
 
ContextVar MapInputContextVar (const rvsdg::Input &input) const noexcept
 Maps input to context variable. More...
 
std::optional< ContextVarMapBinderContextVar (const rvsdg::Output &output) const noexcept
 Maps bound variable reference to context variable. More...
 
std::vector< ContextVarGetContextVars () const noexcept
 Gets all bound context variables. More...
 
std::variant< ArgumentVar, ContextVarMapArgument (const rvsdg::Output &output) const
 Maps region argument to its disposition (formal argument or context var). More...
 
template<typename F >
size_t RemoveLambdaInputsWhere (const F &match)
 
size_t PruneLambdaInputs ()
 
rvsdg::Outputoutput () const noexcept
 
LambdaNodecopy (rvsdg::Region *region, const std::vector< jlm::rvsdg::Output * > &operands) const override
 
LambdaNodecopy (rvsdg::Region *region, rvsdg::SubstitutionMap &smap) const override
 Copy a node with substitutions. More...
 
rvsdg::Outputfinalize (const std::vector< jlm::rvsdg::Output * > &results)
 
- Public Member Functions inherited from jlm::rvsdg::StructuralNode
 ~StructuralNode () noexcept override
 
std::string DebugString () const override
 
size_t nsubregions () const noexcept
 
rvsdg::Regionsubregion (size_t index) const noexcept
 
SubregionIteratorRange Subregions ()
 
SubregionConstIteratorRange Subregions () const
 
StructuralInputinput (size_t index) const noexcept
 
StructuralOutputoutput (size_t index) const noexcept
 
- Public Member Functions inherited from jlm::rvsdg::Node
virtual ~Node ()
 
 Node (Region *region)
 
Id GetNodeId () const noexcept
 
size_t ninputs () const noexcept
 
NodeInputinput (size_t index) const noexcept
 
InputIteratorRange Inputs () noexcept
 
InputConstIteratorRange Inputs () const noexcept
 
size_t noutputs () const noexcept
 
NodeOutputoutput (size_t index) const noexcept
 
OutputIteratorRange Outputs () noexcept
 
OutputConstIteratorRange Outputs () const noexcept
 
bool IsDead () const noexcept
 Determines whether the node is dead. More...
 
std::size_t numSuccessors () const noexcept
 
size_t RemoveInputs (const util::HashSet< size_t > &indices)
 
size_t RemoveOutputs (const util::HashSet< size_t > &indices)
 
Graphgraph () const noexcept
 
rvsdg::Regionregion () const noexcept
 

Static Public Member Functions

static LambdaNodeCreate (rvsdg::Region &parent, std::unique_ptr< LambdaOperation > operation)
 

Private Member Functions

 LambdaNode (rvsdg::Region &parent, std::unique_ptr< LambdaOperation > op)
 

Private Attributes

std::unique_ptr< LambdaOperationOperation_
 

Friends

class LambdaBuilder
 

Additional Inherited Members

- Public Types inherited from jlm::rvsdg::Node
using Id = uint64_t
 
using InputIteratorRange = util::IteratorRange< Input::Iterator >
 
using InputConstIteratorRange = util::IteratorRange< Input::ConstIterator >
 
using OutputIteratorRange = util::IteratorRange< Output::Iterator >
 
using OutputConstIteratorRange = util::IteratorRange< Output::ConstIterator >
 
typedef util::IntrusiveListAccessor< Node, &Node::region_node_list_anchor_region_node_list_accessor
 
typedef util::IntrusiveListAccessor< Node, &Node::region_top_node_list_anchor_region_top_node_list_accessor
 
typedef util::IntrusiveListAccessor< Node, &Node::region_bottom_node_list_anchor_region_bottom_node_list_accessor
 
- Protected Member Functions inherited from jlm::rvsdg::StructuralNode
 StructuralNode (rvsdg::Region *region, size_t nsubregions)
 
StructuralInputaddInput (std::unique_ptr< StructuralInput > input, bool notifyRegion)
 
StructuralOutputaddOutput (std::unique_ptr< StructuralOutput > input)
 
- Protected Member Functions inherited from jlm::rvsdg::Node
NodeInputaddInput (std::unique_ptr< NodeInput > input, bool notifyRegion)
 
NodeOutputaddOutput (std::unique_ptr< NodeOutput > output)
 

Detailed Description

Lambda node.

A lambda node represents a lambda expression in the RVSDG. Its creation requires the invocation of two functions: Create() and finalize(). First, a node with only the function arguments is created by invoking Create(). The free variables of the lambda expression can then be added to the lambda node using the AddContextVar() method, and the body of the lambda node can be created. Finally, the lambda node can be finalized by invoking finalize().

The following snippet illustrates the creation of lambda nodes:

auto lambda = LambdaNode::create(...);
...
auto cv1 = lambda->AddContextVar(...);
auto cv2 = lambda->AddContextVar(...);
...
// generate lambda body
...
auto output = lambda->finalize(...);
rvsdg::Output * output() const noexcept
Definition: lambda.cpp:176

Definition at line 82 of file lambda.hpp.

Constructor & Destructor Documentation

◆ ~LambdaNode()

jlm::rvsdg::LambdaNode::~LambdaNode ( )
overridedefault

◆ LambdaNode()

jlm::rvsdg::LambdaNode::LambdaNode ( rvsdg::Region parent,
std::unique_ptr< LambdaOperation op 
)
private

Definition at line 40 of file lambda.cpp.

Member Function Documentation

◆ AddContextVar()

LambdaNode::ContextVar jlm::rvsdg::LambdaNode::AddContextVar ( jlm::rvsdg::Output origin)

Adds a context/free variable to the lambda node.

Parameters
originThe value to be bound into the lambda node.
Precondition
origin must be from the same region as the lambda node.
Returns
The context variable argument of the lambda abstraction.

Definition at line 131 of file lambda.cpp.

◆ copy() [1/2]

LambdaNode * jlm::rvsdg::LambdaNode::copy ( rvsdg::Region region,
const std::vector< jlm::rvsdg::Output * > &  operands 
) const
overridevirtual

Reimplemented from jlm::rvsdg::Node.

Definition at line 182 of file lambda.cpp.

◆ copy() [2/2]

LambdaNode * jlm::rvsdg::LambdaNode::copy ( rvsdg::Region region,
rvsdg::SubstitutionMap smap 
) const
overridevirtual

Copy a node with substitutions.

Parameters
regionTarget region to create node in
smapOperand substitutions
Returns
Copied node

Create a new node that is semantically equivalent to an existing node. The newly created node will use the same operands as the existing node unless there is a substitution registered for a particular operand.

The given substitution map is updated so that all outputs of the original node will be substituted by corresponding outputs of the newly created node in subsequent copy operations.

Implements jlm::rvsdg::Node.

Definition at line 188 of file lambda.cpp.

◆ Create()

LambdaNode * jlm::rvsdg::LambdaNode::Create ( rvsdg::Region parent,
std::unique_ptr< LambdaOperation operation 
)
static

Creates a lambda node in the region parent with the function type type and name name. After the invocation of Create(), the lambda node only features the function arguments. Free variables can be added to the function node using AddContextVar(). The generation of the node can be finished using the finalize() method.

Parameters
parentThe region where the lambda node is created.
operationOperational details for lambda node (including function signature).
Returns
A lambda node featuring only function arguments.

Definition at line 140 of file lambda.cpp.

◆ finalize()

rvsdg::Output * jlm::rvsdg::LambdaNode::finalize ( const std::vector< jlm::rvsdg::Output * > &  results)

Finalizes the creation of a lambda node.

Parameters
resultsThe result values of the lambda expression, originating from the lambda region.
Returns
The output of the lambda node.

Definition at line 146 of file lambda.cpp.

◆ GetContextVars()

std::vector< LambdaNode::ContextVar > jlm::rvsdg::LambdaNode::GetContextVars ( ) const
noexcept

Gets all bound context variables.

Returns
The context variable descriptions.

Returns all context variable descriptions.

Definition at line 119 of file lambda.cpp.

◆ GetFunctionArguments()

std::vector< rvsdg::Output * > jlm::rvsdg::LambdaNode::GetFunctionArguments ( ) const

Definition at line 57 of file lambda.cpp.

◆ GetFunctionResults()

std::vector< rvsdg::Input * > jlm::rvsdg::LambdaNode::GetFunctionResults ( ) const

Definition at line 69 of file lambda.cpp.

◆ GetOperation()

LambdaOperation & jlm::rvsdg::LambdaNode::GetOperation ( ) const
overridevirtualnoexcept

Implements jlm::rvsdg::Node.

Definition at line 51 of file lambda.cpp.

◆ MapArgument()

std::variant< LambdaNode::ArgumentVar, LambdaNode::ContextVar > jlm::rvsdg::LambdaNode::MapArgument ( const rvsdg::Output output) const

Maps region argument to its disposition (formal argument or context var).

Returns
A description of the role that this arguments plays.
Precondition
output must be an argument to the subregion of this node.

Definition at line 104 of file lambda.cpp.

◆ MapBinderContextVar()

std::optional< LambdaNode::ContextVar > jlm::rvsdg::LambdaNode::MapBinderContextVar ( const rvsdg::Output output) const
noexcept

Maps bound variable reference to context variable.

Parameters
outputRegion argument to lambda subregion
Returns
The context variable description corresponding to the argument
Precondition
output must be an argument to the subregion of this node

Returns the context variable description corresponding to this bound variable reference in the lambda node region. Note that some arguments of the region are formal call arguments and do not have an associated context variable description.

Definition at line 88 of file lambda.cpp.

◆ MapInputContextVar()

LambdaNode::ContextVar jlm::rvsdg::LambdaNode::MapInputContextVar ( const rvsdg::Input input) const
noexcept

Maps input to context variable.

Parameters
inputInput to the lambda node.
Returns
The context variable description corresponding to the input.
Precondition
input must be input to this node.

Returns the context variable description corresponding to this input of the lambda node. All inputs to the lambda node are by definition bound context variables that are accessible in the subregion through the corresponding argument.

Definition at line 80 of file lambda.cpp.

◆ output()

rvsdg::Output * jlm::rvsdg::LambdaNode::output ( ) const
noexcept

Definition at line 176 of file lambda.cpp.

◆ PruneLambdaInputs()

size_t jlm::rvsdg::LambdaNode::PruneLambdaInputs ( )
inline

Remove all dead inputs.

Returns
The number of removed inputs.
See also
RemoveLambdaInputsWhere()

Definition at line 245 of file lambda.hpp.

◆ RemoveLambdaInputsWhere()

template<typename F >
size_t jlm::rvsdg::LambdaNode::RemoveLambdaInputsWhere ( const F &  match)

Remove lambda inputs and their respective arguments.

An input must match the condition specified by match and its argument must be dead.

Template Parameters
FA type that supports the function call operator: bool operator(const rvsdg::input&)
Parameters
matchDefines the condition of the elements to remove.
Returns
The number of removed inputs.

Definition at line 296 of file lambda.hpp.

◆ subregion()

rvsdg::Region* jlm::rvsdg::LambdaNode::subregion ( ) const
inlinenoexcept

Definition at line 138 of file lambda.hpp.

Friends And Related Function Documentation

◆ LambdaBuilder

friend class LambdaBuilder
friend

Definition at line 291 of file lambda.hpp.

Member Data Documentation

◆ Operation_

std::unique_ptr<LambdaOperation> jlm::rvsdg::LambdaNode::Operation_
private

Definition at line 289 of file lambda.hpp.


The documentation for this class was generated from the following files: