EncodedMethod toEncodedMethod(DexOptions dexOptions) { RopMethod ropMethod = new RopMethod(code.toBasicBlocks(), 0); LocalVariableInfo locals = null; DalvCode dalvCode = RopTranslator.translate( ropMethod, PositionList.NONE, locals, code.paramSize(), dexOptions); return new EncodedMethod(method.constant, flags, dalvCode, StdTypeList.EMPTY); } }
/** * Gets the exit predecessors for this instance. * * @return {@code non-null;} the exit predecessors */ public IntList getExitPredecessors() { if (exitPredecessors == null) { calcPredecessors(); } return exitPredecessors; }
IntList preds = ropMethod.labelToPredecessors(b.getLabel()); newBlocks.setImmutable(); return new RopMethod(newBlocks, ropMethod.getFirstLabel());
private void convertRopToSsaBlocks(RopMethod rmeth) { BasicBlockList ropBlocks = rmeth.getBlocks(); int sz = ropBlocks.size(); blocks = new ArrayList<SsaBasicBlock>(sz + 2); for (int i = 0; i < sz; i++) { SsaBasicBlock sbb = SsaBasicBlock.newFromRop(rmeth, i, this); blocks.add(sbb); } // Add an no-op entry block. int origEntryBlockIndex = rmeth.getBlocks() .indexOfLabel(rmeth.getFirstLabel()); SsaBasicBlock entryBlock = blocks.get(origEntryBlockIndex).insertNewPredecessor(); entryBlockIndex = entryBlock.getIndex(); exitBlockIndex = -1; // This gets made later. }
BasicBlockList ropBlocks = rmeth.getBlocks(); BasicBlock bb = ropBlocks.get(basicBlockIndex); SsaBasicBlock result = rmeth.labelToPredecessors(bb.getLabel()));
/** * Constructs instance. Call {@code process()} to run. * * @param rm {@code non-null;} instance to process */ public IdenticalBlockCombiner(RopMethod rm) { ropMethod = rm; blocks = ropMethod.getBlocks(); newBlocks = blocks.getMutableCopy(); }
/** * Does the extraction. * * @return {@code non-null;} the extracted information */ private LocalVariableInfo doit() { for (int label = method.getFirstLabel(); label >= 0; label = Bits.findFirst(workSet, 0)) { Bits.clear(workSet, label); processBlock(label); } resultInfo.setImmutable(); return resultInfo; }
/** * 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); } } }
IntList preds = ropMethod.labelToPredecessors(b.getLabel()); newBlocks.setImmutable(); return new RopMethod(newBlocks, ropMethod.getFirstLabel());
private void convertRopToSsaBlocks(RopMethod rmeth) { BasicBlockList ropBlocks = rmeth.getBlocks(); int sz = ropBlocks.size(); blocks = new ArrayList<SsaBasicBlock>(sz + 2); for (int i = 0; i < sz; i++) { SsaBasicBlock sbb = SsaBasicBlock.newFromRop(rmeth, i, this); blocks.add(sbb); } // Add an no-op entry block. int origEntryBlockIndex = rmeth.getBlocks() .indexOfLabel(rmeth.getFirstLabel()); SsaBasicBlock entryBlock = blocks.get(origEntryBlockIndex).insertNewPredecessor(); entryBlockIndex = entryBlock.getIndex(); exitBlockIndex = -1; // This gets made later. }
BasicBlockList ropBlocks = rmeth.getBlocks(); BasicBlock bb = ropBlocks.get(basicBlockIndex); SsaBasicBlock result = rmeth.labelToPredecessors(bb.getLabel()));
/** * Constructs instance. Call {@code process()} to run. * * @param rm {@code non-null;} instance to process */ public IdenticalBlockCombiner(RopMethod rm) { ropMethod = rm; blocks = ropMethod.getBlocks(); newBlocks = blocks.getMutableCopy(); }
/** * Does the extraction. * * @return {@code non-null;} the extracted information */ private LocalVariableInfo doit() { for (int label = method.getFirstLabel(); label >= 0; label = Bits.findFirst(workSet, 0)) { Bits.clear(workSet, label); processBlock(label); } resultInfo.setImmutable(); return resultInfo; }
/** * 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); } } }
IntList preds = ropMethod.labelToPredecessors(b.getLabel()); newBlocks.setImmutable(); return new RopMethod(newBlocks, ropMethod.getFirstLabel());
private void convertRopToSsaBlocks(RopMethod rmeth) { BasicBlockList ropBlocks = rmeth.getBlocks(); int sz = ropBlocks.size(); blocks = new ArrayList<SsaBasicBlock>(sz + 2); for (int i = 0; i < sz; i++) { SsaBasicBlock sbb = SsaBasicBlock.newFromRop(rmeth, i, this); blocks.add(sbb); } // Add an no-op entry block. int origEntryBlockIndex = rmeth.getBlocks() .indexOfLabel(rmeth.getFirstLabel()); SsaBasicBlock entryBlock = blocks.get(origEntryBlockIndex).insertNewPredecessor(); entryBlockIndex = entryBlock.getIndex(); exitBlockIndex = -1; // This gets made later. }
/** * Returns an instance that is identical to this one, except that * the registers in each instruction are offset by the given * amount. * * @param delta the amount to offset register numbers by * @return {@code non-null;} an appropriately-constructed instance */ public RopMethod withRegisterOffset(int delta) { RopMethod result = new RopMethod(blocks.withRegisterOffset(delta), firstLabel); if (exitPredecessors != null) { /* * The predecessors have been calculated. It's safe to * inject these into the new instance, since the * transformation being applied doesn't affect the * predecessors. */ result.exitPredecessors = exitPredecessors; result.predecessors = predecessors; } return result; }
BasicBlockList ropBlocks = rmeth.getBlocks(); BasicBlock bb = ropBlocks.get(basicBlockIndex); SsaBasicBlock result = rmeth.labelToPredecessors(bb.getLabel()));
/** * Constructs instance. Call {@code process()} to run. * * @param rm {@code non-null;} instance to process */ public IdenticalBlockCombiner(RopMethod rm) { ropMethod = rm; blocks = ropMethod.getBlocks(); newBlocks = blocks.getMutableCopy(); }
/** * Gets the exit predecessors for this instance. * * @return {@code non-null;} the exit predecessors */ public IntList getExitPredecessors() { if (exitPredecessors == null) { calcPredecessors(); } return exitPredecessors; }