ic.dfa
Class DataFlowAnalysis<T>

java.lang.Object
  extended by ic.dfa.DataFlowAnalysis<T>
Direct Known Subclasses:
ReachableAnalysis, ReachableAnalysisWithVisitor

public abstract class DataFlowAnalysis<T>
extends Object

Abstract Dataflow analysis engine. This is a general class for solving dataflow instances. It is parameterized by the type T, which is the type of value contained in the lattice. The solve method is responsible for computing the solution for the CFG passed into the constructor. After calling solve, the in and out methods can be used to access the dataflow facts for each basic block.

To use the framework, you extend this class with a new class --- LiveVariableAnalysis, for example --- which defines the six abstract methods describing the lattice, transfer functions, meet operator, boundary value, and direction of the analysis.

This implementation assumes the the enter and exit blocks for the CFG do not contain instructions that are part of the code. It will not apply transfer functions to those blocks. You can insert a simple "NoOp" TAC Instruction into those blocks.

Note that for forward analysis, in[enter] is typically undefined, but I set it to Top for simplicity. Similarly, for backward analysis, out[exit] is set to Top.


Field Summary
protected  ControlFlowGraph cfg
          The graph to analyze
protected  HashMap<BasicBlock,T> in
          Map for the in values
protected  HashMap<BasicBlock,T> out
          Map for the out values
 
Constructor Summary
DataFlowAnalysis(ControlFlowGraph cfg)
          Create a new dataflow instance that will compute information about the given flow graph.
 
Method Summary
abstract  T boundary()
          Initial value for out[enter] or in[exit], depending on direction.
abstract  boolean equals(T t1, T t2)
          Return true if t1 and t2 are equivalent.
 T in(BasicBlock b)
          Return in[b].
abstract  boolean isForward()
          Return true iff the analysis is a forward analysis.
abstract  T meet(T t1, T t2)
          Return the meet of t1 and t2 in the lattice.
 T out(BasicBlock b)
          Return out[b].
 void solve()
          Solve a dataflow instance with the iterative algorithm.
protected  void solveBackward()
          Solve a backward analysis.
protected  void solveForward()
          Solve a forward analysis and set up in and out.
abstract  T top()
          Top value in the lattice of T elements.
 String toString()
          Print out the in/out values for each basic block.
abstract  T transfer(TInstr instr, T t)
          Return the result of applying the transfer function for instr to t.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cfg

protected ControlFlowGraph cfg
The graph to analyze


in

protected final HashMap<BasicBlock,T> in
Map for the in values


out

protected final HashMap<BasicBlock,T> out
Map for the out values

Constructor Detail

DataFlowAnalysis

public DataFlowAnalysis(ControlFlowGraph cfg)
Create a new dataflow instance that will compute information about the given flow graph.

Method Detail

in

public T in(BasicBlock b)
Return in[b].


out

public T out(BasicBlock b)
Return out[b].


solve

public void solve()
Solve a dataflow instance with the iterative algorithm.


solveForward

protected void solveForward()
Solve a forward analysis and set up in and out.


solveBackward

protected void solveBackward()
Solve a backward analysis. This is the same as above, except we do everything backwards...


toString

public String toString()
Print out the in/out values for each basic block.

Overrides:
toString in class Object

isForward

public abstract boolean isForward()
Return true iff the analysis is a forward analysis.


boundary

public abstract T boundary()
Initial value for out[enter] or in[exit], depending on direction.


top

public abstract T top()
Top value in the lattice of T elements.


meet

public abstract T meet(T t1,
                       T t2)
Return the meet of t1 and t2 in the lattice.


equals

public abstract boolean equals(T t1,
                               T t2)
Return true if t1 and t2 are equivalent.


transfer

public abstract T transfer(TInstr instr,
                           T t)
Return the result of applying the transfer function for instr to t.