BasicBlock toBasicBlock() { InsnList result = new InsnList(instructions.size()); for (int i = 0; i < instructions.size(); i++) { result.set(i, instructions.get(i)); } result.setImmutable(); int primarySuccessorIndex = -1; IntList successors = new IntList(); for (Label catchLabel : catchLabels) { successors.add(catchLabel.id); } if (primarySuccessor != null) { primarySuccessorIndex = primarySuccessor.id; successors.add(primarySuccessorIndex); } if (alternateSuccessor != null) { successors.add(alternateSuccessor.id); } successors.setImmutable(); return new BasicBlock(id, result, successors, primarySuccessorIndex); } }
/** * Helper method to compare the contents of two blocks. * * @param a {@code non-null;} a block to compare * @param b {@code non-null;} another block to compare * @return {@code true} iff the two blocks' instructions are the same */ private static boolean compareInsns(BasicBlock a, BasicBlock b) { return a.getInsns().contentEquals(b.getInsns()); }
/** * Gets the instance for the start of the given block. * * @param block {@code non-null;} the block in question * @return {@code non-null;} the appropriate instance */ public CodeAddress getStart(BasicBlock block) { return starts[block.getLabel()]; }
/** * 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); } }
block.getInsns().forEach(translationVisitor); int succ = block.getPrimarySuccessor(); Insn lastInsn = block.getLastInsn(); (block.getSecondarySuccessor() == nextLabel)) {
RegisterSpecSet primaryState = resultInfo.mutableCopyOfStarts(label); BasicBlock block = blocks.labelToBlock(label); InsnList insns = block.getInsns(); int insnSz = insns.size(); boolean canThrowDuringLastInsn = block.hasExceptionHandlers() && (insns.getLast().getResult() != null); int freezeSecondaryStateAt = insnSz - 1; IntList successors = block.getSuccessors(); int succSz = successors.size(); int primarySuccessor = block.getPrimarySuccessor();
BasicBlock b = blocks.get(bindex); if (toDelete.get(b.getLabel())) { IntList preds = ropMethod.labelToPredecessors(b.getLabel()); || iBlock.getSuccessors().size() > 1 || iBlock.getFirstInsn().getOpcode().getOpcode() == RegOps.MOVE_RESULT) { continue; BasicBlock jBlock = blocks.labelToBlock(jLabel); if (jBlock.getSuccessors().size() == 1 && compareInsns(iBlock, jBlock)) { if (toDelete.get(newBlocks.get(i).getLabel())) { newBlocks.set(i, null);
Type one = catchTypes[i]; if (one != null) { Insn proto = labelToBlock(i).getFirstInsn(); SourcePosition pos = proto.getPosition(); InsnList il = new InsnList(2); il.setImmutable(); BasicBlock bb = new BasicBlock(getExceptionSetupLabel(i), il, IntList.makeImmutable(i),
/** * Looks forward to the current block's primary successor, returning * the RegisterSpec of the result of the move-result-pseudo at the * top of that block or null if none. * * @return {@code null-ok;} result of move-result-pseudo at the beginning of * primary successor */ private RegisterSpec getNextMoveResultPseudo() { int label = block.getPrimarySuccessor(); if (label < 0) { return null; } Insn insn = method.getBlocks().labelToBlock(label).getInsns().get(0); if (insn.getOpcode().getOpcode() != RegOps.MOVE_RESULT_PSEUDO) { return null; } else { return insn.getResult(); } }
/** {@inheritDoc} */ public HashSet<Type> getCatchTypes() { HashSet<Type> result = new HashSet<Type>(20); BasicBlockList blocks = method.getBlocks(); int size = blocks.size(); for (int i = 0; i < size; i++) { BasicBlock block = blocks.get(i); TypeList catches = block.getLastInsn().getCatches(); int catchSize = catches.size(); for (int j = 0; j < catchSize; j++) { result.add(catches.getType(j)); } } return result; }
BasicBlock block = blocks.labelToBlock(order[i]); if (!block.canThrow()) {
/** * Checks to see if the basic block is a subroutine caller block. * * @param bb {@code non-null;} the basic block in question * @return true if this block calls a subroutine */ private boolean isSubroutineCaller(BasicBlock bb) { IntList successors = bb.getSuccessors(); if (successors.size() < 2) return false; int subLabel = successors.get(1); return (subLabel < subroutines.length) && (subroutines[subLabel] != null); }
/** * 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); } }
block.getInsns().forEach(translationVisitor); int succ = block.getPrimarySuccessor(); Insn lastInsn = block.getLastInsn(); (block.getSecondarySuccessor() == nextLabel)) {
RegisterSpecSet primaryState = resultInfo.mutableCopyOfStarts(label); BasicBlock block = blocks.labelToBlock(label); InsnList insns = block.getInsns(); int insnSz = insns.size(); boolean canThrowDuringLastInsn = block.hasExceptionHandlers() && (insns.getLast().getResult() != null); int freezeSecondaryStateAt = insnSz - 1; IntList successors = block.getSuccessors(); int succSz = successors.size(); int primarySuccessor = block.getPrimarySuccessor();
BasicBlock b = blocks.get(bindex); if (toDelete.get(b.getLabel())) { IntList preds = ropMethod.labelToPredecessors(b.getLabel()); || iBlock.getSuccessors().size() > 1 || iBlock.getFirstInsn().getOpcode().getOpcode() == RegOps.MOVE_RESULT) { continue; BasicBlock jBlock = blocks.labelToBlock(jLabel); if (jBlock.getSuccessors().size() == 1 && compareInsns(iBlock, jBlock)) { if (toDelete.get(newBlocks.get(i).getLabel())) { newBlocks.set(i, null);
Type one = catchTypes[i]; if (one != null) { Insn proto = labelToBlock(i).getFirstInsn(); SourcePosition pos = proto.getPosition(); InsnList il = new InsnList(2); il.setImmutable(); BasicBlock bb = new BasicBlock(getExceptionSetupLabel(i), il, IntList.makeImmutable(i),
/** * Looks forward to the current block's primary successor, returning * the RegisterSpec of the result of the move-result-pseudo at the * top of that block or null if none. * * @return {@code null-ok;} result of move-result-pseudo at the beginning of * primary successor */ private RegisterSpec getNextMoveResultPseudo() { int label = block.getPrimarySuccessor(); if (label < 0) { return null; } Insn insn = method.getBlocks().labelToBlock(label).getInsns().get(0); if (insn.getOpcode().getOpcode() != RegOps.MOVE_RESULT_PSEUDO) { return null; } else { return insn.getResult(); } }
/** {@inheritDoc} */ public HashSet<Type> getCatchTypes() { HashSet<Type> result = new HashSet<Type>(20); BasicBlockList blocks = method.getBlocks(); int size = blocks.size(); for (int i = 0; i < size; i++) { BasicBlock block = blocks.get(i); TypeList catches = block.getLastInsn().getCatches(); int catchSize = catches.size(); for (int j = 0; j < catchSize; j++) { result.add(catches.getType(j)); } } return result; }
BasicBlock block = blocks.labelToBlock(order[i]); if (!block.canThrow()) {