Homework 2 Solution - Programming Analysis and Understanding | CMSC 631, Assignments of Computer Science

Material Type: Assignment; Professor: Foster; Class: PROG ANLYS&UNDERSTANDING; Subject: Computer Science; University: University of Maryland; Term: Spring 2006;

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-v75-2
koofers-user-v75-2 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 631, Spring 2006
Homework 2
Due Tuesday, February 21, in class
1. For the following control flow graph
(a) Draw the dominator tree
(b) List the dominance frontiers of each node
(c) Put the control-flow graph in SSA form (you can eyeball this instead of running the algorithm by
hand)
1. x := 3
2. y := 10
4. x < y
5. x := x + y
7. y := y * 3
3. x < 2 * y
6. y := y + 2 8. z := x * y
2. In class we gave a definition that αand γform a Galois connection if
αand γare monotonic
Sγ(α(S)) for any concrete element S.
α(γ(A)) Afor any abstract element A.
(Actually, in class the last inequality was an equality, which it usually is in practice; in that case, α
and γwould form a Galois insertion.)
Similarly, we say that two (arbitrary) functions αand γform an adjunction if
Sγ(A) iff α(S)Afor all concrete S, abstract A
Show that αand γform a Galois connection if and only if they form an adjunction.
1
pf2

Partial preview of the text

Download Homework 2 Solution - Programming Analysis and Understanding | CMSC 631 and more Assignments Computer Science in PDF only on Docsity!

CMSC 631, Spring 2006

Homework 2

Due Tuesday, February 21, in class

  1. For the following control flow graph

(a) Draw the dominator tree (b) List the dominance frontiers of each node (c) Put the control-flow graph in SSA form (you can eyeball this instead of running the algorithm by hand)

  1. x := 3
  2. y := 10
  3. x < y
  4. x := x + y
  5. y := y * 3
  6. x < 2 * y
  7. y := y + 2 8. z := x * y
  8. In class we gave a definition that α and γ form a Galois connection if
  • α and γ are monotonic
  • S ≤ γ(α(S)) for any concrete element S.
  • α(γ(A)) ≤ A for any abstract element A.

(Actually, in class the last inequality was an equality, which it usually is in practice; in that case, α and γ would form a Galois insertion.) Similarly, we say that two (arbitrary) functions α and γ form an adjunction if

S ≤ γ(A) iff α(S) ≤ A for all concrete S, abstract A

Show that α and γ form a Galois connection if and only if they form an adjunction.

  1. Consider the factorial function:

fun fact n = if (n == 0) then 1 else n*(fact (n-1))

We wish to use abstract interpretation to prove that, given a non-negative integer as input, this function always produces a positive integer as output.

(a) Suppose we use as our abstract domain the rule of signs, so that numbers are represented as one of A = {+, −, 0 , ⊥, >}. We want to compute a function f act′^ : A → A in our abstract domain that soundly models f act. Ultimately, we would like to show that f act′(+) = f act′(0) = +. Since f act is a recursive function, we need to do this by computing a fixpoint. We will compute a series f act 0 , f act 1 , f act 2 ,... of successively more accurate models of f act until we reach a fixpoint. Let f act 0 (x) = ⊥ for all x ∈ A. (Note: We are starting with ⊥ for this problem, and we will use join instead of meet.) Written out in a tabular form, we have

x ⊥ > + − 0 f act 0 (x) ⊥ ⊥ ⊥ ⊥ ⊥

This is our first (rather poor) approximation. To compute the next approximation, f act 1 , for each possible input value of x, we will use abstract interpretation to evaluate f act. When we see the recursive call f act(n − 1), we use our previous approximation f act 0. Formally, we compute a series with f acti+1(x) = AEval(if (n == 0) then 1 else n ∗ (f acti (n − 1))) For example, using this formula to compute f act 1 , we get

x ⊥ > + − 0 f act 1 (x) ⊥ + ⊥ ⊥ +

(Remember that all operations, including the test at the if , are strict in ⊥, e.g., x ∗ ⊥ = ⊥.) Continue computing successive approximations of f act, writing each f acti in tabular form, until you reach a fixpoint f act′. Is it the case that f act′(+) = +? What went wrong? (b) Construct a new abstract domain A′^ for which we can show that f act is positive given non-negative input. Draw a picture showing the lattice structure for A′, and describe (briefly) operations in your new domain (if they are obvious, you can just say that you use the obvious abstract operations). Finally, compute a fixpoint approximation (i.e., give a sequence of tables, as above) for f act in your new abstract domain showing that f act is positive given non-negative input. Note: To get an answer to this problem, AEval() must treat if as precisely as possible, i.e., it must know that the test 0 == 0 is always true, and it must know that n is zero on the true branch of the test n == 0 and non-zero on the false branch.