1 / 25

Optimizing Compilers CISC 673 Spring 2009 More Control Flow

Optimizing Compilers CISC 673 Spring 2009 More Control Flow. John Cavazos University of Delaware. Clarification. Leaders are The entry point of the function Any instruction that is a target of a branch Any instruction following a (conditional or unconditional ) branch.

lmiles
Download Presentation

Optimizing Compilers CISC 673 Spring 2009 More Control Flow

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Optimizing CompilersCISC 673Spring 2009More Control Flow John Cavazos University of Delaware

  2. Clarification • Leaders are • The entry point of the function • Any instruction that is a target of a branch • Any instruction following a (conditional or unconditional) branch

  3. Additional Clarification Tree edge: in CFG & ST Advancing edge: (v,w) not tree edge but w is descendant of v in ST Back edge: (v,w): v=w or w is proper ancestor of v in ST Cross edge: (v,w): w neither ancestor nor descendant of v in ST

  4. Class Problem: Identify Edges procedure DFST (v) pre(v) = vnum++ InStack(v) = true for w in Succ(v) if not InTree(w) add v→w to TreeEdges InTree(w) = true DFST(w) else if pre(v) < pre(w) add v→w to AdvancingEdges else if InStack(w) add v→w to BackEdges else add v→w to CrossEdges InStack(v) = false for v in V do inTree(v) = false vnum = 0 InTree(root) DFST(root)

  5. Class Problem: Answer procedure DFST (v) pre(v) = vnum++ InStack(v) = true for w in Succ(v) if not InTree(w) add v→w to TreeEdges InTree(w) = true DFST(w) else if pre(v) < pre(w) add v→w to AdvancingEdges else if InStack(w) add v→w to BackEdges else add v→w to CrossEdges InStack(v) = false for v in V do inTree(v) = false vnum = 0 InTree(root) DFST(root)

  6. Reducibility • Natural loops: • single entry node: no jumps into middle of loop • requires back edge into loop header (single entry point) • Reducible: hierarchical, “well-structured” • flowgraph reducible iff all loops in it natural

  7. Reducibility Example • Some languages only permit procedures with reducible flowgraphs (e.g., Java) • “GOTO Considered Harmful”:introduces irreducibility • FORTRAN • C • C++ • DFST does not find unique header in irreducible graphs reducible graph irreducible graph

  8. Dominance • Node ddominates node i (“d dom i” )if every path from Entry to i includes d • Reflexive: a dom a • 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

  9. Immediate Dominance • aidomb iff a dom bthere is no c such that a dom c, c dom b (c  a, c  b) • Idom’s: • each node has unique idom • relation forms a dominator tree

  10. Dominance Tree • Immediate and other dominators:(excluding Entry) • a idom b; a dom a, b, c, d, e, f, g • b idom c; b dom b, c, d, e, f, g • c idom d; c dom c, d, e, f, g • d idom e; d dom d, e, f, g • e idom f, e idom g; e dom e, f, g control-flow graph dominator tree

  11. Dominator Tree?

  12. Dominator Tree

  13. Reducible Graph Test • Graph is reducible iff … all back edges are ones whose head dominates its tail

  14. Why is this not a Reducible Graph?

  15. Why is this not a Reducible Graph? Remember: head must dominate tail of back edge.

  16. Nonreducible Graph Spanning Tree B (head) does not dominate C (tail)

  17. Reducible Graph? Build Spanning Tree Back edges: head must dominate tail

  18. Natural Loops • Now we can find natural loops • Given back edge m → n, natural loop is n (loop header) and nodes that can reach m without passing through n

  19. Find Natural Loops?

  20. Natural Loops • Back Edge Natural Loop • J → G {G,H,J} • G → D {D,E,F,G,H,J} • D → C {C,D,E,F,G,H,J} • H → C {C,D,E,F,G,H,J} • I → A {A,B,C,D,E,F,G,H,I,J}

  21. Strongly-Connected Components • What about irreducible flowgraphs? • Most general loop form = strongly-connected component (SCC): • subgraph S such that every node in S reachable from every other node by path including only edges in S • Maximal SCC: • S is maximal SCC if it is the largest SCC that contains S.

  22. SCC Example Entry Maximal strongly-connected component B1 B2 Strongly-connected component B3

  23. Computing Maximal SCCs • Tarjan’s algorithm: • Computes all maximal SCCs • Linear-time (in number of nodes and edges) • CLR algorithm: • Also linear-time • Simpler: • Two depth-first searches and one “transpose”:reverse all graph edge

  24. Conclusion • Introduced control-flow analysis • Basic blocks • Control-flow graphs • Discussed application of graph algorithms: loops • Spanning trees, depth-first spanning trees • Reducibility • Dominators • Dominator tree • Strongly-connected components

  25. Next Time • Dataflow analysis • Read Marlowe and Ryder paper

More Related