/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Merges the specified frame into this subroutine's successors, * setting {@code workSet} as appropriate. To be called with * the frame of a subroutine ret block. * * @param frame {@code non-null;} frame from ret block to merge * @param workSet {@code non-null;} workset to update */ void mergeToSuccessors(Frame frame, int[] workSet) { for (int label = callerBlocks.nextSetBit(0); label >= 0; label = callerBlocks.nextSetBit(label+1)) { BasicBlock subCaller = labelToBlock(label); int succLabel = subCaller.getSuccessors().get(0); Frame subFrame = frame.subFrameForLabel(startBlock, label); if (subFrame != null) { mergeAndWorkAsNecessary(succLabel, -1, null, subFrame, workSet); } else { Bits.set(workSet, label); } } } }
/** * Merges the specified frame into this subroutine's successors, * setting {@code workSet} as appropriate. To be called with * the frame of a subroutine ret block. * * @param frame {@code non-null;} frame from ret block to merge * @param workSet {@code non-null;} workset to update */ void mergeToSuccessors(Frame frame, int[] workSet) { for (int label = callerBlocks.nextSetBit(0); label >= 0; label = callerBlocks.nextSetBit(label+1)) { BasicBlock subCaller = labelToBlock(label); int succLabel = subCaller.getSuccessors().get(0); Frame subFrame = frame.subFrameForLabel(startBlock, label); if (subFrame != null) { mergeAndWorkAsNecessary(succLabel, -1, null, subFrame, workSet); } else { Bits.set(workSet, label); } } } }
/** * Merges the specified frame into this subroutine's successors, * setting {@code workSet} as appropriate. To be called with * the frame of a subroutine ret block. * * @param frame {@code non-null;} frame from ret block to merge * @param workSet {@code non-null;} workset to update */ void mergeToSuccessors(Frame frame, int[] workSet) { for (int label = callerBlocks.nextSetBit(0); label >= 0; label = callerBlocks.nextSetBit(label+1)) { BasicBlock subCaller = labelToBlock(label); int succLabel = subCaller.getSuccessors().get(0); Frame subFrame = frame.subFrameForLabel(startBlock, label); if (subFrame != null) { mergeAndWorkAsNecessary(succLabel, -1, null, subFrame, workSet); } else { Bits.set(workSet, label); } } } }
/** * Generates a list of subroutine successors. Note: successor blocks * could be listed more than once. This is ok, because this successor * list (and the block it's associated with) will be copied and inlined * before we leave the ropper. Redundent successors will result in * redundent (no-op) merges. * * @return all currently known successors * (return destinations) for that subroutine */ IntList getSuccessors() { IntList successors = new IntList(callerBlocks.size()); /* * For each subroutine caller, get it's target. If the * target is us, add the ret target (subroutine successor) * to our list */ for (int label = callerBlocks.nextSetBit(0); label >= 0; label = callerBlocks.nextSetBit(label+1)) { BasicBlock subCaller = labelToBlock(label); successors.add(subCaller.getSuccessors().get(0)); } successors.setImmutable(); return successors; }
/** * Generates a list of subroutine successors. Note: successor blocks * could be listed more than once. This is ok, because this successor * list (and the block it's associated with) will be copied and inlined * before we leave the ropper. Redundent successors will result in * redundent (no-op) merges. * * @return all currently known successors * (return destinations) for that subroutine */ IntList getSuccessors() { IntList successors = new IntList(callerBlocks.size()); /* * For each subroutine caller, get it's target. If the * target is us, add the ret target (subroutine successor) * to our list */ for (int label = callerBlocks.nextSetBit(0); label >= 0; label = callerBlocks.nextSetBit(label+1)) { BasicBlock subCaller = labelToBlock(label); successors.add(subCaller.getSuccessors().get(0)); } successors.setImmutable(); return successors; }
/** * Helper for {@link #addOrReplaceBlock} which recursively removes * the given block and all blocks that are (direct and indirect) * successors of it whose labels indicate that they are not in the * normally-translated range. * * @param idx {@code non-null;} block to remove (etc.) */ private void removeBlockAndSpecialSuccessors(int idx) { int minLabel = getMinimumUnreservedLabel(); BasicBlock block = result.get(idx); IntList successors = block.getSuccessors(); int sz = successors.size(); result.remove(idx); resultSubroutines.remove(idx); for (int i = 0; i < sz; i++) { int label = successors.get(i); if (label >= minLabel) { idx = labelToResultIndex(label); if (idx < 0) { throw new RuntimeException("Invalid label " + Hex.u2(label)); } removeBlockAndSpecialSuccessors(idx); } } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }