use of com.android.dx.rop.code.BasicBlock in project J2ME-Loader by nikita36078.
the class IdenticalBlockCombiner method combineBlocks.
/**
* 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.
*
* @param alphaLabel block that will replace all the beta block
* @param betaLabels label list of blocks to combine
*/
private void combineBlocks(int alphaLabel, IntList betaLabels) {
int szBetas = betaLabels.size();
for (int i = 0; i < szBetas; i++) {
int betaLabel = betaLabels.get(i);
BasicBlock bb = blocks.labelToBlock(betaLabel);
IntList preds = ropMethod.labelToPredecessors(bb.getLabel());
int szPreds = preds.size();
for (int j = 0; j < szPreds; j++) {
BasicBlock predBlock = newBlocks.labelToBlock(preds.get(j));
replaceSucc(predBlock, betaLabel, alphaLabel);
}
}
}
use of com.android.dx.rop.code.BasicBlock in project J2ME-Loader by nikita36078.
the class IdenticalBlockCombiner method replaceSucc.
/**
* Replaces one of a block's successors with a different label. Constructs
* an updated BasicBlock instance and places it in {@code newBlocks}.
*
* @param block block to replace
* @param oldLabel label of successor to replace
* @param newLabel label of new successor
*/
private void replaceSucc(BasicBlock block, int oldLabel, int newLabel) {
IntList newSuccessors = block.getSuccessors().mutableCopy();
int newPrimarySuccessor;
newSuccessors.set(newSuccessors.indexOf(oldLabel), newLabel);
newPrimarySuccessor = block.getPrimarySuccessor();
if (newPrimarySuccessor == oldLabel) {
newPrimarySuccessor = newLabel;
}
newSuccessors.setImmutable();
BasicBlock newBB = new BasicBlock(block.getLabel(), block.getInsns(), newSuccessors, newPrimarySuccessor);
newBlocks.set(newBlocks.indexOfLabel(block.getLabel()), newBB);
}
use of com.android.dx.rop.code.BasicBlock in project J2ME-Loader by nikita36078.
the class SsaToRop method convertBasicBlock.
/**
* Converts a single basic block to rop form.
*
* @param block SSA block to process
* @return {@code non-null;} ROP block
*/
private BasicBlock convertBasicBlock(SsaBasicBlock block) {
IntList successorList = block.getRopLabelSuccessorList();
int primarySuccessorLabel = block.getPrimarySuccessorRopLabel();
// Filter out any reference to the SSA form's exit block.
// Exit block may be null.
SsaBasicBlock exitBlock = ssaMeth.getExitBlock();
int exitRopLabel = (exitBlock == null) ? -1 : exitBlock.getRopLabel();
if (successorList.contains(exitRopLabel)) {
if (successorList.size() > 1) {
throw new RuntimeException("Exit predecessor must have no other successors" + Hex.u2(block.getRopLabel()));
} else {
successorList = IntList.EMPTY;
primarySuccessorLabel = -1;
verifyValidExitPredecessor(block);
}
}
successorList.setImmutable();
BasicBlock result = new BasicBlock(block.getRopLabel(), convertInsns(block.getInsns()), successorList, primarySuccessorLabel);
return result;
}
Aggregations