16
LOOPS IN FLOW GRAPHS BP150511 R. RAMYA

Loops in flow

Embed Size (px)

Citation preview

Page 1: Loops in flow

LOOPS IN FLOWGRAPHS

BP150511R. RAMYA

Page 2: Loops in flow

LOOPS IN FLOW GRAPHS

We shall use the notion of a node “Dominating”

another to define “Natural Loop” and the

important special class of “Reducible” of flow

graphs.

An algorithm for finding dominators and

checking reducibility of flow graphs.

Page 3: Loops in flow

i. Dominators

ii. Natural loops

iii. Inner loops

iv. Pre-Headers

v. Reducible flow graphs

Page 4: Loops in flow

DOMINATORS

d dom n – Node d of a CFG dominates node n if

every path from the initial node of the CFG to n

goes through d– The loop entry dominates all

nodes in the loop

The immediate dominator m of a node n is the

last dominator on the path from the initial node

to n – If d ≠ n and d dom n then d dom m

Page 5: Loops in flow
Page 6: Loops in flow

Build a dominator tree as follows:

– Root is CFG entry node n0

– m is child of node n iff n=Idom (m)

Page 7: Loops in flow

NATURAL LOOPS

A back edge is is an edge a → b whose head b

dominates its tail a Given a back edge n → d

1. The natural loop consists of d plus the nodes that can

reach n without going through d

2. The loop header is node d

• Unless two loops have the same header, they are disjoint

or one is nested within the other – A nested loop is an

inner loop if it contains no other loops

Page 8: Loops in flow
Page 9: Loops in flow

NATURAL INNER LOOPS EXAMPLE

Page 10: Loops in flow

NATURAL OUTER LOOPS EXAMPLE

Page 11: Loops in flow

PRE-HEADERS

To facilitate loop transformations, a

compiler often adds a pre-header to a loop

• Code motion, strength reduction, and other

loop transformations populate the pre-header

Page 12: Loops in flow
Page 13: Loops in flow

REDUCIBLE FLOW GRAPHS

Reducible graph = disjoint partition in forward

and back edges such that the forward edges form

an acyclic (sub)graph.

Page 14: Loops in flow
Page 15: Loops in flow

VIDEO video1

Page 16: Loops in flow

THANK YOU