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:

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
StartABCDEFGEND
Startxxxxxxxxx
Axxxxxxx
Bx
Cxxxxx
Dx
Ex
Fxx
Gx
ENDx
Link to original

ABCDEFG
Startaxxxx
fbxxx
cdx
cex
abx

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:

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.