Control Flow II: Dominators and Loop Detection - Lecture 20, University of Michigan, Exams of Electrical and Electronics Engineering

A lecture note from the university of michigan's eecs 483 course, focusing on control flow ii: dominators and loop detection. Topics such as control flow graphs, dominators, immediate dominators, post dominators, and loop detection. Students are encouraged to calculate the dom and idom sets for each bb, as well as the pdom and ipdom sets. The document also discusses why dominators are important for loop detection and optimization.

Typology: Exams

Pre 2010

Uploaded on 09/17/2009

koofers-user-j10
koofers-user-j10 🇺🇸

5

(1)

10 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Control Flow II:
Dominators, Loop Detection
EECS 483 – Lecture 20
University of Michigan
Wednesday, November 15, 2006
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Control Flow II: Dominators and Loop Detection - Lecture 20, University of Michigan and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

Control Flow II: Dominators, Loop Detection

EECS 483 – Lecture 20 University of Michigan Wednesday, November 15, 2006

  • 1 -

Announcements and Reading

Simon’s office hours on Thurs (11/16) » Moved to 10am-12pm, 4817 CSE » Exam 1 problem 11 was incorrectly graded

y

Follow set for B should contain z

» See Simon to get your points back

Project 3/4 – postponed until Monday » Group formation for Project 3/

Today’s class material: » 10.4, end of 10.9 (dominator algorithm)

  • 3 -

Control Flow Analysis

™ Determining properties of the program branchstructure

» Static properties

Æ

Not executing the code

» Properties that exist regardless of the run-time branch

directions

» Use CFG » Optimize efficiency of control flow structure

™ Determine instruction execution properties

» Global optimization of computation operations » Discuss this later

  • 4 -

Dominator

™ Defn: Dominator

  • Given a CFG(V, E, Entry, Exit), a node x dominates a node y, if every pathfrom the Entry block to y contains x ™ 3 properties of dominators

» Each BB dominates itself » If x dominates y, and y dominates z, then x dominates z » If x dominates z and y dominates z, then either x

dominates y or y dominates x

™ Intuition

» Given some BB, which blocks are guaranteed to have

executed prior to executing the BB

  • 6 -

Dominator Analysis

Compute dom(BBi) = set of BBsthat dominate BBi

Initialization

Dom(entry) = entry

Dom(everything else) = all nodes

Iterative computation

while change, do

y change = false y for each BB (except the entry BB) ‹ tmp(BB) = BB + {intersect of Domof all predecessor BB’s} ‹ if (tmp(BB) != dom(BB)) È dom(BB) = tmp(BB) È change = true

BB
BB
BB
BB
BB
BB
BB

Entry Exit

  • 7 -

Immediate Dominator

™ Defn: Immediate dominator (idom)– Each node n has a uniqueimmediate dominator mthat is the last dominatorof n on any path from theinitial node to n

» Closest node that

dominates

BB
BB
BB
BB
BB
BB
BB

Entry Exit

  • 9 -

Post Dominator

Reverse of dominator

Defn: Post Dominator

  • Given a CFG(V, E, Entry, Exit), a node x post dominates anode y, if every path from y to the Exitcontains x

Intuition » Given some BB, which blocks are guaranteed to have executed after executing the BB

  • 10 -

Post Dominator Examples

BB
BB
BB
BB
BB
BB
BB

Entry Exit

BB2 BB
BB
BB

Entry BB1 BB6^ Exit

  • 12 -

Immediate Post Dominator

Defn: Immediate post dominator

(ipdom) –

Each node n has a uniqueimmediate postdominator m that is thefirst post dominator of non any path from n to theExit

Closest node that postdominates

First breadth-firstsuccessor that postdominates a node

BB
BB
BB
BB
BB
BB
BB

Entry Exit

  • 13 -

Class Problem

BB
BB2 BB
BB3 BB

Entry^ BB6^ BB7^ Exit

Calculate the PDOM set for each BB

  • 15 -

Natural Loops

Cycle suitable for optimization » Discuss opti later

2 properties: » Single entry point called the header

y

Header dominates

all blocks in the loop

» Must be one way to iterate the loop (ie at least 1 path back to the header from within theloop) called a backedge

Backedge detection » Edge, x Æ y where the target (y) dominates the source (x)

  • 16 -

Backedge Example

BB2 BB
BB
BB

Entry BB1 BB6^ Exit

dom(1) = E,1dom(2) = E,1,

dom(4) = E,1,2,3,

dom(3) = E,1,2,

dom(5) = E,1,2,3,

dom(6) = E,1,2,

BE = target dominatessourceE

Æ

1 : No

Æ

2 : No

Æ

3 : No

Æ

6 : No

Æ

4 : No

Æ

5 : No

Æ

3 : Yes

Æ

5 : No

Æ

3 : Yes

Æ

6 : No

Æ

2 : Yes

Æ

X : No

In this example, BE = edge from higher BB to lower BB, not always this easy!

  • 18 -

Loop Detection Example

BB2 BB
BB
BB

Entry BB1 BB6^ Exit

dom(1) = E,1 dom(2) = E,1,

dom(4) = E,1,2,3,

dom(3) = E,1,2,

dom(5) = E,1,2,3,

dom(6) = E,1,2,

Loop detection: 3 steps: •

Identify backedges

Compute LoopBB

Merge loops with the same header

Loop1: defined by 6

Æ

LoopBB = 2,3,4,5,

Loop2: defined by 4

Æ

LoopBB = 3,

Loop3: defined by 5

Æ

LoopBB = 3,4,

Merge loops 2,

LoopBB = 3,4,5 Backedges = 4

Æ

Æ

  • 19 -

Class Problem

BB
BB
BB
BB
BB
BB
BB

Entry Exit

Find the loops What are the header(s)? What are the backedge(s)?