Top Description Fields Constructors Methods
org.droidparts.dexmaker.dx.ssa

public final Class SsaMethod

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.rop.code.*, org.droidparts.dexmaker.dx.util.IntList, java.util.*

A method in SSA form.

Field Summary

Modifier and TypeField and Description
private boolean
backMode

"back-convert mode".

private ArrayList<SsaBasicBlock>
blocks

basic blocks, indexed by block index

private int
borrowedSpareRegisters

current count of spare registers used

private SsaInsn[]
definitionList

indexed by register: the insn where said register is defined or null if undefined.

private int
entryBlockIndex

Index of first executed block in method

private int
exitBlockIndex

Index of exit block, which exists only in SSA form, or or -1 if there is none

private final boolean
isStatic

true if this method has no this pointer argument

private int
maxLabel

really one greater than the max label

private final int
paramWidth

the total width, in register-units, of the method's parameters

private int
registerCount

total number of registers required

private int
spareRegisterBase

first register number to use for any temporary "spares"

private List<SsaInsn>[]
unmodifiableUseList

A version of useList with each List unmodifiable

private ArrayList<SsaInsn>[]
useList

indexed by register: the list of all insns that use a register

Constructor Summary

AccessConstructor and Description
private
SsaMethod(RopMethod
non-null; the original rop-form method that this instance is based on
ropMethod
,
int
the total width, in register-units, of the method's parameters
paramWidth
,
boolean
true if this method has no this pointer argument
isStatic
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
pack-priv static BitSet

Returns:

BitSet of block indices
bitSetFromLabelList
(BasicBlockList
Rop blocks
blocks
,
IntList
list of rop block labels
labelList
)

Builds a BitSet of block indices from a basic block list and a list of labels taken from Rop form.

public int

Returns:

rop label or {code -1} if bi was -1
blockIndexToRopLabel
(int
block index or -1 for none
bi
)

public int

Returns:

register number to use
borrowSpareRegister
(int
width (1 or 2) of the register
category
)

Borrows a register to use as a temp.

private void
buildUseList()

Builds useList and unmodifiableUseList.

public void
computeReachability()

Computes reachability for all blocks in the method.

private void
public void
deleteInsns(Set<SsaInsn>
non-null; insns to delete
deletedInsns
)

Deletes all insns in the set from this method.

public void
forEachBlockDepthFirst(boolean
true if this should walk backwards from the exit points
reverse
,
SsaBasicBlock.Visitor
non-null; callback interface. parent is set unless this is the root node
v
)

Walks the basic block tree in depth-first order, calling the visitor method once for every block.

public void
forEachBlockDepthFirstDom(SsaBasicBlock.Visitor
non-null; callback interface
v
)

Visits blocks in dom-tree order, starting at the current node.

public void
forEachInsn(SsaInsn.Visitor
non-null; callback interface
visitor
)

Visits all insns in this method.

public void
forEachPhiInsn(PhiInsn.Visitor
non-null; callback.
v
)

Visits each phi insn in this method

public ArrayList<SsaBasicBlock>

Returns:

non-null; basic block list. Do not modify.
getBlocks
()

public int

Returns:

>= 0; number of reachable basic blocks
getCountReachableBlocks
()

Returns the count of reachable blocks in this method: blocks that have predecessors (or are the start block)

public SsaInsn

Returns:

insn (actual instance from code) that defined this reg or null if reg is not defined.
getDefinitionForRegister
(int
register in question
reg
)

Returns the insn that defines the given register

public SsaBasicBlock

Returns:

first execution block
getEntryBlock
()

public int

Returns:

block index of first execution block
getEntryBlockIndex
()

public SsaBasicBlock

Returns:

null-ok; block of exit block or null if there is none
getExitBlock
()

public int

Returns:

block index of exit block or -1 if there is none
getExitBlockIndex
()

private static SsaInsn

Returns:

an appropriately-constructed instance.
getGoto
(SsaBasicBlock
block to which this GOTO will be added (not it's destination!)
block
)

Gets a new GOTO insn.

public int

Returns:

the total width, in register units, of the method's parameters
getParamWidth
()

public int

Returns:

count of registers used in this method
getRegCount
()

public ArrayList<SsaInsn>[]

Returns:

modifiable copy of the use-list, indexed by register
getUseListCopy
()

Returns a modifiable copy of the register use list.

public List<SsaInsn>

Returns:

unmodifiable instruction list
getUseListForRegister
(int
register in question
reg
)

Returns the list of all source uses (not results) for a register.

public static IntList

Returns:

IntList of block indices
indexListFromLabelList
(BasicBlockList
Rop blocks
ropBlocks
,
IntList
list of rop block labels
labelList
)

Builds an IntList of block indices from a basic block list and a list of labels taken from Rop form.

public boolean

Returns:

true if reg is ever associated with a local
isRegALocal
(RegisterSpec
non-null; ssa reg
spec
)

Checks to see if the given SSA reg is ever associated with a local local variable.

public boolean

Returns:

true if this is a static method
isStatic
()

Returns true if this is a static method.

pack-priv void
makeExitBlock()

Creates an exit block and attaches it to the CFG if this method exits.

public SsaBasicBlock

Returns:

new block
makeNewGotoBlock
()

Makes a new basic block for this method, which is empty besides a single GOTO.

public int

Returns:

>=0; new SSA register.
makeNewSsaReg
()

Makes a new SSA register.

public void
mapRegisters(RegisterMapper
maps old registers to new.
mapper
)

Remaps unversioned registers.

public static SsaMethod
newFromRopMethod(RopMethod
rop-form method to convert from
ropMethod
,
int
the total width, in register-units, of the method's parameters
paramWidth
,
boolean
true if this method has no this pointer argument
isStatic
)

pack-priv void
onInsnAdded(SsaInsn
non-null; insn to add
insn
)

Adds an insn to both the use and def lists.

pack-priv void
onInsnRemoved(SsaInsn
non-null; insn to remove
insn
)

Removes an instruction from use and def lists.

public void
onInsnsChanged()

Indicates that the instruction list has changed or the SSA register count has increased, so that internal datastructures that rely on it should be rebuild.

pack-priv void
onSourceChanged(SsaInsn
non-null; insn being changed
insn
,
RegisterSpec
null-ok; The source that was used, if applicable
oldSource
,
RegisterSpec
non-null; the new source being used
newSource
)

Updates the use list for a single change in source register.

pack-priv void
onSourcesChanged(SsaInsn
insn non-null; insn being changed. insn.getSources() must return the new source list.
insn
,
RegisterSpecList
null-ok; list of sources that were previously used
oldSources
)

Updates the use list for a source list change.

private void
removeFromUseList(SsaInsn
non-null; insn in question
insn
,
RegisterSpecList
null-ok; registers whose use lists insn should be removed form
oldSources
)

Removes a given insn from the use lists for the given oldSources (rather than the sources currently returned by insn.getSources()).

public void
returnSpareRegisters()

Returns all borrowed registers.

public void
setBackMode()

Sets "back-convert mode".

pack-priv void
setNewRegCount(int
new register count
newRegCount
)

Sets the new register count after renaming.

pack-priv void
updateOneDefinition(SsaInsn
non-null; insn who's result should be recorded as a definition
insn
,
RegisterSpec
null-ok; a previous result that should be no longer considered a definition by this insn
oldResult
)

Updates a single definition.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backModeback to summary
private boolean backMode

"back-convert mode". Set during back-conversion when registers are about to be mapped into a non-SSA namespace. When true, use and def lists are unavailable.

Todo

Remove this mode, and place the functionality elsewhere

blocksback to summary
private ArrayList<SsaBasicBlock> blocks

basic blocks, indexed by block index

borrowedSpareRegistersback to summary
private int borrowedSpareRegisters

current count of spare registers used

definitionListback to summary
private SsaInsn[] definitionList

indexed by register: the insn where said register is defined or null if undefined. null until (lazily) created.

entryBlockIndexback to summary
private int entryBlockIndex

Index of first executed block in method

exitBlockIndexback to summary
private int exitBlockIndex

Index of exit block, which exists only in SSA form, or or -1 if there is none

isStaticback to summary
private final boolean isStatic

true if this method has no this pointer argument

maxLabelback to summary
private int maxLabel

really one greater than the max label

paramWidthback to summary
private final int paramWidth

the total width, in register-units, of the method's parameters

registerCountback to summary
private int registerCount

total number of registers required

spareRegisterBaseback to summary
private int spareRegisterBase

first register number to use for any temporary "spares"

unmodifiableUseListback to summary
private List<SsaInsn>[] unmodifiableUseList

A version of useList with each List unmodifiable

useListback to summary
private ArrayList<SsaInsn>[] useList

indexed by register: the list of all insns that use a register

Constructor Detail

SsaMethodback to summary
private SsaMethod(RopMethod ropMethod, int paramWidth, boolean isStatic)

Constructs an instance.

Parameters
ropMethod:RopMethod

non-null; the original rop-form method that this instance is based on

paramWidth:int

the total width, in register-units, of the method's parameters

isStatic:boolean

true if this method has no this pointer argument

Method Detail

bitSetFromLabelListback to summary
pack-priv static BitSet bitSetFromLabelList(BasicBlockList blocks, IntList labelList)

Builds a BitSet of block indices from a basic block list and a list of labels taken from Rop form.

Parameters
blocks:BasicBlockList

Rop blocks

labelList:IntList

list of rop block labels

Returns:BitSet

BitSet of block indices

blockIndexToRopLabelback to summary
public int blockIndexToRopLabel(int bi)
Parameters
bi:int

block index or -1 for none

Returns:int

rop label or {code -1} if bi was -1

borrowSpareRegisterback to summary
public int borrowSpareRegister(int category)

Borrows a register to use as a temp. Used in the phi removal process. Call returnSpareRegisters() when done.

Parameters
category:int

width (1 or 2) of the register

Returns:int

register number to use

buildUseListback to summary
private void buildUseList()

Builds useList and unmodifiableUseList.

computeReachabilityback to summary
public void computeReachability()

Computes reachability for all blocks in the method. First clears old values from all blocks, then starts with the entry block and walks down the control flow graph, marking all blocks it finds as reachable.

convertRopToSsaBlocksback to summary
private void convertRopToSsaBlocks(RopMethod rmeth)
deleteInsnsback to summary
public void deleteInsns(Set<SsaInsn> deletedInsns)

Deletes all insns in the set from this method.

Parameters
deletedInsns:Set<SsaInsn>

non-null; insns to delete

forEachBlockDepthFirstback to summary
public void forEachBlockDepthFirst(boolean reverse, SsaBasicBlock.Visitor v)

Walks the basic block tree in depth-first order, calling the visitor method once for every block. This depth-first walk may be run forward from the method entry point or backwards from the method exit points.

Parameters
reverse:boolean

true if this should walk backwards from the exit points

v:SsaBasicBlock.Visitor

non-null; callback interface. parent is set unless this is the root node

forEachBlockDepthFirstDomback to summary
public void forEachBlockDepthFirstDom(SsaBasicBlock.Visitor v)

Visits blocks in dom-tree order, starting at the current node. The parent parameter of the Visitor.visitBlock callback is currently always set to null.

Parameters
v:SsaBasicBlock.Visitor

non-null; callback interface

forEachInsnback to summary
public void forEachInsn(SsaInsn.Visitor visitor)

Visits all insns in this method.

Parameters
visitor:SsaInsn.Visitor

non-null; callback interface

forEachPhiInsnback to summary
public void forEachPhiInsn(PhiInsn.Visitor v)

Visits each phi insn in this method

Parameters
v:PhiInsn.Visitor

non-null; callback.

getBlocksback to summary
public ArrayList<SsaBasicBlock> getBlocks()
Returns:ArrayList<SsaBasicBlock>

non-null; basic block list. Do not modify.

getCountReachableBlocksback to summary
public int getCountReachableBlocks()

Returns the count of reachable blocks in this method: blocks that have predecessors (or are the start block)

Returns:int

>= 0; number of reachable basic blocks

getDefinitionForRegisterback to summary
public SsaInsn getDefinitionForRegister(int reg)

Returns the insn that defines the given register

Parameters
reg:int

register in question

Returns:SsaInsn

insn (actual instance from code) that defined this reg or null if reg is not defined.

getEntryBlockback to summary
public SsaBasicBlock getEntryBlock()
Returns:SsaBasicBlock

first execution block

getEntryBlockIndexback to summary
public int getEntryBlockIndex()
Returns:int

block index of first execution block

getExitBlockback to summary
public SsaBasicBlock getExitBlock()
Returns:SsaBasicBlock

null-ok; block of exit block or null if there is none

getExitBlockIndexback to summary
public int getExitBlockIndex()
Returns:int

block index of exit block or -1 if there is none

getGotoback to summary
private static SsaInsn getGoto(SsaBasicBlock block)

Gets a new GOTO insn.

Parameters
block:SsaBasicBlock

block to which this GOTO will be added (not it's destination!)

Returns:SsaInsn

an appropriately-constructed instance.

getParamWidthback to summary
public int getParamWidth()
Returns:int

the total width, in register units, of the method's parameters

getRegCountback to summary
public int getRegCount()
Returns:int

count of registers used in this method

getUseListCopyback to summary
public ArrayList<SsaInsn>[] getUseListCopy()

Returns a modifiable copy of the register use list.

Returns:ArrayList<SsaInsn>[]

modifiable copy of the use-list, indexed by register

getUseListForRegisterback to summary
public List<SsaInsn> getUseListForRegister(int reg)

Returns the list of all source uses (not results) for a register.

Parameters
reg:int

register in question

Returns:List<SsaInsn>

unmodifiable instruction list

indexListFromLabelListback to summary
public static IntList indexListFromLabelList(BasicBlockList ropBlocks, IntList labelList)

Builds an IntList of block indices from a basic block list and a list of labels taken from Rop form.

Parameters
ropBlocks:BasicBlockList

Rop blocks

labelList:IntList

list of rop block labels

Returns:IntList

IntList of block indices

isRegALocalback to summary
public boolean isRegALocal(RegisterSpec spec)

Checks to see if the given SSA reg is ever associated with a local local variable. Each SSA reg may be associated with at most one local var.

Parameters
spec:RegisterSpec

non-null; ssa reg

Returns:boolean

true if reg is ever associated with a local

isStaticback to summary
public boolean isStatic()

Returns true if this is a static method.

Returns:boolean

true if this is a static method

makeExitBlockback to summary
pack-priv void makeExitBlock()

Creates an exit block and attaches it to the CFG if this method exits. Methods that never exit will not have an exit block. This is called after edge-splitting and phi insertion, since the edges going into the exit block should not be considered in those steps.

makeNewGotoBlockback to summary
public SsaBasicBlock makeNewGotoBlock()

Makes a new basic block for this method, which is empty besides a single GOTO. Successors and predecessors are not yet set.

Returns:SsaBasicBlock

new block

makeNewSsaRegback to summary
public int makeNewSsaReg()

Makes a new SSA register. For use after renaming has completed.

Returns:int

>=0; new SSA register.

mapRegistersback to summary
public void mapRegisters(RegisterMapper mapper)

Remaps unversioned registers.

Parameters
mapper:RegisterMapper

maps old registers to new.

newFromRopMethodback to summary
public static SsaMethod newFromRopMethod(RopMethod ropMethod, int paramWidth, boolean isStatic)
Parameters
ropMethod:RopMethod

rop-form method to convert from

paramWidth:int

the total width, in register-units, of the method's parameters

isStatic:boolean

true if this method has no this pointer argument

onInsnAddedback to summary
pack-priv void onInsnAdded(SsaInsn insn)

Adds an insn to both the use and def lists. For use when adding a new insn to the method.

Parameters
insn:SsaInsn

non-null; insn to add

onInsnRemovedback to summary
pack-priv void onInsnRemoved(SsaInsn insn)

Removes an instruction from use and def lists. For use during instruction removal.

Parameters
insn:SsaInsn

non-null; insn to remove

onInsnsChangedback to summary
public void onInsnsChanged()

Indicates that the instruction list has changed or the SSA register count has increased, so that internal datastructures that rely on it should be rebuild. In general, the various other on* methods should be called in preference when changes occur if they are applicable.

onSourceChangedback to summary
pack-priv void onSourceChanged(SsaInsn insn, RegisterSpec oldSource, RegisterSpec newSource)

Updates the use list for a single change in source register.

Parameters
insn:SsaInsn

non-null; insn being changed

oldSource:RegisterSpec

null-ok; The source that was used, if applicable

newSource:RegisterSpec

non-null; the new source being used

onSourcesChangedback to summary
pack-priv void onSourcesChanged(SsaInsn insn, RegisterSpecList oldSources)

Updates the use list for a source list change.

Parameters
insn:SsaInsn

insn non-null; insn being changed. insn.getSources() must return the new source list.

oldSources:RegisterSpecList

null-ok; list of sources that were previously used

removeFromUseListback to summary
private void removeFromUseList(SsaInsn insn, RegisterSpecList oldSources)

Removes a given insn from the use lists for the given oldSources (rather than the sources currently returned by insn.getSources()).

Parameters
insn:SsaInsn

non-null; insn in question

oldSources:RegisterSpecList

null-ok; registers whose use lists insn should be removed form

returnSpareRegistersback to summary
public void returnSpareRegisters()

Returns all borrowed registers.

setBackModeback to summary
public void setBackMode()

Sets "back-convert mode". Set during back-conversion when registers are about to be mapped into a non-SSA namespace. When true, use and def lists are unavailable.

setNewRegCountback to summary
pack-priv void setNewRegCount(int newRegCount)

Sets the new register count after renaming.

Parameters
newRegCount:int

new register count

updateOneDefinitionback to summary
pack-priv void updateOneDefinition(SsaInsn insn, RegisterSpec oldResult)

Updates a single definition.

Parameters
insn:SsaInsn

non-null; insn who's result should be recorded as a definition

oldResult:RegisterSpec

null-ok; a previous result that should be no longer considered a definition by this insn