
CMSC 631, Fall 2006
Homework 1
Due Wednesday, Sept. 20, in class
1. Let Sbe a finite set, and let Lbe the lattice of subsets of S, with order ⊆. Show that any function
f(x) constructed from union, intersection, and constant sets is monotonic. Here, I mean that f(x) = e
where ecan be specified by the grammar
e::= x|S0|e∪e|e∩e
where S0is any subset of S. Your proof should be by induction on the structure of e.
2. Suppose that we extend the grammar for efrom problem 1 to include the complement operator !e,
where !T=S−Tfor some set T. Is fstill guaranteed to be monotonic? If it is, justify your answer. If
it’s not, provide a counterexample. In addition, explain why a transfer function defined by Out(stmt)
= Gen(stmt) ∪(In(stmt) - Kill(stmt)), which seems to include negation, is monotonic.
3. Let Abe a lattice, with order ≤. Define A→Ato be the set of all functions from Ato A, and define
f≤0giff f(x)≤g(x) for all x∈A.
•Show that A→Awith order ≤0is also a lattice. That is, show that for all f, g ∈A→A,ftg
and fugalways exist.
•Suppose lattice Ahas height hand that Ais finite with nelements. What is the height of the
lattice (A→A, ≤0)? (When counting height, count “edges” rather than “nodes,” e.g., if Awere
the lattice {a, b}with a < b, then its height would be 1.)
4. A programming language ensures definite initialization when no program in the language is able to
read a variable before it is initialized (written). Your task is to ensure that this property holds by
designing a dataflow analysis on a simplification of the 3-address code language from project 1 (doesn’t
include arrays):
lab stmt ::= stmt
|identifier :stmt
stmt ::= id:=arg1binop arg2;
|id:=arg;
|goto label;
|if arg1relop arg2goto label;
binop ::= +|-|*|/
relop ::= == |!= |<|>|>= |<=
id ::= identifier
label ::= identifier
arg ::= identifier |constant
Write down the following about your analysis:
(a) State precisely what your analysis aims to do. Explain how this will be used to ensure definite
initialization.
(b) Give the direction of your analysis.
(c) Define the lattice, and define the meet operation.
(d) State how you would initialize the dataflow facts at each program point, including the entry or
exit nodes, as appropriate.
(e) Give the transfer functions (e.g., in terms of Gen and Kill functions) for each three-address code
statement.