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

public Class SsaToRop

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.rop.code.*, org.droidparts.dexmaker.dx.ssa.*, org.droidparts.dexmaker.dx.util.Hex, .IntList, java.util.ArrayList, .Arrays, .BitSet, .Comparator

Converts a method in SSA form to ROP form.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SsaToRop.PhiVisitor

Helper for removePhiFunctions: PhiSuccessorUpdater for adding move instructions to predecessors based on phi insns.

Field Summary

Modifier and TypeField and Description
private static final boolean
DEBUG

local debug flag

private final InterferenceGraph
interference

non-null; interference graph

private final boolean
minimizeRegisters

true if the converter should attempt to minimize the rop-form register count

private final SsaMethod
ssaMeth

non-null; method to process

Constructor Summary

AccessConstructor and Description
private
SsaToRop(SsaMethod
non-null; method to process
ssaMethod
,
boolean
true if the converter should attempt to minimize the rop-form register count
minimizeRegisters
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
private RopMethod

Returns:

non-null; rop-form output
convert
()

Performs the conversion.

private BasicBlock

Returns:

non-null; ROP block
convertBasicBlock
(SsaBasicBlock
SSA block to process
block
)

Converts a single basic block to rop form.

private BasicBlockList

Returns:

rop-form basic block list
convertBasicBlocks
()

private InsnList

Returns:

non-null; immutable instruction list
convertInsns
(ArrayList<SsaInsn>
non-null; old instructions
ssaInsns
)

Converts an insn list to rop form.

public static RopMethod

Returns:

non-null; rop-form output
convertToRopMethod
(SsaMethod
non-null; method to process
ssaMeth
,
boolean
true if the converter should attempt to minimize the rop-form register count
minimizeRegisters
)

Converts a method in SSA form to ROP form.

public int[]

Returns:

a list of registers ordered by most-frequently-used to least-frequently-used. Each register is listed once and only once.
getRegistersByFrequency
()

Note

This method is not presently used.

private void
moveParametersToHighRegisters()

Moves the parameter registers, which allocateRegisters() places at the bottom of the frame, up to the top of the frame to match Dalvik calling convention.

private void
removeEmptyGotos()

Removes all blocks containing only GOTOs from the control flow.

private void
removePhiFunctions()

See Appel 19.6.

private void
verifyValidExitPredecessor(SsaBasicBlock
non-null; block to validate
b
)

Validates that a basic block is a valid end predecessor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEBUGback to summary
private static final boolean DEBUG

local debug flag

interferenceback to summary
private final InterferenceGraph interference

non-null; interference graph

minimizeRegistersback to summary
private final boolean minimizeRegisters

true if the converter should attempt to minimize the rop-form register count

ssaMethback to summary
private final SsaMethod ssaMeth

non-null; method to process

Constructor Detail

SsaToRopback to summary
private SsaToRop(SsaMethod ssaMethod, boolean minimizeRegisters)

Constructs an instance.

Parameters
ssaMethod:SsaMethod

non-null; method to process

minimizeRegisters:boolean

true if the converter should attempt to minimize the rop-form register count

Method Detail

convertback to summary
private RopMethod convert()

Performs the conversion.

Returns:RopMethod

non-null; rop-form output

convertBasicBlockback to summary
private BasicBlock convertBasicBlock(SsaBasicBlock block)

Converts a single basic block to rop form.

Parameters
block:SsaBasicBlock

SSA block to process

Returns:BasicBlock

non-null; ROP block

convertBasicBlocksback to summary
private BasicBlockList convertBasicBlocks()
Returns:BasicBlockList

rop-form basic block list

convertInsnsback to summary
private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns)

Converts an insn list to rop form.

Parameters
ssaInsns:ArrayList<SsaInsn>

non-null; old instructions

Returns:InsnList

non-null; immutable instruction list

convertToRopMethodback to summary
public static RopMethod convertToRopMethod(SsaMethod ssaMeth, boolean minimizeRegisters)

Converts a method in SSA form to ROP form.

Parameters
ssaMeth:SsaMethod

non-null; method to process

minimizeRegisters:boolean

true if the converter should attempt to minimize the rop-form register count

Returns:RopMethod

non-null; rop-form output

getRegistersByFrequencyback to summary
public int[] getRegistersByFrequency()

Note

This method is not presently used.

Returns:int[]

a list of registers ordered by most-frequently-used to least-frequently-used. Each register is listed once and only once.

moveParametersToHighRegistersback to summary
private void moveParametersToHighRegisters()

Moves the parameter registers, which allocateRegisters() places at the bottom of the frame, up to the top of the frame to match Dalvik calling convention.

removeEmptyGotosback to summary
private void removeEmptyGotos()

Removes all blocks containing only GOTOs from the control flow. Although much of this work will be done later when converting from rop to dex, not all simplification cases can be handled there. Furthermore, any no-op block between the exit block and blocks containing the real return or throw statements must be removed.

removePhiFunctionsback to summary
private void removePhiFunctions()

See Appel 19.6. To remove the phi instructions in an edge-split SSA representation we know we can always insert a move in a predecessor block.

verifyValidExitPredecessorback to summary
private void verifyValidExitPredecessor(SsaBasicBlock b)

Validates that a basic block is a valid end predecessor. It must end in a RETURN or a THROW. Throws a runtime exception on error.

Parameters
b:SsaBasicBlock

non-null; block to validate

Exceptions
RuntimeException:
on error
org.droidparts.dexmaker.dx.ssa.back back to summary

private Class SsaToRop.PhiVisitor

extends Object
implements Visitor
Class Inheritance
All Implemented Interfaces
org.droidparts.dexmaker.dx.ssa.PhiInsn.Visitor

Helper for removePhiFunctions: PhiSuccessorUpdater for adding move instructions to predecessors based on phi insns.

Field Summary

Modifier and TypeField and Description
private final ArrayList<SsaBasicBlock>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blocksback to summary
private final ArrayList<SsaBasicBlock> blocks

Constructor Detail

PhiVisitorback to summary
public PhiVisitor(ArrayList<SsaBasicBlock> blocks)

Method Detail

visitPhiInsnback to summary
public void visitPhiInsn(PhiInsn insn)

Implements org.droidparts.dexmaker.dx.ssa.PhiInsn.Visitor.visitPhiInsn.