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

public Class IdenticalBlockCombiner

extends Object
Class Inheritance
Imports
org.droidparts.dexmaker.dx.rop.code.BasicBlock, .BasicBlockList, .RegOps, .RopMethod, org.droidparts.dexmaker.dx.util.IntList, java.util.BitSet

Searches for basic blocks that all have the same successor and insns but different predecessors. These blocks are then combined into a single block and the now-unused blocks are deleted. These identical blocks frequently are created when catch blocks are edge-split.

Field Summary

Modifier and TypeField and Description
private final BasicBlockList
private final BasicBlockList
private final RopMethod

Constructor Summary

AccessConstructor and Description
public
IdenticalBlockCombiner(RopMethod
non-null; instance to process
rm
)

Constructs instance.

Method Summary

Modifier and TypeMethod and Description
private void
combineBlocks(int
block that will replace all the beta block
alphaLabel
,
IntList
label list of blocks to combine
betaLabels
)

Combines blocks proven identical into one alpha block, re-writing all of the successor links that point to the beta blocks to point to the alpha block instead.

private static boolean

Returns:

true iff the two blocks' instructions are the same
compareInsns
(BasicBlock
non-null; a block to compare
a
,
BasicBlock
non-null; another block to compare
b
)

Helper method to compare the contents of two blocks.

public RopMethod

Returns:

non-null; new method that has been processed
process
()

Runs algorithm.

private void
replaceSucc(BasicBlock
block to replace
block
,
int
label of successor to replace
oldLabel
,
int
label of new successor
newLabel
)

Replaces one of a block's successors with a different label.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blocksback to summary
private final BasicBlockList blocks
newBlocksback to summary
private final BasicBlockList newBlocks
ropMethodback to summary
private final RopMethod ropMethod

Constructor Detail

IdenticalBlockCombinerback to summary
public IdenticalBlockCombiner(RopMethod rm)

Constructs instance. Call process() to run.

Parameters
rm:RopMethod

non-null; instance to process

Method Detail

combineBlocksback to summary
private void combineBlocks(int alphaLabel, IntList betaLabels)

Combines blocks proven identical into one alpha block, re-writing all of the successor links that point to the beta blocks to point to the alpha block instead.

Parameters
alphaLabel:int

block that will replace all the beta block

betaLabels:IntList

label list of blocks to combine

compareInsnsback to summary
private static boolean compareInsns(BasicBlock a, BasicBlock b)

Helper method to compare the contents of two blocks.

Parameters
a:BasicBlock

non-null; a block to compare

b:BasicBlock

non-null; another block to compare

Returns:boolean

true iff the two blocks' instructions are the same

processback to summary
public RopMethod process()

Runs algorithm.

Todo

This is n^2, and could be made linear-ish with a hash. In particular, hash the contents of each block and only compare blocks with the same hash.

Returns:RopMethod

non-null; new method that has been processed

replaceSuccback to summary
private void replaceSucc(BasicBlock block, int oldLabel, int newLabel)

Replaces one of a block's successors with a different label. Constructs an updated BasicBlock instance and places it in newBlocks.

Parameters
block:BasicBlock

block to replace

oldLabel:int

label of successor to replace

newLabel:int

label of new successor