use of com.android.dx.ssa.SsaBasicBlock in project buck by facebook.
the class SsaToRop method 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.
*/
private void removePhiFunctions() {
ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks();
for (SsaBasicBlock block : blocks) {
// Add moves in all the pred blocks for each phi insn.
block.forEachPhiInsn(new PhiVisitor(blocks));
// Delete the phi insns.
block.removeAllPhiInsns();
}
/*
* After all move insns have been added, sort them so they don't
* destructively interfere.
*/
for (SsaBasicBlock block : blocks) {
block.scheduleMovesFromPhis();
}
}
use of com.android.dx.ssa.SsaBasicBlock in project buck by facebook.
the class SsaDumper method endParsingMember.
/** {@inheritDoc} */
@Override
public void endParsingMember(ByteArray bytes, int offset, String name, String descriptor, Member member) {
if (!(member instanceof Method)) {
return;
}
if (!shouldDumpMethod(name)) {
return;
}
if ((member.getAccessFlags() & (AccessFlags.ACC_ABSTRACT | AccessFlags.ACC_NATIVE)) != 0) {
return;
}
ConcreteMethod meth = new ConcreteMethod((Method) member, classFile, true, true);
TranslationAdvice advice = DexTranslationAdvice.THE_ONE;
RopMethod rmeth = Ropper.convert(meth, advice, classFile.getMethods());
SsaMethod ssaMeth = null;
boolean isStatic = AccessFlags.isStatic(meth.getAccessFlags());
int paramWidth = computeParamWidth(meth, isStatic);
if (args.ssaStep == null) {
ssaMeth = Optimizer.debugNoRegisterAllocation(rmeth, paramWidth, isStatic, true, advice, EnumSet.allOf(Optimizer.OptionalStep.class));
} else if ("edge-split".equals(args.ssaStep)) {
ssaMeth = Optimizer.debugEdgeSplit(rmeth, paramWidth, isStatic, true, advice);
} else if ("phi-placement".equals(args.ssaStep)) {
ssaMeth = Optimizer.debugPhiPlacement(rmeth, paramWidth, isStatic, true, advice);
} else if ("renaming".equals(args.ssaStep)) {
ssaMeth = Optimizer.debugRenaming(rmeth, paramWidth, isStatic, true, advice);
} else if ("dead-code".equals(args.ssaStep)) {
ssaMeth = Optimizer.debugDeadCodeRemover(rmeth, paramWidth, isStatic, true, advice);
}
StringBuffer sb = new StringBuffer(2000);
sb.append("first ");
sb.append(Hex.u2(ssaMeth.blockIndexToRopLabel(ssaMeth.getEntryBlockIndex())));
sb.append('\n');
ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks();
ArrayList<SsaBasicBlock> sortedBlocks = (ArrayList<SsaBasicBlock>) blocks.clone();
Collections.sort(sortedBlocks, SsaBasicBlock.LABEL_COMPARATOR);
for (SsaBasicBlock block : sortedBlocks) {
sb.append("block ").append(Hex.u2(block.getRopLabel())).append('\n');
BitSet preds = block.getPredecessors();
for (int i = preds.nextSetBit(0); i >= 0; i = preds.nextSetBit(i + 1)) {
sb.append(" pred ");
sb.append(Hex.u2(ssaMeth.blockIndexToRopLabel(i)));
sb.append('\n');
}
sb.append(" live in:" + block.getLiveInRegs());
sb.append("\n");
for (SsaInsn insn : block.getInsns()) {
sb.append(" ");
sb.append(insn.toHuman());
sb.append('\n');
}
if (block.getSuccessors().cardinality() == 0) {
sb.append(" returns\n");
} else {
int primary = block.getPrimarySuccessorRopLabel();
IntList succLabelList = block.getRopLabelSuccessorList();
int szSuccLabels = succLabelList.size();
for (int i = 0; i < szSuccLabels; i++) {
sb.append(" next ");
sb.append(Hex.u2(succLabelList.get(i)));
if (szSuccLabels != 1 && primary == succLabelList.get(i)) {
sb.append(" *");
}
sb.append('\n');
}
}
sb.append(" live out:" + block.getLiveOutRegs());
sb.append("\n");
}
suppressDump = false;
setAt(bytes, 0);
parsed(bytes, 0, bytes.size(), sb.toString());
suppressDump = true;
}
use of com.android.dx.ssa.SsaBasicBlock in project J2ME-Loader by nikita36078.
the class LivenessAnalyzer method run.
/**
* From Appel algorithm 19.17.
*/
public void run() {
List<SsaInsn> useList = ssaMeth.getUseListForRegister(regV);
for (SsaInsn insn : useList) {
nextFunction = NextFunction.DONE;
if (insn instanceof PhiInsn) {
// If s is a phi-function with V as it's ith argument.
PhiInsn phi = (PhiInsn) insn;
for (SsaBasicBlock pred : phi.predBlocksForReg(regV, ssaMeth)) {
blockN = pred;
nextFunction = NextFunction.LIVE_OUT_AT_BLOCK;
handleTailRecursion();
}
} else {
blockN = insn.getBlock();
statementIndex = blockN.getInsns().indexOf(insn);
if (statementIndex < 0) {
throw new RuntimeException("insn not found in it's own block");
}
nextFunction = NextFunction.LIVE_IN_AT_STATEMENT;
handleTailRecursion();
}
}
int nextLiveOutBlock;
while ((nextLiveOutBlock = liveOutBlocks.nextSetBit(0)) >= 0) {
blockN = ssaMeth.getBlocks().get(nextLiveOutBlock);
liveOutBlocks.clear(nextLiveOutBlock);
nextFunction = NextFunction.LIVE_OUT_AT_BLOCK;
handleTailRecursion();
}
}
use of com.android.dx.ssa.SsaBasicBlock in project J2ME-Loader by nikita36078.
the class LivenessAnalyzer method coInterferePhis.
/**
* Ensures that all the phi result registers for all the phis in the
* same basic block interfere with each other. This is needed since
* the dead code remover has allowed through "dead-end phis" whose
* results are not used except as local assignments. Without this step,
* a the result of a dead-end phi might be assigned the same register
* as the result of another phi, and the phi removal move scheduler may
* generate moves that over-write the live result.
*
* @param ssaMeth {@code non-null;} method to pricess
* @param interference {@code non-null;} interference graph
*/
private static void coInterferePhis(SsaMethod ssaMeth, InterferenceGraph interference) {
for (SsaBasicBlock b : ssaMeth.getBlocks()) {
List<SsaInsn> phis = b.getPhiInsns();
int szPhis = phis.size();
for (int i = 0; i < szPhis; i++) {
for (int j = 0; j < szPhis; j++) {
if (i == j) {
continue;
}
interference.add(phis.get(i).getResult().getReg(), phis.get(j).getResult().getReg());
}
}
}
}
use of com.android.dx.ssa.SsaBasicBlock 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