forge.dataflow
Class DataflowAnalysis<D>

java.lang.Object
  extended by forge.dataflow.DataflowAnalysis<D>
Direct Known Subclasses:
DominatorAnalysis, InverseDominatorAnalysis, ReachabilityAnalysis

public abstract class DataflowAnalysis<D>
extends java.lang.Object

A template for a dataflow analysis.

Subclasses need only indicate the direction of the analysis as an argument to the constructor and implement the initial, merge, and transfer functions, though they must be implemented carefully.

An analysis may be forward or backward. A forward analysis proceeds forward from the entry stmt in the CFG, and a backwards analysis proceeds backwards through the CFG from the exit stmt. When implementing a backwards analysis, the transfer function for a branch node must always return branch data whose thenData and elseData are the exact same reference; this can be ensured by using the BranchData constructor that takes a single data argument.

The transfer functions must not modify the input data.. That is, if the data has changed, a new data instance must be returned. The transfer functions may return null (bottom) if the analysis deems the subsequent stmt to be unreachable. For performance reasons, subclasses are encouraged, but not required, to ensure their transfer functions return the input data reference if the data has not changed. This avoids calls to the merge method, which can be costly.

The data before or after a given stmt in the results may be mapped to null, while is used as a bottom value to indicate that the analysis deems the stmt to be unreachable.

Author:
Greg Dennis (gdennis@mit.edu)

Constructor Summary
protected DataflowAnalysis(boolean backward)
          Constructs a new dataflow analysis in the specified direction.
 
Method Summary
 AnalysisResults<D> analyze(ForgeCFG cfg)
          Performs the analysis and returns a mapping from each reachable node to the data at the program point immediately preceding the node.
abstract  D copy(D data)
          Makes a copy of the specified data.
abstract  D initial()
          Returns the initial data set.
 boolean isBackward()
          Returns true if this is a backwards analysis.
abstract  boolean merge(D from, D into)
          Merges "from" data into the "into" data and return true iff the into data has changed.
 D transfer(AssignStmt stmt, D input)
          Transfer function at an assign stmt.
 BranchData<D> transfer(BranchStmt stmt, D input)
          Transfer function at a branch node.
 D transfer(CallStmt stmt, D input)
          Transfer function at a call stmt.
 D transfer(CreateStmt stmt, D input)
          Transfer function at a create stmt.
 D transfer(ExitStmt stmt, D input)
          Transfer function at a terminal node.
 D transfer(SpecStmt stmt, D input)
          Transfer function at an spec stmt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataflowAnalysis

protected DataflowAnalysis(boolean backward)
Constructs a new dataflow analysis in the specified direction.

Method Detail

isBackward

public final boolean isBackward()
Returns true if this is a backwards analysis.

Returns:
this.backward

analyze

public final AnalysisResults<D> analyze(ForgeCFG cfg)
Performs the analysis and returns a mapping from each reachable node to the data at the program point immediately preceding the node.


initial

public abstract D initial()
Returns the initial data set. If this is a forward analysis, it is the data immediately preceding the CFG's entry node; in a backward analysis it is the exit data immediate following the terminal node.


transfer

public D transfer(AssignStmt stmt,
                  D input)
Transfer function at an assign stmt. This implementation returns the input data.


transfer

public D transfer(CallStmt stmt,
                  D input)
Transfer function at a call stmt. This implementation returns the input data.


transfer

public D transfer(CreateStmt stmt,
                  D input)
Transfer function at a create stmt. This implementation returns the input data.


transfer

public D transfer(SpecStmt stmt,
                  D input)
Transfer function at an spec stmt. This implementation returns the input data.


transfer

public BranchData<D> transfer(BranchStmt stmt,
                              D input)
Transfer function at a branch node. If this is a backward analysis, the then and else data must be the same; they must exhibit reference equality (==) with one another; otherwise, the analyze method may throw an IllegalStateException. This implementation returns new BranchData(input).


transfer

public D transfer(ExitStmt stmt,
                  D input)
Transfer function at a terminal node. This implementation returns the input data.


merge

public abstract boolean merge(D from,
                              D into)
Merges "from" data into the "into" data and return true iff the into data has changed.


copy

public abstract D copy(D data)
Makes a copy of the specified data.