










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Class: Compiler Design; Subject: Computer & Info Science; University: Syracuse University; Term: Unknown 1989;
Typology: Study notes
1 / 18
This page cannot be seen from the preview
Don't miss anything!
Can be a simple translation of three address instruction to target code
x = y + z
becomes
lw
$t0, y
lw
$t1, z
add
$t2, $t0, $t
sw
$t2, x
procedures have a location (offset) of the code in this area
-^
global variables allocated in the static area also given offsets here
for j from 1 to 10 do
a[i, j] = 0.
for i from 1 to 10 do
a[i, j] = 1.
i = 1
leader
j = 1
leader
t1 = 10 * i
leader
t2 = t1 + j
t3 = 8 * t
t4 = t3 – 88
a[t4] = 0.
j = j + 1
if j <= 10 goto 3.
leader
leader
leader
loop entry is only node withpredecessor outside the loop
-^
every node in the loop has apath to the entry
i = 1
j = 1
t1 = 10 * It2 = t1 + jt3 = 8 * t2t4 = t3 – 88a[t4] = 0.0j = j + 1if j <= 10 goto B3.
i = i + 1if i <= 10 goto B2.
i = 1
t5 = i – 1t6 = 88 * t5a[t6] = 1.0i = i + 1if i <= 10 goto B6.
node for each instruction in the block whose children are the previousstatements giving the last definition of the operands
check if there are nodes with the same operator and the same children
if there is a node with no ancestors and with no live variables, then thatnode can be eliminated
arithmetic identities (e.g. x – 0 = x = x + 0 = 0 + x …)
-^
reduction in strength, replacing expensive operations with cheaper ones(e.g. x
2
= x * x, 2 * x = x + x)
constant folding - evaluate constant expressions at compile time (e.g. 2* 3.14)
register descriptor keeps track of which variable names have acurrent value in that register
-^
address descriptor for each program variable keeps track of wherethe current value of the variable can be found
call GetRegister for each of the operands
lw Ry, y
lw Rz, z
add Rx, Ry, Rz
if y is already in a register, pick it (no load instruction needed)
-^
if y is not in a register, but one is free, pick that register (and load it)
-^
if y is not in a register but there is not register free, consider candidateregisters R
value is in memory already
is not also one of the operands (x will be rewritten anyway)
register with the fewest number of stores
sliding window of instructions (peephole) to examine
example: eliminate jumps over jumps
A register-interference graph is constructed
is live at a point where the other is defined
Try to color the graph with k colors, where k is the # of registers
have the same color
algorithms exist
If the graph cannot be colored for k registers, choose a register to “spill”
known as Sethi-Ullman numbers, or Ershov numbers
label any leaf 1
-^
label of an interior node with one child is the label of its child
-^
label of an interior node with two children is
if an interior node has two children with unequal labels
b + k -
base b, result is in b + m-
op Rb+k-1, Rb+m-1, Rb+k-
For a leaf representing x, with base register b, generate:
lw Rb
x
insert some store instructions to spill register values into memory
for an interior node with a child whose label < r (#registers)
-^
generate code for the big child, using base register 1, result will bein register r
-^
generate instruction sw Rr, tk, where tk is a temporary memorylocation used to evaluate nodes with label k
-^
generate code for the little child. If the label is r or greater, use base= 1. If the label is j < r, use base = r-j, result appears in Rr
-^
generate instruction lw Rr-1, tk
-^
generate node instruction:
op Rr, Rr, Rr-1 (or op Rr, Rr-1, Rr)