Examples of Basic Blocks - PowerPoint PPT Presentation

About This Presentation
Title:

Examples of Basic Blocks

Description:

Live name: A name is a basic block is said to be live at a given point if its ... (1) First determine a set of leaders, the 1st statement of basic blocks: ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 7
Provided by: Arc127
Category:
Tags: basic | blocks | examples

less

Transcript and Presenter's Notes

Title: Examples of Basic Blocks


1
Examples of Basic Blocks
  • Following sequence of three-address statements
    forms a basic block
  • t1 a a
  • t2 a b
  • t3 2 t2
  • t4 t1 t3
  • t5 b b
  • t6 t4 t5
  • It computes aa 2ab bb
  • Given 3-AS x yz
  • -it defines X
  • -it uses (reference) y and z
  • Live name A name is a basic block is said to be
    live at a given point if its value is used after
    that point in the program, perhaps in another
    basic block.

t7

t5
t4


t1
t3


b
b
t2

2
a
a
a
b
a b
t7
t6
2
Examples of 3 address code translation
  • C-code
  • void quicksort(m,n)
  • int m,n
  • int i,j
  • int v,x
  • if (nltm) return
  • / fragment begins /
  • im-1 jn van
  • while(1)
  • do ii1 while(ailtv)
  • do jj-1 while(ajgtv)
  • if (igtj) break
  • xaiaiananx
  • xaiaiananx
  • / fragment ends /
  • quicksort( m ,j) quicksort(l1,n)
  • 3 Address Code.
  • i m-1 j n v an
  • (1) i m-l jn t1 4n v at1
  • while(1)
  • do i i 1 while(ailtv)
  • (5) i i1 t2 4i t3 at2
  • (8) if t3ltv goto(5)
  • do j j-1 while (aj gt v)
  • jj1 t44j t5at4
  • (12) if t5 gtv goto (9)
  • (13) if( i gtj) goto (23)
  • x ai ai an anx
  • (14) t6 4i xat6
  • (16) t7 4i xat6
  • (18) t9 at8 at7t9
  • (20) t10 4j at10 x
  • (22) goto(5)
  • (23) ...

3
Example of Flow graphs
im-1 jn t14n v at1
B1
Ii1 t24i t3at2 if( t3ltv) goto B2
B2
jj-1 t4 4 j t5 at4 if( t5 gtv ) goto B3
B3
B4
if(igtj) goto B6
t11 4 i X at11 t12 4 i t13 4n t14
at13 at12 t14 t15 4 n at15 x
B6
t64i x at6 t7 4 i t8 4 j t9
at8 at7 t9 t10 4 j at10x goto B2
B5
4
Partition into Basic Blocks algorithm
  • Input A sequence of 3 address statements
  • Output A sequence of basic blocks with each 3A
    Statement in exactly
  • one block.
  • Method
  • (1) First determine a set of leaders, the 1st
    statement of basic blocks
  • a) The first statement is a leader
  • b) Any statement that is a target of a
    conditional or
  • unconditional goto is a
    leader
  • c) Any statement that immediately follows a
    goto, or conditional
  • goto statement is a leader.
  • (2) For each leader its basic block consists
    of
  • a) The leader
  • b) All statements upto but not including the
    next leader or the
  • end of the program.

5
Example of Partition into Basic Blocks
  • (1) prod 0
  • (2) i 1
  • (3) t1 4 i
  • (4) t2 at1
  • (5) t3 4 i
  • (6) t4 bt3
  • (7) t5 t2 t4
  • (8) t6 prod t5
  • (9) prod t6
  • (10) t7 i1
  • (11) i t7
  • (12) if( i lt20) goto (3)

6
Example of Partition into Basic Blocks
A leader by rule 1.a A block by rule 2 A leader
by rule 1.b A block by rule 2 A leader by
rule 1.c
(1) prod 0 (2) i 1 (3) t1 4
i (4) t2 at1 (5) t3 4 i (6)
t4 bt3 (7) t5 t2 t4 (8) t6
prod t5 (9) prod t6 (10) t7 i1 (11)
i t7 (12) if( i lt20) goto (3)
B1
B2
Write a Comment
User Comments (0)
About PowerShow.com