basic blocks
DESCRIPTION
Basic Blocks. Mooly Sagiv Schrierber 317 03-640-7606 Wed 10:00-12:00 html://www.math.tau.ac.il/~msagiv/courses/wcc.html. Already Studied. Source program (string). lexical analysis. Tokens. syntax analysis. Abstract syntax tree. semantic analysis. Abstract syntax tree. Translate. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/1.jpg)
Basic Blocks
Mooly Sagiv
Schrierber 31703-640-7606
Wed 10:00-12:00
html://www.math.tau.ac.il/~msagiv/courses/wcc.html
![Page 2: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/2.jpg)
Already StudiedSource program (string)
lexical analysis
syntax analysis
semantic analysis
Translate
Tokens
Abstract syntax tree
Tree IR
Abstract syntax tree
![Page 3: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/3.jpg)
Mismatches between IR and Machine Languages
• CJUMP jumps into two labels– But typical machine instructions use one target
BEQ Ri, Rj, L
• Optimizing IR programs is difficult due to side effects in expressions– ESEQ nodes– Call nodes
• Call nodes within expressions prevent passing arguments in registers
![Page 4: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/4.jpg)
Mismatches between IR and Machine Languages
• Call nodes within expressions prevent passing arguments in registers
binop
plus call call
Namef1
exp1
Namef2
exp2
![Page 5: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/5.jpg)
Why can’t we be smarter?
• Avoid two-way jumps
• Do not use ESEQ expressions
![Page 6: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/6.jpg)
Three Phase Solution• Rewrite the tree into a list of canonical trees
without SEQ or ESEQ nodes
• Group the list into basic blocks
• Order basic blocks into a set of traces – CJUMP is immediately followed by false label
![Page 7: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/7.jpg)
nfact example
function nfactor (n: int): int=
if n = 0
then 1
else n * nfactor(n-1)
![Page 8: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/8.jpg)
MOVE
TEMP t103
ESEQ
CJUMP
EQ TEMP t128 CONST 0
ESEQ
LABEL l0 ESEQ
MOVE
TEMP t129 CONST 1
l1l0ESEQ
JUMP
NAME l2
ESEQ
LABEL l1 ESEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
![Page 9: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/9.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
SEQ
SEQ
TEMP t129BINOP
TIMES
TEMP t131
CALL
nfactor
BINOP
MINUS TEMP t128 CONST 1
MOVE
TEMP t103
TEMP t129
SEQ
LABEL l2
SEQ
TEMP t130
MOVE
TEMP t130
MOVE
TEMP t128
TEMP t131
SEQ
MOVE
![Page 10: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/10.jpg)
LABEL(l3)
CJUMP(EQ, TEMP t128, CONST 0, l0, l1)
LABEL( l0)
MOVE(TEMP t129, CONST 1)
JUMP(NAME l2)
LABEL( l1)
MOVE(TEMP t131, TEMP t128)
MOVE(TEMP t130, CALL(nfactor, BINOP(MINUS, TEMP t128, CONST 1)))
MOVE(TEMP t129, BINOP(TIMES, TEMP t131, TEMP t30))
JUMP(NEME l2)
LABEL( l2)
MOVE(TEMP t103, TEMP t129)
JUMP(NAME lend)
![Page 11: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/11.jpg)
LABEL(l3)
CJUMP(EQ, TEMP t128, CONST 0, l0, l1)
LABEL( l0)
MOVE(TEMP t129, CONST 1)
JUMP(NAME l2)
LABEL( l1)
MOVE(TEMP t131, TEMP t128)
MOVE(TEMP t130, CALL(nfactor, BINOP(MINUS, TEMP t128, CONST 1)))
MOVE(TEMP t129, BINOP(TIMES, TEMP t131, TEMP t130))
/* JUMP(NAME l2) */
LABEL( l2)
MOVE(TEMP t103, TEMP t129)
JUMP(NAME lend)
![Page 12: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/12.jpg)
Outline• The Cannon Interface
• Phase 1: Removal of ESEQ nodes
• Phase 2: Basic Blocks
• Phase 3: Order traces– CJUMP is followed by a false label
![Page 13: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/13.jpg)
/* canon.h */
typedef struct C_stmListList *C_stmListList;
struct C_block {C_stmListList stmLists; Temp_label label;}
struct C_stmListList_ { T_stmList head; C_stmListList tail;}
T_stmList C_linearize(T_stm stm); /* Eliminate ESEQs */
struct C_block C_basicBlocks(T_stmList stmList);
T_stmList C_traceSchedule(struct C_block b);
/* main.c */
static void doProc(FILE *out, F_frame frame, T_stm body)
{ T_stmList stmList;
AS_instrList iList;
stmList = C_linearize(body); /* Removes ESEQs */
stmList = C_traceSchedule(C_basicBlocks(stmList));
iList = F_codegen(frame, stmList); /* 9 */
}
![Page 14: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/14.jpg)
Canonical Trees (Phase 1)• Rewrite the tree
– No SEQ and ESEQ– The parent of each CALL is either EXP or
MOVE(TEMP t, …)
• Apply “meaning preserving” rewriting rules
• Sometimes generates temporaries
![Page 15: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/15.jpg)
ESEQs1 ESEQ
s2 e
ESEQSEQ
s1
e
s2
![Page 16: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/16.jpg)
BINOP
op e2
s e1
ESEQ
ESEQs BINOP
e2op e1
![Page 17: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/17.jpg)
MEM
s e
ESEQ
ESEQ
s
e
MEM
![Page 18: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/18.jpg)
JUMP
s e
ESEQ
SEQ
s
e
JUMP
![Page 19: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/19.jpg)
CJUMP
s e1
ESEQop e2 l1 l1
![Page 20: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/20.jpg)
BINOP
op ESEQ
s e2
e1
ESEQs BINOP
e2op e1
When s and e1 commutes
![Page 21: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/21.jpg)
Which statements commute?• In general very difficult
• Example
• The compiler decides conservatively
MEM
e1
MOVE
MEM
e2
e3
![Page 22: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/22.jpg)
Which statements commute?static bool commute(T_stm x, T_exp y)
{
if (isNop(x)) return TRUE;
if (y->kind == T_NAME || y->kind == T_CONST) return TRUE;
return FALSE;
}
![Page 23: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/23.jpg)
BINOP
op ESEQ
s e2
e1
ESEQ
MOVE
BINOP
e2op TEMP t
When s and e1 may not commute
sTEMP t e1
ESEQ
![Page 24: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/24.jpg)
CJUMP
s e2
e1op ESEQ l1 l1
When s and e1 may not commute
CJUMPs
TEMP top e2 l1 l1
SEQ
MOVE
TEMP t e1
SEQ
![Page 25: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/25.jpg)
MOVE
TEMP t103
ESEQ
CJUMP
EQ TEMP t128 CONST 0
ESEQ
LABEL l0 ESEQ
MOVE
TEMP t129 CONST 1
l1l0ESEQ
JUMP
NAME l2
ESEQ
LABEL l1 ESEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
![Page 26: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/26.jpg)
SEQ
CJUMP
EQ TEMP t128
CONST 0
ESEQ
LABEL l0 ESEQ
MOVE
TEMP t129 CONST 1
l1l0ESEQ
JUMP
NAME l2
ESEQ
LABEL l1 ESEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
TEMP t103
MOVE
![Page 27: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/27.jpg)
SEQ
CJUMP
EQ TEMP t128
CONST 0
LABEL l0ESEQ
MOVE
TEMP t129 CONST 1
l1l0ESEQ
JUMP
NAME l2
ESEQ
LABEL l1 ESEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
TEMP t103
MOVESEQ
![Page 28: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/28.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0 ESEQ
JUMP
NAME l2
ESEQ
LABEL l1 ESEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
![Page 29: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/29.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
ESEQ
LABEL l1 ESEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
![Page 30: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/30.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
ESEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
![Page 31: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/31.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
SEQ
MOVE
TEMP t129 BINOP
TIMES TEMP t128 CALL
nfactor BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
![Page 32: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/32.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
SEQ
MOVETEMP t129
BINOP
TIMES TEMP t128
CALL
nfactor
BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
ESEQ
TEMP t130MOVE
TEMP t130
![Page 33: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/33.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
SEQ
MOVETEMP t129
BINOP
TIMES
TEMP t131
CALL
nfactor
BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
TEMP t130
MOVE
TEMP t130
ESEQMOVE
TEMP t128
TEMP t131
ESEQ
![Page 34: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/34.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
SEQ
SEQ
TEMP t129
BINOP
TIMES
TEMP t131
CALL
nfactor
BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
TEMP t130
MOVE
TEMP t130
MOVE
TEMP t128
TEMP t131
ESEQ
MOVE
![Page 35: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/35.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
SEQ
SEQ
TEMP t129BINOP
TIMES
TEMP t131
CALL
nfactor
BINOP
MINUS TEMP t128 CONST 1
ESEQ
LABEL l2
TEMP t129
SEQ
TEMP t103
MOVE
TEMP t130
MOVE
TEMP t130
MOVE
TEMP t128
TEMP t131
SEQ
MOVE
![Page 36: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/36.jpg)
SEQ
CJUMP
EQ
TEMP t128
CONST 0
LABEL l0
SEQ
MOVE
TEMP t129CONST 1
l1l0
SEQ
JUMP
NAME l2
SEQ
LABEL l1
SEQ
SEQ
TEMP t129BINOP
TIMES
TEMP t131
CALL
nfactor
BINOP
MINUS TEMP t128 CONST 1
MOVE
TEMP t103
TEMP t129
SEQ
LABEL l2
SEQ
TEMP t130
MOVE
TEMP t130
MOVE
TEMP t128
TEMP t131
SEQ
MOVE
![Page 37: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/37.jpg)
A Theoretical Solution• Apply rewriting rules until convergence
• The result need not be unique
• Efficiency and termination of the compiler
![Page 38: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/38.jpg)
A Practical Solution• Apply rewriting rules in “one” pass
• Two mutually recursive routines– do_stm(s) applies rewritings to s– do_exp(e) applies rewritings to e
• reorder(expRefList) – Returns the side effect statements in expRefList
– Replaces expressions by temporaries
• Code distributed in “cannon.c”
![Page 39: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/39.jpg)
Taming Conditional Brunch• Reorder statements so that CJUMP is
followed by a false label
• Two subphases:– Partition the statement list into basic blocks
(straightline programs starting with a label and ending with a branch)
– Reorder basic blocks (Traces)
![Page 40: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/40.jpg)
Phase 2: Basic Blocks• The compiler does not know which branch
will be taken
• Conservatively analyze the control flow of the program
• A basic block– The first statement is a LABEL– The last statement is JUMP or CJUMP– There are no other LABELs, JUMPs, or
CJUMPs
![Page 41: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/41.jpg)
An Algorithm for Basic BlocksC_basicBlocks()
• Applied for each function body• Scan the statement list from left to right• Whenever a LABEL is found
– a new block begins (and the previous block ends)
• Whenever JUMP or CJUMP are found – the current block ends (and the next block begins)
• When a block ends without JUMP or CJUMP– JUMP to the following LABEL
• When a block does not start with a LABEL– Add a LABEL
• At the end of the function body jump to the beginning of the epilogue
![Page 42: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/42.jpg)
LABEL(l3)
CJUMP(EQ, TEMP t128, CONST 0, l0, l1)
LABEL( l0)
MOVE(TEMP t129, CONST 1)
JUMP(NAME l2)
LABEL( l1)
MOVE(TEMP t131, TEMP t128)
MOVE(TEMP t130, CALL(nfactor, BINOP(MINUS, TEMP t128, CONST 1)))
MOVE(TEMP t129, BINOP(TIMES, TEMP t131, TEMP t130))
LABEL( l2)
MOVE(TEMP t103, TEMP t129)
JUMP(NAME l2)
JUMP(NAME lend)
![Page 43: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/43.jpg)
Traces
• Reorder basic blocks– Every CJUMP is followed by a false label
– Many of the unconditional jumps are followed by the corresponding labels
• can be eliminated
• A trace – a sequence of basic blocks that are executed sequentially
• A program has many overlapping traces• Find a set of traces that exactly covers the program
– every block appears in exactly one trace
• Minimize the number of traces
![Page 44: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/44.jpg)
An Algorithm for Generating Traces C_traceSchedule()''
Put all the blocks of the program into a list Q
while Q is not empty do
Start a new (empty) trace, call it T
Remove the head element b of Q
while b is not marked do
mark b
append b to the end of the current trace T
if there is an unmarked successor c of b
b := c
end of current trace T
![Page 45: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/45.jpg)
LABEL(l3)
CJUMP(EQ, TEMP t128, CONST 0, l0, l1)
LABEL( l0)
MOVE(TEMP t129, CONST 1)
JUMP(NAME l2)
LABEL( l1)
MOVE(TEMP t131, TEMP t128)
MOVE(TEMP t130, CALL(nfactor, BINOP(MINUS, TEMP t128, CONST 1)))
MOVE(TEMP t129, BINOP(TIMES, TEMP t131, TEMP t130))
JUMP(NAME l2)
LABEL( l2)
MOVE(TEMP t103, TEMP t129)
JUMP(NAME lend)
T1
T2
![Page 46: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/46.jpg)
Finishing-Up• CJUMP followed by a false label is left alone• JUMP (NAME l) that is followed by a label l is
removed• CJUMP followed by a true label
– replace true and false labels and negate the condition
• If CJUMP(cond, a, b, lt, lf) is not followed by lt or lf
– Replace by: CJUMP(cond, a, b, lt, l'f)LABEL(l'f)JUMP(NAME lf)
• At the end of the process flat basic blocks (trade simplicity for efficiency of the compiler and of the generated code)
![Page 47: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/47.jpg)
LABEL(l3)
CJUMP(EQ, TEMP t128, CONST 0, l0, l1)
LABEL( l0)
MOVE(TEMP t129, CONST 1)
JUMP(NAME l2)
LABEL( l1)
MOVE(TEMP t131, TEMP t128)
MOVE(TEMP t130, CALL(nfactor, BINOP(MINUS, TEMP t128, CONST 1)))
MOVE(TEMP t129, BINOP(TIMES, TEMP t131, TEMP t130))
JUMP(NAME l2)
LABEL( l2)
MOVE(TEMP t103, TEMP t129)
JUMP(NAME lend)
T1
T2
![Page 48: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/48.jpg)
LABEL(l3)
CJUMP(EQ, TEMP t128, CONST 0, l0, l1)
LABEL( l0)
MOVE(TEMP t129, CONST 1)
JUMP(NAME l2)
LABEL( l1)
MOVE(TEMP t131, TEMP t128)
MOVE(TEMP t130, CALL(nfactor, BINOP(MINUS, TEMP t128, CONST 1)))
MOVE(TEMP t129, BINOP(TIMES, TEMP t131, TEMP t130))
JUMP(NAME l2)
LABEL( l2)
MOVE(TEMP t103, TEMP t129)
JUMP(NAME lend)
![Page 49: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/49.jpg)
LABEL(l3)
CJUMP(EQ, TEMP t128, CONST 0, l0, l1)
LABEL( l0)
MOVE(TEMP t129, CONST 1)
JUMP(NAME l2)
LABEL( l1)
MOVE(TEMP t131, TEMP t128)
MOVE(TEMP t130, CALL(nfactor, BINOP(MINUS, TEMP t128, CONST 1)))
MOVE(TEMP t129, BINOP(TIMES, TEMP t131, TEMP t130))
/* JUMP(NAME l2) */
LABEL( l2)
MOVE(TEMP t103, TEMP t129)
JUMP(NAME lend)
![Page 50: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/50.jpg)
Optimal-Traces• Optimizing compilers locate traces for
frequently executed instructions• Minimize the (dynamic) number of jumps
– Improve instruction cache performance
• Improves register allocation • Optimize loops• Sometimes use
– Static heuristics– Profiling information– Dynamic compilation
![Page 51: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/51.jpg)
prologue statements
JUMP (NAME test)
LABEL (test)
CJ(=, i, N, done, body)
LABEL(body)
loop-body statements
JUMP(NAME(test))
LABEL(done)
epilogue statements
prologue statements
JUMP (NAME test)
LABEL (test)
CJ(<=, i, N, body, done)
LABEL(done)
epilogue statements
LABEL(body)
loop-body statements
JUMP(NAME test)
prologue statements
JUMP (NAME test)
LABEL (body)
loop-body statements
JUMP(NAME TEST)
LABEL(TEST)
CJ(<=, i, N, body, done)
LABEL(done)
epilogue statements
![Page 52: Basic Blocks](https://reader033.vdocuments.site/reader033/viewer/2022050819/56814e46550346895dbbc61b/html5/thumbnails/52.jpg)
Summary
• Tree like IR saves temporary variables
• But ESEQ nodes may require some temporaries
• Rewriting rules is a powerful mechanism
• Estimating “commuting” statements is a challenge
• Traces may effect the performance of the generated code