Package kilim.analysis
Class Usage
java.lang.Object
kilim.analysis.Usage
Each BasicBlock owns one instance of Usage. This class maintains, in essence, three vectors of
booleans, indexed by the local variable number. Since it is very rare for a method to have
more than 31 local variables, the vectors are represented by int bitmaps. For more than this, the
basic block creates an instance of BigUsage that is functionally identical (TODO)
Note that we don't need to track usage of operand stack. All elements of the operand stack are
always live, and always need to be stored and restored (during stack switching). This is not true
of local vars; a var may have a valid value which may not be used downstream, so we track which
vars must be taken seriously.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BitSetborn.bit(i) == 1 (from LSB) if the ith var has been defined prior either as a method parameter or by a write only vars that have been born can be live (used to protect against vars that are def'd in a block and used in the catch, eg the exception)private BitSetdef.bit(i) == 1 (from LSB) if the ith var is written into before it has been read.private BitSetbit(i) == 1 (counting from LSB) if the ith local var is live downstreamprivate intThe number of local vars in the owning BB's frameprivate BitSetuse.bit(i) == 1 (from LSB) if the ith var is read before it has been written. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidCalled to coalesce a successor's usage into the current BB.voidborn(int var) (package private) Usagecopy()(package private) booleanevalBornIn(Usage pred, BitSet combo) evolve the born value a single iteration by mixing in either pred or combobooleanevalLiveIn(ArrayList<Usage> succUsage, ArrayList<Handler> handUsage) This is the standard liveness calculation (Dragon Book, section 10.6).(package private) BitSetgetCombo()get def OR born(package private) voidset born - used for the first BB only, others are calculatedbooleanisLiveIn(int var) return true if var is live at the entrance to this BB.(package private) voidmerge def into bornprivate voidprintBits(StringBuffer sb, BitSet b) private voidprintBitsFull(StringBuffer sb, BitSet b) private Stringvoidread(int var) voidsetBornIn(int var) This is purely for testing purposes.voidsetLiveIn(int var) This is purely for testing purposes.toString()toStringBits(String sep) voidwrite(int var)
-
Field Details
-
nLocals
private int nLocalsThe number of local vars in the owning BB's frame -
in
bit(i) == 1 (counting from LSB) if the ith local var is live downstream -
born
born.bit(i) == 1 (from LSB) if the ith var has been defined prior either as a method parameter or by a write only vars that have been born can be live (used to protect against vars that are def'd in a block and used in the catch, eg the exception) -
use
use.bit(i) == 1 (from LSB) if the ith var is read before it has been written. The bit vector as a whole represents the set of vars that the BB needs from its predecessors. -
def
def.bit(i) == 1 (from LSB) if the ith var is written into before it has been read. It represents all the vars that this BB is capable of supplying downstream on its own, hence those vars are not required to be supplied by its predecessors (even if they do supply them, they will be overwritten anyway).
-
-
Constructor Details
-
Usage
public Usage(int numLocals)
-
-
Method Details
-
read
public void read(int var) -
write
public void write(int var) -
born
public void born(int var) -
isLiveIn
public boolean isLiveIn(int var) return true if var is live at the entrance to this BB. -
evalLiveIn
This is the standard liveness calculation (Dragon Book, section 10.6). At each BB (and its corresponding usage), we evaluate "in" using use and def. in = use U (out \ def) where out = U succ.in, for all successors this algorithm has been modified to treat catch blocks as occurring anywhere ie, that vars defined in a try may never be set however, this only applies to vars that have been defined at least once (ie, born) -
getCombo
BitSet getCombo()get def OR born -
mergeBorn
void mergeBorn()merge def into born -
initBorn
set born - used for the first BB only, others are calculated -
evalBornIn
evolve the born value a single iteration by mixing in either pred or combo- Parameters:
pred- if combo is null, use pred.borncombo- if non-null, the value to mix in- Returns:
- true if the evolution resulted in a change in the born value
-
absorb
Called to coalesce a successor's usage into the current BB. Important: This should be called before live variable analysis begins, because we don't bother merging this.in or this.born. -
toString
-
toStringBits
-
printBits
-
printBitsFull
-
printBitsFull
-
setLiveIn
public void setLiveIn(int var) This is purely for testing purposes.- Parameters:
var- local var index
-
setBornIn
public void setBornIn(int var) This is purely for testing purposes.- Parameters:
var- local var index
-
copy
Usage copy()
-