com.android.dx.ssa.SsaInsn Java Examples
The following examples show how to use
com.android.dx.ssa.SsaInsn.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LivenessAnalyzer.java From Box with Apache License 2.0 | 6 votes |
/** * "v is live-out at n." */ private void liveOutAtBlock() { if (! visitedBlocks.get(blockN.getIndex())) { visitedBlocks.set(blockN.getIndex()); blockN.addLiveOut(regV); ArrayList<SsaInsn> insns; insns = blockN.getInsns(); // Live out at last statement in blockN statementIndex = insns.size() - 1; nextFunction = NextFunction.LIVE_OUT_AT_STATEMENT; } }
Example #2
Source File: LivenessAnalyzer.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * "v is live-out at n." */ private void liveOutAtBlock() { if (! visitedBlocks.get(blockN.getIndex())) { visitedBlocks.set(blockN.getIndex()); blockN.addLiveOut(regV); ArrayList<SsaInsn> insns; insns = blockN.getInsns(); // Live out at last statement in blockN statementIndex = insns.size() - 1; nextFunction = NextFunction.LIVE_OUT_AT_STATEMENT; } }
Example #3
Source File: LivenessAnalyzer.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * 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()); } } } }
Example #4
Source File: FirstFitLocalCombiningAllocator.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * Gets the parameter index for SSA registers that are method parameters. * {@code -1} is returned for non-parameter registers. * * @param ssaReg {@code >=0;} SSA register to look up * @return parameter index or {@code -1} if not a parameter */ private int getParameterIndexForReg(int ssaReg) { SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg); if (defInsn == null) { return -1; } Rop opcode = defInsn.getOpcode(); // opcode == null for phi insns. if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) { CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn(); return ((CstInteger) origInsn.getConstant()).getValue(); } return -1; }
Example #5
Source File: SsaToRop.java From Box with Apache License 2.0 | 6 votes |
/** * Removes all blocks containing only GOTOs from the control flow. * Although much of this work will be done later when converting * from rop to dex, not all simplification cases can be handled * there. Furthermore, any no-op block between the exit block and * blocks containing the real return or throw statements must be * removed. */ private void removeEmptyGotos() { final ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks(); ssaMeth.forEachBlockDepthFirst(false, new SsaBasicBlock.Visitor() { @Override public void visitBlock(SsaBasicBlock b, SsaBasicBlock parent) { ArrayList<SsaInsn> insns = b.getInsns(); if ((insns.size() == 1) && (insns.get(0).getOpcode() == Rops.GOTO)) { BitSet preds = (BitSet) b.getPredecessors().clone(); for (int i = preds.nextSetBit(0); i >= 0; i = preds.nextSetBit(i + 1)) { SsaBasicBlock pb = blocks.get(i); pb.replaceSuccessor(b.getIndex(), b.getPrimarySuccessorIndex()); } } } }); }
Example #6
Source File: SsaToRop.java From J2ME-Loader with Apache License 2.0 | 6 votes |
/** * Removes all blocks containing only GOTOs from the control flow. * Although much of this work will be done later when converting * from rop to dex, not all simplification cases can be handled * there. Furthermore, any no-op block between the exit block and * blocks containing the real return or throw statements must be * removed. */ private void removeEmptyGotos() { final ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks(); ssaMeth.forEachBlockDepthFirst(false, new SsaBasicBlock.Visitor() { @Override public void visitBlock(SsaBasicBlock b, SsaBasicBlock parent) { ArrayList<SsaInsn> insns = b.getInsns(); if ((insns.size() == 1) && (insns.get(0).getOpcode() == Rops.GOTO)) { BitSet preds = (BitSet) b.getPredecessors().clone(); for (int i = preds.nextSetBit(0); i >= 0; i = preds.nextSetBit(i + 1)) { SsaBasicBlock pb = blocks.get(i); pb.replaceSuccessor(b.getIndex(), b.getPrimarySuccessorIndex()); } } } }); }
Example #7
Source File: FirstFitLocalCombiningAllocator.java From Box with Apache License 2.0 | 6 votes |
/** * Gets the parameter index for SSA registers that are method parameters. * {@code -1} is returned for non-parameter registers. * * @param ssaReg {@code >=0;} SSA register to look up * @return parameter index or {@code -1} if not a parameter */ private int getParameterIndexForReg(int ssaReg) { SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg); if (defInsn == null) { return -1; } Rop opcode = defInsn.getOpcode(); // opcode == null for phi insns. if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) { CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn(); return ((CstInteger) origInsn.getConstant()).getValue(); } return -1; }
Example #8
Source File: LivenessAnalyzer.java From Box with Apache License 2.0 | 6 votes |
/** * Ensures that all the phi result registers for all the phis in the * same basic block interfere with each other, and also that a phi's source * registers interfere with the result registers from other phis. 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 process * @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; } SsaInsn first = phis.get(i); SsaInsn second = phis.get(j); coInterferePhiRegisters(interference, first.getResult(), second.getSources()); coInterferePhiRegisters(interference, second.getResult(), first.getSources()); interference.add(first.getResult().getReg(), second.getResult().getReg()); } } } }
Example #9
Source File: LivenessAnalyzer.java From buck with Apache License 2.0 | 6 votes |
/** * "v is live-out at n." */ private void liveOutAtBlock() { if (! visitedBlocks.get(blockN.getIndex())) { visitedBlocks.set(blockN.getIndex()); blockN.addLiveOut(regV); ArrayList<SsaInsn> insns; insns = blockN.getInsns(); // Live out at last statement in blockN statementIndex = insns.size() - 1; nextFunction = NextFunction.LIVE_OUT_AT_STATEMENT; } }
Example #10
Source File: LivenessAnalyzer.java From buck with Apache License 2.0 | 6 votes |
/** * 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()); } } } }
Example #11
Source File: FirstFitLocalCombiningAllocator.java From buck with Apache License 2.0 | 6 votes |
/** * Gets the parameter index for SSA registers that are method parameters. * {@code -1} is returned for non-parameter registers. * * @param ssaReg {@code >=0;} SSA register to look up * @return parameter index or {@code -1} if not a parameter */ private int getParameterIndexForReg(int ssaReg) { SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg); if (defInsn == null) { return -1; } Rop opcode = defInsn.getOpcode(); // opcode == null for phi insns. if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) { CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn(); return ((CstInteger) origInsn.getConstant()).getValue(); } return -1; }
Example #12
Source File: LivenessAnalyzer.java From Box with Apache License 2.0 | 6 votes |
/** * "v is live-out at n." */ private void liveOutAtBlock() { if (! visitedBlocks.get(blockN.getIndex())) { visitedBlocks.set(blockN.getIndex()); blockN.addLiveOut(regV); ArrayList<SsaInsn> insns; insns = blockN.getInsns(); // Live out at last statement in blockN statementIndex = insns.size() - 1; nextFunction = NextFunction.LIVE_OUT_AT_STATEMENT; } }
Example #13
Source File: LivenessAnalyzer.java From Box with Apache License 2.0 | 6 votes |
/** * Ensures that all the phi result registers for all the phis in the * same basic block interfere with each other, and also that a phi's source * registers interfere with the result registers from other phis. 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 process * @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; } SsaInsn first = phis.get(i); SsaInsn second = phis.get(j); coInterferePhiRegisters(interference, first.getResult(), second.getSources()); coInterferePhiRegisters(interference, second.getResult(), first.getSources()); interference.add(first.getResult().getReg(), second.getResult().getReg()); } } } }
Example #14
Source File: FirstFitLocalCombiningAllocator.java From Box with Apache License 2.0 | 6 votes |
/** * Gets the parameter index for SSA registers that are method parameters. * {@code -1} is returned for non-parameter registers. * * @param ssaReg {@code >=0;} SSA register to look up * @return parameter index or {@code -1} if not a parameter */ private int getParameterIndexForReg(int ssaReg) { SsaInsn defInsn = ssaMeth.getDefinitionForRegister(ssaReg); if (defInsn == null) { return -1; } Rop opcode = defInsn.getOpcode(); // opcode == null for phi insns. if (opcode != null && opcode.getOpcode() == RegOps.MOVE_PARAM) { CstInsn origInsn = (CstInsn) defInsn.getOriginalRopInsn(); return ((CstInteger) origInsn.getConstant()).getValue(); } return -1; }
Example #15
Source File: SsaToRop.java From buck with Apache License 2.0 | 6 votes |
/** * Removes all blocks containing only GOTOs from the control flow. * Although much of this work will be done later when converting * from rop to dex, not all simplification cases can be handled * there. Furthermore, any no-op block between the exit block and * blocks containing the real return or throw statements must be * removed. */ private void removeEmptyGotos() { final ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks(); ssaMeth.forEachBlockDepthFirst(false, new SsaBasicBlock.Visitor() { public void visitBlock(SsaBasicBlock b, SsaBasicBlock parent) { ArrayList<SsaInsn> insns = b.getInsns(); if ((insns.size() == 1) && (insns.get(0).getOpcode() == Rops.GOTO)) { BitSet preds = (BitSet) b.getPredecessors().clone(); for (int i = preds.nextSetBit(0); i >= 0; i = preds.nextSetBit(i + 1)) { SsaBasicBlock pb = blocks.get(i); pb.replaceSuccessor(b.getIndex(), b.getPrimarySuccessorIndex()); } } } }); }
Example #16
Source File: SsaToRop.java From Box with Apache License 2.0 | 6 votes |
/** * Removes all blocks containing only GOTOs from the control flow. * Although much of this work will be done later when converting * from rop to dex, not all simplification cases can be handled * there. Furthermore, any no-op block between the exit block and * blocks containing the real return or throw statements must be * removed. */ private void removeEmptyGotos() { final ArrayList<SsaBasicBlock> blocks = ssaMeth.getBlocks(); ssaMeth.forEachBlockDepthFirst(false, new SsaBasicBlock.Visitor() { @Override public void visitBlock(SsaBasicBlock b, SsaBasicBlock parent) { ArrayList<SsaInsn> insns = b.getInsns(); if ((insns.size() == 1) && (insns.get(0).getOpcode() == Rops.GOTO)) { BitSet preds = (BitSet) b.getPredecessors().clone(); for (int i = preds.nextSetBit(0); i >= 0; i = preds.nextSetBit(i + 1)) { SsaBasicBlock pb = blocks.get(i); pb.replaceSuccessor(b.getIndex(), b.getPrimarySuccessorIndex()); } } } }); }
Example #17
Source File: LivenessAnalyzer.java From buck with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example #18
Source File: RegisterAllocator.java From buck with Apache License 2.0 | 5 votes |
/** * Returns true if the definition site of this register is a * move-param (ie, this is a method parameter). * * @param reg register in question * @return {@code true} if this is a method parameter */ protected boolean isDefinitionMoveParam(int reg) { SsaInsn defInsn = ssaMeth.getDefinitionForRegister(reg); if (defInsn instanceof NormalSsaInsn) { NormalSsaInsn ndefInsn = (NormalSsaInsn) defInsn; return ndefInsn.getOpcode().getOpcode() == RegOps.MOVE_PARAM; } return false; }
Example #19
Source File: SsaToRop.java From buck with Apache License 2.0 | 5 votes |
/** * Converts an insn list to rop form. * * @param ssaInsns {@code non-null;} old instructions * @return {@code non-null;} immutable instruction list */ private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns) { int insnCount = ssaInsns.size(); InsnList result = new InsnList(insnCount); for (int i = 0; i < insnCount; i++) { result.set(i, ssaInsns.get(i).toRopInsn()); } result.setImmutable(); return result; }
Example #20
Source File: SsaToRop.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Converts an insn list to rop form. * * @param ssaInsns {@code non-null;} old instructions * @return {@code non-null;} immutable instruction list */ private InsnList convertInsns(ArrayList<SsaInsn> ssaInsns) { int insnCount = ssaInsns.size(); InsnList result = new InsnList(insnCount); for (int i = 0; i < insnCount; i++) { result.set(i, ssaInsns.get(i).toRopInsn()); } result.setImmutable(); return result; }
Example #21
Source File: SsaToRop.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Validates that a basic block is a valid end predecessor. It must * end in a RETURN or a THROW. Throws a runtime exception on error. * * @param b {@code non-null;} block to validate * @throws RuntimeException on error */ private void verifyValidExitPredecessor(SsaBasicBlock b) { ArrayList<SsaInsn> insns = b.getInsns(); SsaInsn lastInsn = insns.get(insns.size() - 1); Rop opcode = lastInsn.getOpcode(); if (opcode.getBranchingness() != Rop.BRANCH_RETURN && opcode != Rops.THROW) { throw new RuntimeException("Exit predecessor must end" + " in valid exit statement."); } }
Example #22
Source File: SsaToRop.java From buck with Apache License 2.0 | 5 votes |
/** * Validates that a basic block is a valid end predecessor. It must * end in a RETURN or a THROW. Throws a runtime exception on error. * * @param b {@code non-null;} block to validate * @throws RuntimeException on error */ private void verifyValidExitPredecessor(SsaBasicBlock b) { ArrayList<SsaInsn> insns = b.getInsns(); SsaInsn lastInsn = insns.get(insns.size() - 1); Rop opcode = lastInsn.getOpcode(); if (opcode.getBranchingness() != Rop.BRANCH_RETURN && opcode != Rops.THROW) { throw new RuntimeException("Exit predecessor must end" + " in valid exit statement."); } }
Example #23
Source File: RegisterAllocator.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Returns true if the definition site of this register is a * move-param (ie, this is a method parameter). * * @param reg register in question * @return {@code true} if this is a method parameter */ protected boolean isDefinitionMoveParam(int reg) { SsaInsn defInsn = ssaMeth.getDefinitionForRegister(reg); if (defInsn instanceof NormalSsaInsn) { NormalSsaInsn ndefInsn = (NormalSsaInsn) defInsn; return ndefInsn.getOpcode().getOpcode() == RegOps.MOVE_PARAM; } return false; }
Example #24
Source File: RegisterAllocator.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Returns the category (width) of the definition site of the register. * Returns {@code 1} for undefined registers. * * @param reg register * @return {@code 1..2} */ protected final int getCategoryForSsaReg(int reg) { SsaInsn definition = ssaMeth.getDefinitionForRegister(reg); if (definition == null) { // an undefined reg return 1; } else { return definition.getResult().getCategory(); } }
Example #25
Source File: RegisterAllocator.java From buck with Apache License 2.0 | 5 votes |
/** * Returns the category (width) of the definition site of the register. * Returns {@code 1} for undefined registers. * * @param reg register * @return {@code 1..2} */ protected final int getCategoryForSsaReg(int reg) { SsaInsn definition = ssaMeth.getDefinitionForRegister(reg); if (definition == null) { // an undefined reg return 1; } else { return definition.getResult().getCategory(); } }
Example #26
Source File: LivenessAnalyzer.java From buck with Apache License 2.0 | 5 votes |
/** * "v is live-out at s." */ private void liveOutAtStatement() { SsaInsn statement = blockN.getInsns().get(statementIndex); RegisterSpec rs = statement.getResult(); if (!statement.isResultReg(regV)) { if (rs != null) { interference.add(regV, rs.getReg()); } nextFunction = NextFunction.LIVE_IN_AT_STATEMENT; } }
Example #27
Source File: LivenessAnalyzer.java From Box with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example #28
Source File: LivenessAnalyzer.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * "v is live-out at s." */ private void liveOutAtStatement() { SsaInsn statement = blockN.getInsns().get(statementIndex); RegisterSpec rs = statement.getResult(); if (!statement.isResultReg(regV)) { if (rs != null) { interference.add(regV, rs.getReg()); } nextFunction = NextFunction.LIVE_IN_AT_STATEMENT; } }
Example #29
Source File: LivenessAnalyzer.java From Box with Apache License 2.0 | 5 votes |
/** * 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(); } }
Example #30
Source File: LivenessAnalyzer.java From Box with Apache License 2.0 | 5 votes |
/** * "v is live-out at s." */ private void liveOutAtStatement() { SsaInsn statement = blockN.getInsns().get(statementIndex); RegisterSpec rs = statement.getResult(); if (!statement.isResultReg(regV)) { if (rs != null) { interference.add(regV, rs.getReg()); } nextFunction = NextFunction.LIVE_IN_AT_STATEMENT; } }