Basic Code Generation, DAG Representations - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Basic Code Generation, Data Flow Analysis, Variables, DAG Representations, Interior nodes, Optimization, Labeling algorithms are basic concepts discussed of course.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekavia
ekavia 🇮🇳

4.3

(58)

241 documents

1 / 48

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Compiler
Construction
Lecture 45
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
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30

Partial preview of the text

Download Basic Code Generation, DAG Representations - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 45

2

Liveness information allows us to keep values in registers if they will be used later (efficiency)

Basic Code Generation

4

 Why do we need to save live variables at the end?

 We might have to reload them in the next block.

 Global Data-Flow Analysis

Basic Code Generation

5

DAG Representations

A dag (directed acyclic graph)

for a basic block has the

following labels for the nodes:

7

DAG Representations

BB DAG for x = y op z

op x

y z

8

Generating DAGs

For statement i: x = y op z  if y op z node exists, add x to the label for that node. else add node for y op z.  If y or z exist in the dag, point to existing locations else add leaves for y and/or z and have the op node point to them.

10

Example 1

a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t

11

Example 1

a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2 (^) b c

a +

13

Example 1

a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2 (^) b’

t

c

b +

a

14

Example 1

a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2 (^) b’

t

c’

b +

  • c

a

16

Example 1

a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2 (^) b’

t

c’

t

b +

c

a

17

Example 2

t1 = 4 * i t2 = a[t1] t3 = 4 * i t4 = b[t3] t5 = t2 * t t6 = p + t p = t t7 = i + 1 i = t if i <20 goto (1)

a b 4 i’ 1

[ ] (^) [ ] <

p’

t6,p t t2 t t1,t3 (^) t7,i

(1) 20

19

Order Matters

Order 1 t1 = a + b t2 = c + d t3 = e – t t4 = t1 – t

Order 2 t2 = c + d t3 = e – t t1 = a + b t4 = t1 – t

a (^) b e + c (^) d

t

t

t t

20

Order #1 with 2 registers

t1 = a + b t2 = c + d t3 = e – t t4 = t1 – t

MOV a, R ADD b,R MOV c, R ADD D, R MOV R0,t MOV e, R SUB R1,R MOV t1,R SUB R0, R MOV R1,t ; 10 instructions