[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
Misc:
[2001S]
[2002F]
[SamR]
Back to Miscellaneous. On to Register Allocation.
Held: Monday, 3 May 2004
Summary: Today we consider techniques for determining how long a variable remains useful in a program. Such knowledge can help us generate more efficient code and allocate registers to temporaries. .
Related Pages:
Overview:
variables(or temporaries) are not used at the same time.
swapped out.
used,
needed,
defined, and
livefor variables.
Do we need to remember the value assigned to this variable (temporary) for later statements?
Is it possible, in some path through the program, that the current value assigned to this variable will be used in a later statement?
statement.
in
: the variables needed/live just before the statement;
out
: the variables needed/live after the statement;
use
: the variables used within the statement;
def
: the variables defined by the statement;
succ
: the successors of a statement; and
pred
: the predecessors of a statement.
use(s)
is a subset of in(s)
out(s)
is a superset of in(t)
for each
t
in succ(s)
in(s)
is a superset of out(s)def(s)
.
s0: a := 0 s1: a := b + c s2: b := a + b s3: end
use(s0) = { } use(s1) = { b, c } use(s2) = { a, b } use(s3) = { } def(s0) = { a } def(s1) = { a } def(s2) = { b } def(s3) = { } succ(s0) = { s1 } succ(s1) = { s2 } succ(s2) = { s3 } succ(s3) = { }
in
and out
satisfy
the equations given earlier?
in(s0) = { q,b,c } out(s0) = { q,b,c } in(s1) = { q,b,c } out(s1) = { q,a,b,c } in(s2) = { q,a,c } out(s2) = { q,a,b,c } in(s3) = { q,a,b,c }
in(s0) = { b,c } out(s0) = { b,c } in(s1) = { b,c } out(s1) = { a,b } in(s2) = { a,b } out(s2) = { } in(s3) = { }
in
and out
?
compute used and def for each statement // the prior step may be done during translation foreach statement, s in(s) = used(s) repeat foreach statement s in(s) = in(s) + (out(s)def(s)) foreach predecessor, p, of s out(p) = out(p) + in(s) until no changes are made
for i := 1 to 10 do begin writeln(i); end;
y := 1; while (x <= 10) do begin x := x + 1; y := x; end writeln(y);
y := 1; repeat x := x + 1; y := x; until (x > 10); writeln(y);
used
for those
calls?
begin x := 10; y := 5; proc(y); end.
y
is not needed?
x
is needed?
procedure foo(x: integer); begin x := x + 1; writeln(x); x := x  1; end;
procedure bar(var x: integer); begin x := x + 1; writeln(x); x := x  1; end;
Back to Miscellaneous. On to Register Allocation.
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]

[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
Misc:
[2001S]
[2002F]
[SamR]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Wed May 5 12:11:27 2004.
The source to the document was last modified on Tue Jan 20 23:06:46 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2004S/Outlines/outline.39.html
.
You may wish to validate this document's HTML ; ; Check with Bobby
Samuel A. Rebelsky, rebelsky@grinnell.edu