Dominators in a Flowgraph
This presentation is the property of its rightful owner.
Sponsored Links
1 / 119

Dominators in a Flowgraph PowerPoint PPT Presentation


  • 82 Views
  • Uploaded on
  • Presentation posted in: General

Dominators in a Flowgraph. Flowgraph : G = ( V, E, r ) ; each v in V is reachable from r. v dominates w if every path from r to w includes v.

Download Presentation

Dominators in a Flowgraph

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Dominators in a flowgraph

Dominators in a Flowgraph

Flowgraph: G =(V, E, r); each v in V is reachable from r

vdominateswif every path from rtow includes v

Application areas : Program optimization, VLSI testing, theoretical biology, distributed systems, constraint programming, memory profiling, analysis of diffusion networks…


Dominators in a flowgraph

Dominators in a Flowgraph

Flowgraph: G =(V, E, r); each v in V is reachable from r

vdominateswif every path from rtow includes v

Set of dominators:Dom(w)={v|v dominates w}

Trivial dominators: wr,w,rDom(w)

Immediate dominator: idom(w)Dom(w) – w and dominatedby everyv in Dom(w) – w

Goal: Find idom(v)for each vinV


Dominators in a flowgraph

Dominators in a Flowgraph

Flowgraph: G =(V, E, r); each v in V is reachable from r

vdominateswif every path from rtow includes v

dominator tree of

algorithm: [Lengauer and Tarjan ’79]

algorithms:

[Alstrup, Harel, Lauridsen, and Thorup ‘97]

[Buchsbaum, Kaplan, Rogers, and Westbrook ‘04]

[G., and Tarjan ‘04]

[Buchsbaumet al. ‘08]


Dominators in a flowgraph

Application: Loop Optimizations

Loop optimizations typically make a program much more efficient

since a large fraction of the total running time is spent on loops.

Dominators can be used to detect loops.


Dominators in a flowgraph

Application: Loop Optimizations

Loop L

  • There is a node h L(loop header), such that

  • There is a (v,h) for some vL

  • For any w L-hthere is no (v,w) for vL

  • h is reachable from every w  L

  • h reaches every w  L

h

a

b

c

d

e

Thus h dominates all nodes in L.

Loop back-edge: (v,h)  A and h dominates v.


Dominators in a flowgraph

Application: Identifying Functionally Equivalent Faults

x1

Consider a circuit C:

Inputs: x1, … , xn

Output: f(x1, … ,xn)

Suppose there is a fault in wire a.ThenC = Caevaluatesfainstead.

Fault a and fault b are functionally equivalent iff

fa(x1, … ,xn) = fb(x1, … ,xn)

Such pairs of faults are indistinguishable and we want to avoid

spending time to distinguish them (since it is impossible).

x2

x3

b

x4

fb

x5


Dominators in a flowgraph

Application: Identifying Functionally Equivalent Faults

a

x1

Consider a circuit C:

Inputs: x1, … , xn

Output: f(x1, … ,xn)

Suppose there is a fault in wire a.ThenC = Caevaluatesfainstead.

Fault a and fault b are functionally equivalent iff

fa(x1, … ,xn) = fb(x1, … ,xn)

It suffices to evaluate the output of a gate g that dominates a and b. This is can be faster than evaluating f since g may have fewer inputs.

g

x2

x3

b

x4

f

x5


Dominators in a flowgraph

Example

r

Dom(r)={r }

Dom(b)={r, b }

Dom(c)={r, c }

Dom(a)={r, a }

Dom(d)={r, d }

Dom(e)={r, e }

Dom(l)={r, d, l }

Dom(h)={r, h }

c

b

g

a

d

e

f

l

j

h

i

k


Dominators in a flowgraph

Example

Dom(r)={r }

Dom(b)={r, b }

Dom(c)={r, c }

Dom(a)={r, a }

Dom(d)={r, d }

Dom(e)={r, e }

Dom(l)={r, d, l }

Dom(h)={r, h }

Dom(k)={r, k }

Dom(f)={r, c, f }

Dom(g)={r, g }

r

c

b

g

a

d

e

f

l

j

h

i

k


Dominators in a flowgraph

Example

Dom(b)={r, b }

Dom(c)={r, c }

Dom(a)={r, a }

Dom(d)={r, d }

Dom(e)={r, e }

Dom(l)={r,d, l }

Dom(h)={r, h }

Dom(k)={r, k }

Dom(f)={r,c, f }

Dom(g)={r, g }

Dom(j)={r,g, j }

Dom(i)={r, i }

r

c

b

g

a

d

e

f

l

j

h

i

k


Dominators in a flowgraph

Example

idom(b)=r

idom(c)=r

idom(a)=r

idom(d)=r

idom(e)=r

idom(l)=d

idom(h)=r

idom(k)=r

idom(f)=c

idom(g)=r

idom(j)=g

idom(i)=r

r

c

b

g

a

d

e

f

l

j

h

i

k


Dominators in a flowgraph

Example

r

r

g

i

e

a

b

c

d

h

k

c

b

g

a

j

f

l

d

e

f

Dominator Tree D

D=(V,w  r(idom(w),w))

l

j

h

i

k


Dominators in a flowgraph

A Straightforward Algorithm

Purdom-Moore [1972]:

for all vinV– r do

remove vfromG

R(v) unreachable vertices

for alluinR(v) do

Dom(u)Dom(u) { v }

done

done

The running time is O(nm).Also very slow in practice.


Dominators in a flowgraph

Iterative Algorithm

Dominators can be computed by solving iteratively the set of equations [Allen and Cocke, 1972]

Initialization

In the intersection we consider only the nonempty Dom(u).

Each Dom(v)set can be represented by an n-bit vector.

Intersection bit-wise AND.

Requires n2space. Very slow in practice (but better than PM).


Dominators in a flowgraph

Iterative Algorithm

Dominators can be computed by solving iteratively the set of equations [Allen and Cocke, 1972]

Efficient implementation [Cooper, Harvey and Kennedy 2000]:

Maintain tree ; process the edges until a fixed-pointis reached.

Process : compute nearest common ancestor of and in .

If is ancestor of parent of , make new parent of .


Dominators in a flowgraph

Iterative Algorithm

Efficient implementation [Cooper, Harvey and Kennedy 2000]

dfs(r)

T {r}

changed  true

while (changed ) do

changed  false

for all vinV– r in reverse postorderdo

x nca(pred(v))

if x parent(v)then

parent(v)x

changed  true

end

done

done


Dominators in a flowgraph

Iterative Algorithm: Example

Perform a depth-first search on G  postorder numbers

r

r

13

c

6

b

c

12

b

g

e

a

g

4

5

8

11

f

a

d

e

f

3

7

d

10

j

h

l

j

i

9

2

l

h

i

k

1

k


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 1

process 12


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 1

process 11


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 1

process 11


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 1

process 10


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 1

process 7


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 1

process 1


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 2

process 8


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 2

process 8


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 2

process 2


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 2

process 2


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm: Example

iteration = 3

process 4


Dominators in a flowgraph

r

13

c

6

b

12

e

g

4

5

8

a

11

f

l

9

3

7

d

10

j

h

i

2

k

1

Iterative Algorithm: Example

iteration = 3

process 4

DONE!

But we need one more iteration to verify that nothing changes


Dominators in a flowgraph

r

13

6

c

b

12

e

g

5

8

4

a

11

f

3

7

d

10

j

h

i

9

2

l

k

1

Iterative Algorithm

Running Time

Each pairwise intersection takes O(n) time.

#iterations  d + 3. [Kam and Ullman 1976]

d =max#back-edges in any

cycle-free path of G

d = 2


Dominators in a flowgraph

Iterative Algorithm

Running Time

Each pairwise intersection takes O(n) time.

The number of iterations is  d + 3.

d =max#back-edges in any cycle-free path of G

= O(n)

Running time = O(mn2)

This bound is tight, but very pessimistic in practice.


Dominators in a flowgraph

A Fast Dominator Algorithm

Lengauer-Tarjan [1979]:O(m(m,n))time

A simpler version runs inO(m  log 2+ m/n n)time


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Depth-First Search

Perform a depth-first search on G DFS-tree T

r

r

1

c

2

b

c

8

b

g

e

a

g

3

7

9

11

f

a

d

e

f

4

10

d

12

j

h

l

j

i

13

5

l

h

i

k

6

k


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Depth-First Search

Depth-First Search Tree T:

We refer to the vertices by their DFS numbers:

v<w :v was visited by DFS before w

Notation

v*w:vis an ancestor of winT

v+w:vis a proper ancestor of winT

parent(v) : parent of vinT

Property 1

v,wsuch that vw,(v,w)Ev*w


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Semidominators

Semidominator path (SDOM-path):

P= (v0=v,v1,v2, …,vk=w)such that

vi>w, for 1 ik-1

(r, a,d, l ,h, e) is an SDOM-path for e

r

1

c

2

b

8

e

g

3

7

9

11

f

a

4

10

d

12

j

h

i

13

5

l

k

6


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Semidominators

Semidominator path (SDOM-path):

P= (v0=v,v1,v2, …,vk=w)such that

vi>w, for 1 ik-1

Semidominator:

sdom(w)=

min {v|SDOM-pathfromvtow}

r

1

c

2

b

8

e

g

3

7

9

11

f

a

4

10

d

12

j

h

i

13

5

l

k

6


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Semidominators

Semidominator path (SDOM-path):

P= (v0=v,v1,v2, …,vk=w)such that

vi>w, for 1 ik-1

Semidominator:

sdom(w)=

min {v|SDOM-pathfromvtow}

r

1

c

2

b

8

sdom(e)=r

e

g

3

7

9

11

f

a

4

10

d

12

j

h

i

13

5

l

k

6


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Semidominators

  • For any w r,idom(w) * sdom(w)+ w.

idom(w)

sdom(w)

w


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Semidominators

  • For any w r,idom(w) * sdom(w)+ w.

  • sdom(w) = min ( { v | (v, w)  E and v<w } 

  • {sdom(u)|u>wand(v, w)Esuch thatu *v}).

sdom(u)

sdom(u)

nca(w,v) = v

nca(w,v) = w

nca(w,v)

w

u

w

u

v

v


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Semidominators

  • For any w r,idom(w) * sdom(w)+ w.

  • sdom(w) = min ( { v | (v, w)  E and v<w } 

  • {sdom(u)|u>wand(v, w)Esuch thatu *v}).

  • Letwr and let ube any vertex with minsdom(u) that

  • satisfies sdom(w)+u*w. Then idom(w)=idom(u).

sdom(u)

sdom(w)

idom(w) = idom(u)

u

w


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Semidominators

  • For any w r,idom(w) * sdom(w)+ w.

  • sdom(w) = min ( { v | (v, w)  E and v<w } 

  • {sdom(u)|u>wand(v, w)Esuch thatu *v}).

  • Letwr and let ube any vertex with minsdom(u) that

  • satisfies sdom(w)+u*w. Then idom(w)=idom(u).

  • Moreover, if sdom(u)=sdom(w)thenidom(w)=sdom(w).

sdom(u) = sdom(w)

idom(w) = sdom(w)

u

w


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm

  • Overview of the Algorithm

  • Carry out a DFS.

  • Process the vertices in reverse preorder. For vertex

  • w, compute sdom(w).

  • Implicitly define idom(w).

  • Explicitly define idom(w)by a preorder pass.


Dominators in a flowgraph

Evaluating minima on tree paths

If we process vertices in reverse preorderthen the

sdom values we need are known.


Dominators in a flowgraph

Evaluating minima on tree paths

Data Structure: Maintain forest F and supports the operations:

link(v,w): Add the edge (v,w)to F.

eval(v): Let r be the root of the tree that contains v in F.

If v= r then return v. Otherwise return any vertex

with minimum sdom among the vertices uthat

satisfy r+u*v.

Initially every vertex in V is a root in F.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm

dfs(r)

for allwVin reverse preorder do

for allvpred(w)do

ueval(v)

ifsemi(u)<semi(w)thensemi(w)semi(u)

done

add w to the bucket of semi(w)

link(parent(w),w)

for allvin the bucket of parent(w)do

delete vfrom the bucket of parent(w)

ueval(v)

ifsemi(u)<semi(v)thendom(v)u

elsedom(v)parent(w)

done

done

for allwVin reverse preorder do

ifdom(w)semi(w)thendom(w)dom(dom(w))

done


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

eval(12) = 12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

add 13 to bucket(12)

link(13)

13

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

delete 13 from bucket(12)

eval(13) = 13

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

eval(11) = 11

[11]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

eval(8) = 8

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

add 12 to bucket(8)

link(12)

12

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

eval(8)=8

12

[8]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

eval(1)=1

12

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

11

add 11 to bucket(1)

link(11)

12

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

11

delete 12 from bucket(8)

eval(12) = 11

[1]

dom(12)=11

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

11

eval(13) = 11

[1]

dom(12)=11

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

11

10

9

8

add 8 to bucket(1)

link(8)

[1]

[1]

[1]

dom(12)=11

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

10

9

8

delete 11 from bucket(1)

eval(11) = 11

[1]

dom(11)=1

[1]

[1]

dom(12)=11

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

9

8

delete 10 from bucket(1)

eval(10) = 10

[1]

dom(11)=1

[1]

[1]

dom(10)=1

dom(12)=11

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

8

delete 9 from bucket(1)

eval(9) = 9

[1]

dom(9)=1

dom(11)=1

[1]

[1]

dom(10)=1

dom(12)=11

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

delete 8 from bucket(1)

eval(8) = 8

dom(8)=1

[1]

dom(9)=1

dom(11)=1

[1]

[1]

dom(10)=1

dom(12)=11

[1]

[8]

dom(13)=12

[12]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

eval(6) = 6

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

dom(10)=1

dom(12)=11

[1]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

add 5 to bucket(1)

link(5)

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

dom(10)=1

dom(12)=11

[1]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

eval(3) = 3

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

dom(10)=1

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

add 4 to bucket(3)

link(4)

dom(8)=1

[1]

4

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

dom(10)=1

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

delete 4 from bucket(3)

eval(4) = 4

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

eval(2) = 2

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[2]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

eval(5) = 5

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

3

add 3 to bucket(1)

link(3)

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

3

eval(1) = 1

[1]

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

6

5

3

2

add 2 to bucket(1)

link(2)

[1]

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

5

3

2

delete 6 from bucket(1)

eval(6) = 6

[1]

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

[12]

[1]

dom(6)=1

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

3

2

delete 5 from bucket(1)

eval(5) = 5

[1]

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

dom(5)=1

[12]

[1]

dom(6)=1

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

2

delete 3 from bucket(1)

eval(3) = 3

[1]

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(3)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

dom(5)=1

[12]

[1]

dom(6)=1

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

delete 2 from bucket(1)

eval(2) = 2

[1]

dom(2)=1

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(3)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=11

[1]

[3]

[8]

dom(13)=12

dom(5)=1

[12]

[1]

dom(6)=1

[1]


Dominators in a flowgraph

r

1

c

2

b

8

e

g

3

7

9

a

11

f

4

10

d

12

j

h

i

13

5

l

k

6

The Lengauer-Tarjan Algorithm: Example

dom(12)  semi(12)

set dom(12)=dom(11)

[1]

dom(2)=1

dom(8)=1

[1]

dom(7)=2

dom(9)=1

dom(3)=1

dom(11)=1

[2]

[1]

[1]

[1]

dom(10)=1

dom(4)=3

dom(12)=1

[1]

[3]

[8]

dom(13)=12

dom(5)=1

[12]

[1]

dom(6)=1

[1]


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm

Running Time = O(n + m) + Time for n-1 calls to link()

+ Time for m+n-1 calls to eval()


Dominators in a flowgraph

Data Structure for link() and eval()

We want to apply Path Compression:

eval(v3)

l’1=l1

semi(l’2)=min{semi(l1),semi(l2)}

semi(l’3)=min{semi(l1),semi(l2),semi(l3)}


Dominators in a flowgraph

Data Structure for link() and eval()

  • We maintain a virtual forest VF such that:

  • For each T in F there is a corresponding VT in VF with

  • the same vertices as T.

  • Corresponding trees T and VT have the same root with

  • thesame label.

  • If v is any vertex, eval(v,F) = eval(v, VF).

Representation: ancestor(v) =parent of v in VT.


Dominators in a flowgraph

Data Structure for link() and eval()

eval(v): Compress the path r* vand return the label of v.

link(v,w): Make vthe parent of w.

VF satisfies Properties 1-3.

Time for n-1 calls to link() +

Time for m+n-1 calls to eval()=O(m  log 2+m/n n)


Dominators in a flowgraph

Experimental Results (Small Graphs)


Dominators in a flowgraph

Experimental Results (Large Graphs)

Running time in ms. Missing values correspond to execution time >1 h.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Lemma 1: v,wsuch that vw, any path from vto w contains

a common ancestor of v and winT.

Follows from Property 1

Lemma 2: For anywr, idom(w)is an ancestor of w inT.

idom(w) is contained in every path from r to w


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

  • Lemma 3: For anywr, sdom(w)is an ancestor of w inT.

  • (parent(w), w) is an SDOM-path sdom(w)parent(w).

  • SDOM-path P =(v0=sdom(w),v1, …,vk=w);

  • Lemma 1 somevi is a common ancestor

  • of sdom(w)and w.

  • We must have visdom(w)vi=sdom(w).


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Lemma 4: For anywr, idom(w)is an ancestor of sdom(w) inT.

The SDOM-path from sdom(w)to w

avoids the proper ancestors of w that

are proper descendants of sdom(w).


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Lemma 5: Letv,wsatisfy v*w. Then v*idom(w)or

idom(w) * idom(v).

For each x thatsatisfies

idom(v)+x+v

there is a path Px from rto vthat avoids x.

Px v*wis a path from rto wthat

avoids x idom(w)x.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 2: Letwr. Ifsdom(u)sdom(w)for every u that

satisfies sdom(w)+ u*w then idom(w)=sdom(w).

Suppose for contradiction sdom(w)Dom(w)

  pathPfromrtowthat

avoids sdom(w).

x= last vertex Psuch that x< sdom(w)

y = first vertex Psdom(w)*w

Q= part of Pfrom xtoy

Lemma 1  y<u, uQ –{x,y}

 sdom(y)<sdom(w).


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 3: Letwr and let ube any vertex for which

sdom(u)is minimum among the vertices uthat satisfy

sdom(w)+u*w. Then idom(u) = idom(w).

Lemma 4 and Lemma 5 idom(w) *idom(u).

Suppose for contradiction idom(u)idom(w).

pathPfromrtowthat avoids idom(u).


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 3: Letwr and let ube any vertex for which

sdom(u)is minimum among the vertices uthat satisfy

sdom(w)+u*w. Then idom(u) = idom(w).

x= last vertex Psuch that x<idom(u).

y = first vertex Pidom(u)*w.

Q= part of Pfrom xto y.

Lemma 1  y<u, uQ–{x,y}

 sdom(y)<idom(u)sdom(u).

Therefore yvfor any v that satisfies

idom(u)+v*u.

But y cannot be an ancestor of idom(u).


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

From Theorem 2 and Theorem 3 we have sdomidom:

Corollary 1: Letwr and let ube any vertex for which sdom(u)is

minimum among the vertices uthat satisfy sdom(w)+u*w.

Then idom(w)= sdom(w), if sdom(w)=sdom(w) and

idom(w)=idom(u)otherwise.

We still need a method to compute sdom.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 4: For any wr,

sdom(w)=min( {v|(v,w) E andv<w} 

{sdom(u)| u>wand(v,w) E such thatu*v} ).

Let x = min({ v|(v,w)Eandv<w}

{ sdom(u)|u>wand(v,w) Esuch thatu*v}).

We first show sdom(w)xand thensdom(w)x.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 4: For any wr,

sdom(w)=min( {v|(v,w) E andv<w} 

{sdom(u)| u>wand(v,w) E such thatu*v} ).

  • sdom(w)x

  • Assume x=vsuch that (v,w)Eandv<w sdom(w)x.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 4: For any wr,

sdom(w)=min( {v|(v,w) E andv<w} 

{sdom(u)| u>wand(v,w) E such thatu*v} ).

  • sdom(w)x

  • Assume x=sdom(u)such that u>wand (v,w)Efor some

  • descendant vof uinT.

  • P=SDOM-path from x to u

  • Pu*v(v, w) is an SDOM-path from x to w.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 4: For any wr,

sdom(w)=min( {v|(v,w) E andv<w} 

{sdom(u)| u>wand(v,w) E such thatu*v} ).

  • sdom(w) x

  • Assume that (sdom(w),w)  E sdom(w)x.


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Correctness

Theorem 4: For any wr,

sdom(w)=min( {v|(v,w) E andv<w} 

{sdom(u)| u>wand(v,w) E such thatu*v} ).

  • sdom(w)x

  • Assume that P= (sdom(w)=v0,v1, … ,vk=w)is a simple path

  • vi>w, 1 ik-1.

  • j =min{i 1 |vi *vk-1}.

  • Lemma 1  vi>vj , 1 ij-1

  •  x sdom(vj)sdom(w).


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Almost-Linear-Time Version

We get better running time if the trees in Fare balanced

(as in Set-Union).

Fis balanced for constants a> 1, c> 0 if for all i we have:

# vertices in F of height i cn/ai

Theorem 5 [Tarjan 1975]: The total length of an arbitrary

sequence of m path compressions in an n-vertex forest

balanced for a, c is O((m+n)  (m+n, n)), where the

constant depends on a and c.


Dominators in a flowgraph

Linear-Time Algorithms

  • There are linear-time dominators algorithms both for the

  • RAM Model and the Pointer-Machine Model.

  • Based on LT, but much more complicated.

  • First published algorithms that claimed linear-time, in fact didn’t

  • achieve that bound.

  • RAM: Harel [1985]

  • Alstrup, Harel, Lauridsen and Thorup [1999]

  • Pointer-Machine: Buchsbaum, Kaplan, Rogers and Westbrook [1998]

  •  G. and Tarjan [2004],

  •  Buchsbaum, G., Kaplan, Rogers, Tarjan and Westbrook [2008]


Dominators in a flowgraph

GT Linear-Time Algorithm: High-Level View

Partition DFS-treeD into nontrivial microtrees and lines.

Nontrivial microtree: Maximal subtree of Dof size  gthat

contains at least one leaf of D.

Trivial microtree: Single internal vertex of D.

Line: Maximal unary path of

trivial microtrees.

1

lines

2

16

3

17

20

27

30

4

5

6

13

18

19

21

28

29

31

7

14

15

22

8

9

23

24

nontrivial

microtrees

10

25

g=3

11

12

26


Dominators in a flowgraph

GT Linear-Time Algorithm: High-Level View

Partition DFS-treeD into nontrivial microtrees and lines.

Nontrivial microtree: Maximal subtree of Dof size  gthat

contains at least one leaf of D.

Trivial microtree: Single internal vertex of D.

Line: Maximal unary path of

trivial microtrees.

CoreC: Tree D – nontrivial microtrees

C’ : contract each line of C to

a sigle vertex

1

2

16

{1}

3

20

{2,3,6,7,9}

{16,20,21,22}

6

21

C’

7

22

9

C


Dominators in a flowgraph

GT Linear-Time Algorithm: High-Level View

Basic Idea: Compute external dominators in each nontrivial

microtree and semidominators in each line,

by running LT on C’

Precomputeinternal dominatorsin non-identicalnontrivial microtrees.

Remark: LT runs in linear-time on C’

1

lines

2

16

3

17

20

27

30

4

5

6

13

18

19

21

28

29

31

7

14

15

22

8

9

23

24

nontrivial

microtrees

10

25

g=3

11

12

26


Dominators in a flowgraph

The Lengauer-Tarjan Algorithm: Almost-Linear-Time Version

Back to the O(n(m,n))-timeversion of LT…

We give the details of a data structure that achieves

asymptotically faster link() and eval()


Dominators in a flowgraph

A Better Data Structure for link() and eval()

  • VF must satisfy one additional property:

  • For each T in F there is a corresponding VT in VF with

  • the same vertices as T.

  • Corresponding trees T and VT have the same root with

  • thesame label.

  • If v is any vertex, eval(v,F) = eval(v, VF).

  • Each VT consists of subtrees STi with roots ri, 0 i k,

  • such that semi(label(rj))semi(label(rj+1)), 1 j<k.


Dominators in a flowgraph

A Better Data Structure for link() and eval()

  • Each VT consists of subtrees STi with roots ri, 0 i k,

  • such that semi(label(rj))semi(label(rj+1)), 1 j<k.

r0 has not been processed yet

i.e., semi(r0)sdom(r0)

semi(l1)semi(l2)semi(l3)


Dominators in a flowgraph

A Better Data Structure for link() and eval()

  • Each VT consists of subtrees STi with roots ri, 0 i k,

  • such that semi(label(rj))semi(label(rj+1)), 1 j<k.

We need an extra pointer per node:

child(rj) = rj+1, 0 j<k

ancestor(rj)= 0, 0 jk

semi(l1)semi(l2)semi(l3)


Dominators in a flowgraph

A Better Data Structure for link() and eval()

  • Each VT consists of subtrees STi with roots ri, 0 i k,

  • such that semi(label(rj))semi(label(rj+1)), 1 j<k.

  • For any v in STj, eval(v)doesn’t

  • depend on label(ri), i < j.

  • We can use path compression

    inside each STj.

semi(l1)semi(l2)semi(l3)


Dominators in a flowgraph

A Better Data Structure for link() and eval()

  • Each VT consists of subtrees STi with roots ri, 0 i k,

  • such that semi(label(rj))semi(label(rj+1)), 1 j<k.

To get the O((m+n)  (m+n, n))time

bound we want to keep each STj

balanced.

semi(l1)semi(l2)semi(l3)


Dominators in a flowgraph

A Better Data Structure for link() and eval()

  • Each VT consists of subtrees STi with roots ri, 0 i k,

  • such that semi(label(rj))semi(label(rj+1)), 1 j<k.

size(rj)=|STj| +|STj+1|+ … + |STk|

subsize(rj)=|STj| =size(rj)–size(rj+1)

semi(l1)semi(l2)semi(l3)


Dominators in a flowgraph

A Better Data Structure for link() and eval()

First we implement the following auxiliary operation:

update(r): If r is a root in F and l=label(r) then

restoreProperty 4for all subtree roots.

semi(label(rj))semi(label(rj+1))

1 j<k.

semi(label(r’j))semi(label(r’j+1))

0  j < k’.


Dominators in a flowgraph

Implementation of update()

Suppose semi(l0)<semi(l1)

Case (a):subsize(r1)subsize(r2)


Dominators in a flowgraph

Implementation of update()

Suppose semi(l0)<semi(l1)

Case (b):subsize(r1)<subsize(r2)


Dominators in a flowgraph

Implementation of update()

update(r): Let VT be the virtual tree rooted at r=r0,

with subtrees STi and corresponding roots ri,

0 i k.

If semi(label(r))<semi(label(r1)) then combine

ST0 and ST1 to a new subtree ST’0. Repeat this

process for STj, i= 2, … , j, where j=k or

semi(label(r))semi(label(rj)).

Set the label of the root r’0 of the final subtree ST’0

equal to label(r) and set child(r) = r’1.


Dominators in a flowgraph

Implementation of link()

link(v,w): update(w,label(v))

Combine the virtual trees rooted at v and w.

Case (a):size(v)size(w)


Dominators in a flowgraph

Implementation of link()

link(v,w): update(w,label(v))

Combine the virtual trees rooted at v and w.

Case (b):size(v)<size(w)


Dominators in a flowgraph

Implementation of link()

link(v,w): update(w,label(v))

Let VT1 be the virtual tree rooted at v= r0,

with subtree roots ri, 0 ik.

Let VT2 be the virtual tree rooted at w=s0,

with subtree roots si, 0 i  l.

If size(v)size(w) make v parent of s0, s1,…,sl.

Otherwise make v parent of r1,r2, …,rk and

make w the child of v.


Dominators in a flowgraph

Analysis of link()

We will show that the (uncompressed) subtrees built by link()

are balanced.

U : uncompressed forest.

Just before ancestor(y)x xandyare subtree roots.

Then we add (x,y) to U. Let (x,y), (y,z)U.

(x,y) is good ifsubsize(x) 2subsize(y)

(y,z)is mediocre if subsize(x) 2subsize(z)


Dominators in a flowgraph

Analysis of link()

(x,y) is good ifsubsize(x) 2subsize(y)

(y,z)is mediocre if subsize(x) 2subsize(z)

Every edge added by update() is good.

Assume (x,y) and (y,z) are added outside update().

(y,z) size(y) 2size(z)

(x,y) subsize(x)  2subsize(z)

Thus, every edge added by link() is mediocre.


Dominators in a flowgraph

Analysis of link()

For any x,yandzinUsuch that xyz, we have

subsize(x) 2subsize(z).

It follows by induction that any vertex of height h in U has

 2h/2 descendants.

The number of vertices of height h in U is n/2h/2

 2½n/(2½)h  U is balanced for constants .


Dominators in a flowgraph

Lengauer-Tarjan Running Time

By Theorem 5, m calls to eval()take O((m+n)  (m+n, n))time.

The total time for all the link()instructions is proportional to

the number of edges in UO(n+m)time.

The Lengauer-Tarjan algorithm runs in O(m(m,n))time.


  • Login