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

public Class ConstCollector

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.rop.code.*, org.droidparts.dexmaker.dx.rop.cst.Constant, .CstString, .TypedConstant, org.droidparts.dexmaker.dx.rop.type.StdTypeList, .TypeBearer, java.util.*

Collects constants that are used more than once at the top of the method block. This increases register usage by about 5% but decreases insn size by about 3%.

Field Summary

Modifier and TypeField and Description
private static boolean
COLLECT_ONE_LOCAL

If true, allow one local var to be involved with a collected const.

private static boolean
COLLECT_STRINGS

Also collect string consts, although they can throw exceptions.

private static final int
MAX_COLLECTED_CONSTANTS

Maximum constants to collect per method.

private final SsaMethod
ssaMeth

method we're processing

Constructor Summary

AccessConstructor and Description
private
ConstCollector(SsaMethod
non-null; method to process
ssaMethod
)

Constructs an instance.

Method Summary

Modifier and TypeMethod and Description
private void
fixLocalAssignment(RegisterSpec
non-null; original register
origReg
,
RegisterSpec
non-null; new register that will replace origReg
newReg
)

Inserts mark-locals if necessary when changing a register.

private ArrayList<TypedConstant>

Returns:

non-null; list of constants in most-to-least used order
getConstsSortedByCountUse
()

Gets all of the collectable constant values used in this method, sorted by most used first.

public static void
process(SsaMethod
non-null; method to process
ssaMethod
)

Processes a method.

private void
run()

Applies the optimization.

private void
updateConstUses(HashMap<TypedConstant, RegisterSpec>
non-null; mapping between constant and new reg
newRegs
,
int
>=0; original SSA reg count, not including newly added constant regs
origRegCount
)

Updates all uses of various consts to use the values in the newly assigned registers.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COLLECT_ONE_LOCALback to summary
private static boolean COLLECT_ONE_LOCAL

If true, allow one local var to be involved with a collected const. Turned off because it mostly just inserts more moves.

COLLECT_STRINGSback to summary
private static boolean COLLECT_STRINGS

Also collect string consts, although they can throw exceptions. This is off now because it just doesn't seem to gain a whole lot. TODO if you turn this on, you must change SsaInsn.hasSideEffect() to return false for const-string insns whose exceptions are not caught in the current method.

MAX_COLLECTED_CONSTANTSback to summary
private static final int MAX_COLLECTED_CONSTANTS

Maximum constants to collect per method. Puts cap on reg use

ssaMethback to summary
private final SsaMethod ssaMeth

method we're processing

Constructor Detail

ConstCollectorback to summary
private ConstCollector(SsaMethod ssaMethod)

Constructs an instance.

Parameters
ssaMethod:SsaMethod

non-null; method to process

Method Detail

fixLocalAssignmentback to summary
private void fixLocalAssignment(RegisterSpec origReg, RegisterSpec newReg)

Inserts mark-locals if necessary when changing a register. If the definition of origReg is associated with a local variable, then insert a mark-local for newReg just below it. We expect the definition of origReg to ultimately be removed by the dead code eliminator

Parameters
origReg:RegisterSpec

non-null; original register

newReg:RegisterSpec

non-null; new register that will replace origReg

getConstsSortedByCountUseback to summary
private ArrayList<TypedConstant> getConstsSortedByCountUse()

Gets all of the collectable constant values used in this method, sorted by most used first. Skips non-collectable consts, such as non-string object constants

Returns:ArrayList<TypedConstant>

non-null; list of constants in most-to-least used order

processback to summary
public static void process(SsaMethod ssaMethod)

Processes a method.

Parameters
ssaMethod:SsaMethod

non-null; method to process

runback to summary
private void run()

Applies the optimization.

updateConstUsesback to summary
private void updateConstUses(HashMap<TypedConstant, RegisterSpec> newRegs, int origRegCount)

Updates all uses of various consts to use the values in the newly assigned registers.

Parameters
newRegs:HashMap<TypedConstant, RegisterSpec>

non-null; mapping between constant and new reg

origRegCount:int

>=0; original SSA reg count, not including newly added constant regs