Table of Contents

Class ControlFlow

Namespace
Graphity.ControlFlow
Assembly
Graphity.ControlFlow.dll

Relations of control flow that follow from Dominators, returned as graphs: the dominance frontiers and, from them, control dependence.

public static class ControlFlow
Inheritance
ControlFlow
Inherited Members

Examples

Here, for a method load with a for loop and an if in it, whose control flow cfg ends in the block exit:

Dominators postDominators =
    Dominators.Of(BiAdjacentGraph.Of(cfg).Transposed(), exit);
Graph controlDependence =
    BiAdjacentGraph.Of(ControlFlow.DominanceFrontiers(postDominators))
        .Transposed();
// header -> [header, body, next]: the loop condition decides whether they run
// body -> [then]: the if decides whether then runs

Remarks

A block is control dependent on another if that block decides whether it runs. Control dependence is the transposed graph of the dominance frontiers of the post-dominators. The post-dominators are the dominators of the transposed graph with the exits as entries. For the placement of phi-nodes, IteratedDominanceFrontier answers without building the dominance frontiers.

The class shares its name with the namespace Graphity.ControlFlow, as the Java class shares it with its package. Code in that namespace writes ControlFlow.DominanceFrontiers, and so does code outside the Graphity namespace that imports it with using Graphity.ControlFlow;. Code in another namespace below Graphity finds the namespace first and needs Graphity.ControlFlow.ControlFlow or a using alias.

Methods

DominanceFrontiers(Dominators)

Returns the dominance frontiers as a graph: an edge n -> m for every node m in the dominance frontier of n.

public static Graph DominanceFrontiers(Dominators dominators)

Parameters

dominators Dominators

The dominators of the control-flow graph.

Returns

Graph

The dominance frontiers, with the node IDs of the graph of dominators.

Remarks

The dominance frontier of n holds the nodes where its dominance ends: m is in it if n dominates an in-node of m but does not strictly dominate m. A node can be in its own dominance frontier, as the header of a natural loop is, so the result can have self-loops. Nodes that the entries do not reach have empty dominance frontiers and are in none.

Uses the algorithm of Cooper, Harvey and Kennedy. The result is computed anew on every call, not cached: keep it to use it more than once. It can grow quadratically with the node count, for example on deeply nested do-while loops.

Time: O(NodeCount + EdgeCount + frontierCount), where frontierCount is the number of edges of the result.
Memory: 4 x (NodeCount + frontierCount) bytes for the result; while it runs, as much again and 8 x NodeCount bytes more.

Exceptions

ArgumentException

The result would have more edges than a graph can have.