When inspecting the graph for analysis it is necessary to identify different nodes/operations and structures. Depending on the direction, the two fundamental questions of interest are:
- what is the origin of a value, what operation is computing it?
- what are the users of a particular value, what operations depend on it?
This requires resolving the type of operation a specific rvsdg::Input or rvsdg::Output belong to. Every rvsdg::Output is one of the following:
- the output of a node representing an operation
- the entry argument into a region
Likewise, every rvsdg::Input is one of the following:
- the input of a node representing an operation
- the exit result of a region
Analysis code can determine which of the two is the case using rvsdg::Output::GetOwner and rvsdg::Input::GetOwner, respectively, and then branch deeper based on its results. For convenience, code can more directly match against the specific kinds of nodes using the following convenience functions:
- rvsdg::TryGetOwnerNode checks if the owner of an output/input is a graph node of the requested kind
- rvsdg::TryGetRegionParentNode checks if the output/input is a region entry argument / exit result, and if the parent node of the region is of the requested kind
Example:
if (auto lambda = rvsdg::TryGetOwnerNode<LambdaNode>(def))
{
}
else if (auto gamma = rvsdg::TryGetOwnerNode<GammaNode>(def))
{
}
else if (auto gamma = rvsdg::TryGetRegionParentNode<GammaNode>(def))
{
}
Similarly, the following variants of the accessor functions assert that the nodes are of requested type and will throw an exception otherwise:
- rvsdg::AssertGetOwnerNode asserts that the owner of an output/input is a graph node of the requested kind and returns it.
- rvsdg::AssertGetRegionParentNode asserts that the output/input is a region entry argument / exit result, and that the parent node of the region is of the requested kind
These are mostly suitable for unit tests rather, or for the rare circumstances that the type of node can be assumed to be known statically.