Worklist Algorithm - Advanced Compiler - Lecture Slides , Slides of Computer Science

These are the Lecture Slides of Advanced Compiler which includes Partial Transfer Functions, Input Information, Output Information, Data-Based Context Sensitivity, Bottom-Up Example, Infinite Domains, Interprocedural Analysis etc. Key important points are: Worklist Algorithm, Remove Node, Issues with Worklist Algorithm, Algorithm Terminate, Original Nodes, Order of Nodes, Topological Order, Reverse Depth First Order, Structure of Domain

Typology: Slides

2012/2013

Uploaded on 03/19/2013

dharmaa
dharmaa 🇮🇳

4.4

(19)

149 documents

1 / 39

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Worklist algorithm
Initialize all di to the empty set
Store all nodes onto a worklist
while worklist is not empty:
remove node n from worklist
apply flow function for node n
update the appropriate di, and add nodes whose
inputs have changed back onto worklist
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27

Partial preview of the text

Download Worklist Algorithm - Advanced Compiler - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Worklist algorithm

  • Initialize all d (^) i to the empty set
  • Store all nodes onto a worklist
  • while worklist is not empty:
    • remove node n from worklist
    • apply flow function for node n
    • update the appropriate di, and add nodes whose inputs have changed back onto worklist

Worklist algorithm

let m: map from edge to computed value at edge let worklist: work list of nodes

for each edge e in CFG do m(e) := ;

for each node n do worklist.add(n)

while (worklist.empty.not) do let n := worklist.remove_any; let info_in := m(n.incoming_edges); let info_out := F(n, info_in); for i := 0 .. info_out.length-1 do if (m(n.outgoing_edges[i])info_out[i]) m(n.outgoing_edges[i]) := info_out[i]; worklist.add(n.outgoing_edges[i].dst);

Two issues with worklist algorithm

  • Ordering
    • In what order should the original nodes be added to the worklist?
    • What order should nodes be removed from the worklist?
  • Does this algorithm terminate?

Order of nodes

  • Topological order assuming back-edges have

been removed

  • Reverse depth first order
  • Use an ordered worklist

Termination

  • Why is termination important?
  • Can we stop the algorithm in the middle and

just say we’re done...

  • No: we need to run it to completion,

otherwise the results are not safe...

Termination

  • Assuming we’re doing reaching defs, let’s try

to guarantee that the worklist loop

terminates, regardless of what the flow

function F does while (worklist.empty.not) do

let n := worklist.remove_any; let info_in := m(n.incoming_edges); let info_out := F(n, info_in); for i := 0 .. info_out.length-1 do if (m(n.outgoing_edges[i])info_out[i]) m(n.outgoing_edges[i]) := info_out[i]; worklist.add(n.outgoing_edges[i].dst);

Structure of the domain

  • We’re using the structure of the domain

outside of the flow functions

  • In general, it’s useful to have a framework that

formalizes this structure

  • We will use lattices

Background material

Relations

  • A relation over a set S is a set R μ S £ S
    • We write a R b for (a,b) 2 R
  • A relation R is:
    • reflexive iff 8 a 2 S. a R a
    • transitive iff 8 a 2 S, b 2 S, c 2 S. a R b Æb R c ) a R c
    • symmetric iff 8 a, b 2 S. a R b ) b R a
    • anti-symmetric iff 8 a, b, 2 S. a R b ) : (b R a) 8 a, b, 2 S. a R b Æb R a ) a = b

Partial orders

  • An equivalence class is a relation that is:
  • A partial order is a relation that is:

Lub and glb

  • Given a poset (S, · ), and two elements a 2 S

and b 2 S, then the:

  • least upper bound (lub) is an element c such that a · c, b · c, and 8 d 2 S. (a · d Æb · d) ) c · d
  • greatest lower bound (glb) is an element c such that c · a, c · b, and 8 d 2 S. (d · a Æd · b) ) d · c

Lub and glb

  • Given a poset (S, · ), and two elements a 2 S

and b 2 S, then the:

  • least upper bound (lub) is an element c such that a · c, b · c, and 8 d 2 S. (a · d Æb · d) ) c · d
  • greatest lower bound (glb) is an element c such that c · a, c · b, and 8 d 2 S. (d · a Æd · b) ) d · c
  • lub and glb don’t always exists:

Lattices

  • A lattice is a tuple (S, v ,? , > , t , u) such that:
    • (S, v ) is a poset
    • 8 a 2 S.? v a
    • 8 a 2 S. a v >
    • Every two elements from S have a lub and a glb
    • t is the least upper bound operator, called a join
    • u is the greatest lower bound operator, called a meet

Examples of lattices

  • Powerset lattice