Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dominators and CFGs Taken largely from University of Delaware Compiler Notes.

Similar presentations


Presentation on theme: "Dominators and CFGs Taken largely from University of Delaware Compiler Notes."— Presentation transcript:

1

2 Dominators and CFGs Taken largely from University of Delaware Compiler Notes

3 Dominators Node (basic block) D in a CFG dominates node N if every path from the start node to N goes through D. We say that node D is a dominator of node N. Define dom(N) = set of node N’s dominators, or the dominator set for node N. Note: by definition, each node dominates itself i.e., N  dom(N).

4 Domination relation: An Example 1 2 3 4 5 6 7 8 9 10 S { (1, 1), (1, 2), (1, 3), (1, 4) … (2, 3), (2, 4), … (2, 10) } Direct domination: DOM : 1 < d 2, 2 < d 3, … DOM(1) = {1} DOM(2) = {1, 2} DOM(3) = {1, 2, 3} DOM(10) = {1, 2, 10)

5 Immediate Dominators and Dominator Tree Node M is the immediate dominator of node N ==> Node M must be the last dominator of N on any path from the start node to N. Therefore, every node other than the start node must have a unique immediate dominator (the start node has no immediate dominator.) What does this mean ?

6 Dominator Tree 1 2 3 4 5 6 7 8 9 10 S 1 2 3 4 5 7 8 6 9 A flowgraph (left) and its dominator tree (right)

7 Question Assume an immediate dominator n’ of a node n, is n’ necessarily an immediate predecessor in the flow graph? Answer: NO! Example: consider nodes 5 and 8.

8 1 2 3 4 7 5 6 8 9 10 An Example (Dominators)

9 Depth-First Search (DFS) zAn “ordering” of nodes of CFG zBBs dfs_nums 1..N zEach BB dfs_num represents when that BB first encountered in DFS zWrite dfs(BB root);

10 DFS and Depth-First Order zCONFUSING: They are NOT the same zDFS as defined: order of first visitation during depth-first search zDepth-First Order y“The depth-first ordering of the nodes is the reverse of the order in which we last visit the nodes in a preorder traversal” (Aho-Sethi-Ullman) yUsed (sometimes) to identify loops yLater …

11 1 2 3 4 7 5 6 8 9 10 An Example DFS


Download ppt "Dominators and CFGs Taken largely from University of Delaware Compiler Notes."

Similar presentations


Ads by Google