Intermediate Representation
Control Flow Graphs:
Each instruction in a function has a set of possible successor instruction in that function
is a Directed Graph
- : instructions of the function
- : iff is a possible successor of
- : is the root node with no predecessor
IR’s typically are intra-functional and control flow between functions is not modelled by CFGs
Basic Blocks:
Is a sequence of instructions with the following properties.
- the first node has multiple predecessors
- the last node has multiple successors
- the nodes in the between have exactly one predecessor and one successor
Critical Edges:
A edge in the control graph that goes from a basic block with multiple successor to a node with multiple predecessor
Dominance:
For a connected , a node dominates node if for every path from the root node to the node passes through node
That is to say if we want to reach from the root , we have to pass through .
Theorem1:
Dominance is a Partial Ordered Relation.
Reflexive: Every basic block/node dominates itself
AntiSymmetric: If and then
Transitive: if and then
Theorem2:
If and either or
If there are two different nodes that are dominating a third node, then one has to dominate the other.
Corollary:
- All dominators of a particular node have a total ordering among them
- Except for the root node that has no dominators, for every node there is an immediate dominator .
- is a tree.
Post Dominance:
Dual of the dominance relation.
Consider a CFG with a unique exit node .
A node post dominates a node if all paths from to have to go through
SESE - Single Entry Single Exit:
A set of nodes that are dominated by a node and are post dominated by a node form a set of single entry and single exit nodes.
The notion of dominance is important as we want to identify set of nodes that are executed under same control flow conditions.
Control Flow Dependence:
A node is control dependent on an edge if
- node post dominates : Thus if is executed then has to be executed.
- : Thus, is not post dominated by : Thus the control condition at node determines the execution of the node
Depth First Search:
Using DFS we can classify each edge as:
- forward edge: is an ancestor of
- retreat edge: is an ancestor of
- cross edges: otherwise
A DAG form a CFG is obtained by removing all the retreat edges.
Reducibility:
A class of practically important CFGs are Reducible CFGs
A graph G is called reducible if for every retreat edge ,
such an edge is called a back edge and the node is called header.
Presence of a retreat edge in CFG means that there is a loop. Now if retreat edge is a back edge then the only entry in the loop is through the header node .
Theorem:
The following three statements are equivalent.
- G is reducible
- G has a unique DAG: To not have a unique DAG there has to be multiple entry in the loop. but here since the header dominates all the nodes in a cycle there is a single entry in the loop.
- for all the cycles in G, all the nodes in the cycle are dominated by a single node. i.e. header
Loop Nesting:
The natural loop of a back edge is the set of all the nodes that reach without going through
Natural loop is a set of the nodes that follow the above condition
Theorem:
For two loops and one of the following conditions hold:
- or
