Jlm
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
jlm::rvsdg::GammaNode Class Reference

Conditional operator / pattern matching. More...

#include <gamma.hpp>

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

Classes

struct  EntryVar
 A variable routed into all gamma regions. More...
 
struct  ExitVar
 A variable routed out of all gamma regions as result. More...
 
struct  MatchVar
 The match/discriminator variable of this gamma node. More...
 

Public Member Functions

 ~GammaNode () noexcept override
 
const GammaOperationGetOperation () const noexcept override
 
rvsdg::Inputpredicate () const noexcept
 
EntryVar AddEntryVar (rvsdg::Output *origin)
 Routes a variable into the gamma branches. More...
 
MatchVar GetMatchVar () const
 
std::vector< EntryVarGetEntryVars () const
 Gets all entry variables for this gamma. More...
 
std::variant< MatchVar, EntryVarMapInput (const rvsdg::Input &input) const
 Maps gamma input to its role (match variable or entry variable). More...
 
std::variant< MatchVar, EntryVarMapBranchArgument (const rvsdg::Output &output) const
 Maps branch subregion entry argument to its role (pattern match or entry variable). More...
 
ExitVar AddExitVar (std::vector< rvsdg::Output * > values)
 Routes per-branch result of gamma to output. More...
 
std::vector< ExitVarGetExitVars () const
 Gets all exit variables for this gamma. More...
 
ExitVar MapOutputExitVar (const rvsdg::Output &output) const
 Maps gamma output to exit variable description. More...
 
ExitVar MapBranchResultExitVar (const rvsdg::Input &input) const
 Maps gamma region exit result to exit variable description. More...
 
void RemoveExitVars (const std::vector< ExitVar > &exitVars)
 Removes the given exit variables. More...
 
void RemoveEntryVars (const std::vector< EntryVar > &entryVars)
 Removes the given entry variables. More...
 
void PruneExitVars ()
 
GammaNodecopy (jlm::rvsdg::Region *region, SubstitutionMap &smap) const override
 Copy a node with substitutions. More...
 
- 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
 
virtual Nodecopy (rvsdg::Region *region, const std::vector< jlm::rvsdg::Output * > &operands) const
 

Static Public Member Functions

static GammaNodecreate (jlm::rvsdg::Output *predicate, size_t nalternatives)
 
static GammaNodeCreate (jlm::rvsdg::Output &predicate, size_t numAlternatives, std::vector< std::shared_ptr< const Type >> matchContentTypes)
 
static GammaNodeCreate (jlm::rvsdg::Output &predicate, std::unique_ptr< GammaOperation > op)
 

Private Member Functions

 GammaNode (rvsdg::Output &predicate, std::unique_ptr< GammaOperation > op)
 
 GammaNode (rvsdg::Output &predicate, size_t nalternatives, std::vector< std::shared_ptr< const Type >> match_content_types)
 
EntryVar GetEntryVar (std::size_t index) const
 Gets entry variable by index. More...
 

Private Attributes

std::unique_ptr< GammaOperationOperation_
 

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

Conditional operator / pattern matching.

Gamma nodes discriminate over a given value and conditionally select one of its subregions. In its simplest form, they correspond to an if/else statement:

if (pred) { branch1(); } else { branch0(); }

More generically, they perform pattern-matching over a finitely- constructed type:

match shape with
| Circle x y r => ...
| Rect x1 y1 x2 y2 => ...
| Poly points => ...
end
jlm::rvsdg::Output * match(size_t nbits, const std::unordered_map< uint64_t, uint64_t > &mapping, uint64_t default_alternative, size_t nalternatives, jlm::rvsdg::Output *operand)
Definition: control.cpp:179

where the "contents" of the match is made available in its corresponding branch. Simple types such as booleans do not have any content and thus produce the content-less UnitType as placeholder for the destructured content – so effectively Gamma then corresponds to:

match pred with
| false => branch1
| true => branch0
end

Definition at line 98 of file gamma.hpp.

Constructor & Destructor Documentation

◆ ~GammaNode()

jlm::rvsdg::GammaNode::~GammaNode ( )
overridedefaultnoexcept

◆ GammaNode() [1/2]

jlm::rvsdg::GammaNode::GammaNode ( rvsdg::Output predicate,
std::unique_ptr< GammaOperation op 
)
private

Definition at line 228 of file gamma.cpp.

◆ GammaNode() [2/2]

jlm::rvsdg::GammaNode::GammaNode ( rvsdg::Output predicate,
size_t  nalternatives,
std::vector< std::shared_ptr< const Type >>  match_content_types 
)
private

Definition at line 244 of file gamma.cpp.

Member Function Documentation

◆ AddEntryVar()

GammaNode::EntryVar jlm::rvsdg::GammaNode::AddEntryVar ( rvsdg::Output origin)

Routes a variable into the gamma branches.

Parameters
originValue to be routed in.
Returns
Description of entry variable.

Routes a variable into a gamma region. To access the variable in each branch use EntryVar::branchArgument.

Definition at line 260 of file gamma.cpp.

◆ AddExitVar()

GammaNode::ExitVar jlm::rvsdg::GammaNode::AddExitVar ( std::vector< rvsdg::Output * >  values)

Routes per-branch result of gamma to output.

Parameters
valuesValue to be routed out.
Returns
Description of exit variable.

Routes per-branch values for a particular variable out of the gamma regions and makes it available as output of the gamma node.

Definition at line 342 of file gamma.cpp.

◆ copy()

GammaNode * jlm::rvsdg::GammaNode::copy ( jlm::rvsdg::Region region,
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 439 of file gamma.cpp.

◆ Create() [1/2]

static GammaNode& jlm::rvsdg::GammaNode::Create ( jlm::rvsdg::Output predicate,
size_t  numAlternatives,
std::vector< std::shared_ptr< const Type >>  matchContentTypes 
)
inlinestatic

Definition at line 167 of file gamma.hpp.

◆ Create() [2/2]

static GammaNode& jlm::rvsdg::GammaNode::Create ( jlm::rvsdg::Output predicate,
std::unique_ptr< GammaOperation op 
)
inlinestatic

Definition at line 176 of file gamma.hpp.

◆ create()

static GammaNode* jlm::rvsdg::GammaNode::create ( jlm::rvsdg::Output predicate,
size_t  nalternatives 
)
inlinestatic

Definition at line 161 of file gamma.hpp.

◆ GetEntryVar()

GammaNode::EntryVar jlm::rvsdg::GammaNode::GetEntryVar ( std::size_t  index) const
private

Gets entry variable by index.

Parameters
indexIndex of entry variable
Returns
Description of entry variable.

Looks up the index 'th entry variable into the gamma node and returns its description.

Definition at line 278 of file gamma.cpp.

◆ GetEntryVars()

std::vector< GammaNode::EntryVar > jlm::rvsdg::GammaNode::GetEntryVars ( ) const

Gets all entry variables for this gamma.

Definition at line 303 of file gamma.cpp.

◆ GetExitVars()

std::vector< GammaNode::ExitVar > jlm::rvsdg::GammaNode::GetExitVars ( ) const

Gets all exit variables for this gamma.

Definition at line 361 of file gamma.cpp.

◆ GetMatchVar()

GammaNode::MatchVar jlm::rvsdg::GammaNode::GetMatchVar ( ) const

Definition at line 291 of file gamma.cpp.

◆ GetOperation()

const GammaOperation & jlm::rvsdg::GammaNode::GetOperation ( ) const
overridevirtualnoexcept

Implements jlm::rvsdg::Node.

Definition at line 254 of file gamma.cpp.

◆ MapBranchArgument()

std::variant< GammaNode::MatchVar, GammaNode::EntryVar > jlm::rvsdg::GammaNode::MapBranchArgument ( const rvsdg::Output output) const

Maps branch subregion entry argument to its role (pattern match or entry variable).

Parameters
outputThe branch argument to be mapped.
Returns
The entry variable description corresponding to this input
Precondition
output must be the entry argument to a subregion of this gamma nade.

Maps the subregion entry argument to the variable description corresponding to it (the predicate + pattern matches, or an entry variable into this branch). This allows to trace the value to users in other branches as well as its def site preceding the gamma node:

Definition at line 328 of file gamma.cpp.

◆ MapBranchResultExitVar()

GammaNode::ExitVar jlm::rvsdg::GammaNode::MapBranchResultExitVar ( const rvsdg::Input input) const

Maps gamma region exit result to exit variable description.

Parameters
inputThe result to be mapped to be mapped.
Returns
The exit variable description corresponding to this output.
Precondition
input must be a result of a subregion of this node.

Maps the gamma region result to the exit variable description corresponding to it.

Definition at line 389 of file gamma.cpp.

◆ MapInput()

std::variant< GammaNode::MatchVar, GammaNode::EntryVar > jlm::rvsdg::GammaNode::MapInput ( const rvsdg::Input input) const

Maps gamma input to its role (match variable or entry variable).

Parameters
inputInput to be mapped.
Returns
The variable description corresponding to this input
Precondition
input must be an input of this node

Maps the gamma input to the variable description corresponding to it. This is either the "match" or "predicate" of the gamma, or an entry variable for values used inside the region. This allows to trace the value through to users in the gamma subregions.

Definition at line 314 of file gamma.cpp.

◆ MapOutputExitVar()

GammaNode::ExitVar jlm::rvsdg::GammaNode::MapOutputExitVar ( const rvsdg::Output output) const

Maps gamma output to exit variable description.

Parameters
outputOutput to be mapped.
Returns
The exit variable description corresponding to this output.
Precondition
output must be an output of this node.

Maps the gamma output to the exit variable description corresponding to it. This allows to trace the value through to users in the gamma subregions.

Definition at line 377 of file gamma.cpp.

◆ predicate()

rvsdg::Input * jlm::rvsdg::GammaNode::predicate ( ) const
inlinenoexcept

Definition at line 398 of file gamma.hpp.

◆ PruneExitVars()

void jlm::rvsdg::GammaNode::PruneExitVars ( )
inline

Remove all exit variables where the variables' output is dead.

See also
Output::IsDead()

Definition at line 337 of file gamma.hpp.

◆ RemoveEntryVars()

void jlm::rvsdg::GammaNode::RemoveEntryVars ( const std::vector< EntryVar > &  entryVars)

Removes the given entry variables.

Precondition
All entry variables must be unused in the gamma branch subregions (= the corresponding region arguments must not have any users).

Removes the variables as entry variables from this gamma.

Definition at line 420 of file gamma.cpp.

◆ RemoveExitVars()

void jlm::rvsdg::GammaNode::RemoveExitVars ( const std::vector< ExitVar > &  exitVars)

Removes the given exit variables.

Precondition
All exit variables must be unused (= the corresponding gamma outputs must not have any users).

Removes the variables as exit variables from this gamma.

Definition at line 401 of file gamma.cpp.

Member Data Documentation

◆ Operation_

std::unique_ptr<GammaOperation> jlm::rvsdg::GammaNode::Operation_
private

Definition at line 370 of file gamma.hpp.


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