Idea
Intuitively, node is control-dependent on a node if determines whether is executed.
Example of Basic Control Dependence
In this case, we would say that S1 and S2 are control-dependent on e.
Example of Self Control Dependence
In this case, we would say:
- S1 is control-dependent on e.
- e is control dependent on
START
and itself
Example with Transitive Control Dependence
In this case, we would say:
- S1 and S3 are control-dependent on f
- They are transitively dependent on e, but e does not fully determine if S1 or S3 are executed, so S1 and S3 are not control-dependent on e
- However, we can say that f is control-dependent on e and S1 and S3 are transitively control-dependent on e
Definition
For to be control-dependent on edge , must postdominate for some CFG successor of , can not be , and can not .
Intuitively, if control flows from to , it is guaranteed that will be executed. But from we can reach END
without encountering , so there is a decision being made at that determines whether or not is executed.
As a result, we can rewrite this to be:
- does not strictly postdominate
Example
Using the example from before:
Example CFG
graph TD A[START] --> B(a) B --> C(b) C --> D(c) D --> E{d} D --> F{e} E --> G(f) F --> G G --> C B --> D G --> H(g) H --> I[END] A --> I
Link to original
Start A B C D E F G END Start x x x x x x x x x A x x x x x x x B x C x x x x x D x E x F x x G x END x
A | B | C | D | E | F | G | |
---|---|---|---|---|---|---|---|
Start→a | x | x | x | x | |||
f→b | x | x | x | ||||
c→d | x | ||||||
c→e | x | ||||||
a→b | x |
An x
marks control dependence. This is not transitive control dependence.
Computing Control-Dependence Relation
Given a CFG , a node is control-dependent on an edge if:
- postdominates
- does not strictly postdominate
Nodes control dependent on edge are nodes on the path up from the postdominator tree from to excluding
- Written as
- Half-open interval in tree
Overlay each edge on pdom tree and determine nodes in interval . The time and space complexity is .
However, in practice, we don’t want the full relation and only make queries:
- cd(): what are the nodes control-dependent on an edge
- conds(): what are the edges that is is control-dependent on
- cdequiv(): what nodes have the same control-dependences as node
It is possible to create a simple data structure that takes time and space to build and that answers these queries in time proportional to the output of the query.