Back to Pause for Breath. On to An Abstract Assembly Language.
Held Monday, April 16, 2001
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
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) = { v in in(y) | 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?
computed 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);
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;
used for those
calls?
begin x := 10; y := 5; proc(y); end.
y is not needed?
x is needed?
Monday, 22 January 2001
Monday, 16 April 2001
Back to Pause for Breath. On to An Abstract Assembly Language.
[Current]
[Discussions]
[Glance]
[Honesty]
[Instructions]
[Links]
[Search]
[Syllabus]
Primary
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Project]
[Quizzes]
[Readings]
[Reference]
Sets
[Blackboard]
[98F]
Links
Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.
This page was generated by Siteweaver on Mon Apr 30 10:52:09 2001.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS362/2001S/outline.31.html.
You may validate
this page's HTML.
The source was last modified Mon Apr 16 10:17:57 2001.