200 likes | 223 Vues
Extended Basic Blocks & Dominators. Prof. M. Rajasekhara Babu School of Computing Science and Engineering mrajasekharababu@vit.ac.in http://www.mrajababu.com. OutLine. Re-Cap Extended Basic Blocks Definition Example Practice Problem Algorithm Dominators Introduction Properties
E N D
Extended Basic Blocks & Dominators Prof. M. Rajasekhara Babu School of Computing Science and Engineering mrajasekharababu@vit.ac.in http://www.mrajababu.com
OutLine • Re-Cap • Extended Basic Blocks • Definition • Example • Practice Problem • Algorithm • Dominators • Introduction • Properties • Example & Practice Problem • Strict Dominators • Post Dominators • Immediate Dominators • Assignment • References
Re-Cap 1. List of other Intermediate Representation? 2. Distinguish between Syntax tree and DAG 3. Tell about structure of Quadruples 4. Tell about structure of Triples 5. List functions to create syntax tree
Objectives & Teaching Learning Material • Session Objectives • To provide the knowledge on Extended basic blocks and dominators. • At the end topic student able to identify Extended basic blocks and able to compute dominators of CFG. • Teaching Learning Material • LCD, White board Marker, Presentation slides
Extended Basic Blocks An extended basic block is defined as maximal sub graph of CFG which doesn't have join nodes An EBB is a set of blocks B1 B2 B3…….Bn where Bi may have multiple predecessors and every other Bi has a unique predecessor. The block Bi form a tree that can be entered only at its root B1 Bcan have multiple exits
Example Entry B1 Root Nodes: {Entry, B1,B4,B5,Exit} B3 B2 Successor nodes for Root Node Entry {Entry} B4 Successor nodes for Root Node B1 {B1,B2,B3} Successor nodes for Root Node B4 {B4,B6} B5 B6 Successor nodes for Root Node B5 {B5,B7} B7 Successor nodes for Root Node Exit {Exit} Exit
Entry Example A Root Nodes: C B Successor nodes for Root Node Entry E D Successor nodes for Root Node Successor nodes for Root Node F Successor nodes for Root Node G Successor nodes for Root Node Exit Exit
Dominators & PostDominators • Introduction: • Dominator is a binary relation on a flow graph nodes • Dominance is the one of the oldest idea in compilation • Computation of Dominators • In a CFG, node ‘i’ denotes node j if every path from the entry node to j passes through i. • i dominates j , written as I dom j
Properties of Dominators • Reflexive: Evey node dominates inteslf • Transitive If a dom b and b dom c then a dom c • Antisymmetric if a dom b and b dom a then b=a
1 2 3 4 5 7 6 8 9 10 Example
Strict Dominators • A CFG node M strictly dominates (M Sdom N ) iff M dom N and M≠N • A Node can’t strictly dominates itself • N Sdom N is never true • Data flow Equation to compute Dominators Dom(n)={n} u (∩pЄ Pred(n) DOM(P))
Immediate Dominators • If a CFG node has more than one dominator ( Which is common), there is always a unique closet dominator called its Immediate Dominators. • Immediate dominator m that is the last dominator of n on any path from the initial node to n • Using immediate dominators, we can create a dominator tree in which A→B in the dominator tree if and only if (A idom B).
Algorithm Temp(n) Dominators(n)-{n} 1.Identify strict Dominators 2. r entry For each n Є N-{r} do For each S Є Temp(n) do if t Є Temp(n) then Temp(n)=Temp(n)-{s} For each n Є N-{r} do Idom(n) =Temp(n) Return Idom
1 2 3 4 5 7 6 8 9 10 Example
Post Dominators • A block Z postdominates a block Y (Z pdom Y) if and only if all paths from Y to an exit block must pass through Z. • Notions of immediate postdominance and a postdominator tree carry over. • If a node p post dominates node i, written as p dom i.
Assignment • Write a pseudo code for the computation of Extended Basic Block ( Ref: Steven Muchnick: Advanced Compiler Design and Implementation. Morgan Kaufmann, 1997, page No:175,176,177) • Write C /java code to compute dominators, immediate dominators and post dominators ( Ref: Steven Muchnick: Advanced Compiler Design and Implementation. Morgan Kaufmann, 1997,
References • Steven Muchnick: Advanced Compiler Design and Implementation. Morgan Kaufmann, 1997 • Alfred Aho, Ravi Sethi, Jeffrey Ullman, Monica Lam: 21st Century Compilers. Addison-Wesley, 2004.