Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Sets:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaneous:
[2001S]
[98F]
[SamR]
[Glimmer Labs]
Back to Translating Procedure Calls. On to Register Allocation.
Held Monday, November 18, 2002
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.
Notes
Overview
variables(or termporaries) 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(x)
is a subset of in(x)
out(x)
is a superset of in(y)
for each
y
that can follow x
.
in(x)
is a superset of out(x)-def(x)
.
in(x) = use(x) union (out(x)-def(x)) out(x) = Union(in(y) s.t. y in succ(x))
s0: a := 0 s1: a := b + c s2: b := a s3: end
use(s0) = { } use(s1) = { b, c } use(s2) = { a } 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 } in(s2) = { a } 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;
Thursday, 29 August 2002 [Samuel A. Rebelsky]
Monday, 18 November 2002 [Samuel A. Rebelsky]
Back to Translating Procedure Calls. On to Register Allocation.
Primary:
[Skip To Body]
[Front Door]
[Current]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Sets:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Readings]
[Reference]
ECA:
[About]
[Grades]
[Quizzes]
[Submit Work]
[Change Password]
[Reset Password]
Miscellaneous:
[2001S]
[98F]
[SamR]
[Glimmer Labs]
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 Fri Dec 6 10:38:33 2002.
The source to the document was last modified on Mon Nov 18 10:38:24 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2002F/Outlines/outline.32.html
.
You may wish to
validate this document's HTML
;
;
Check with Bobby