com.android.dx.ssa.PhiInsn Java Examples

The following examples show how to use com.android.dx.ssa.PhiInsn. 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 J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #2
Source File: SsaToRop.java    From buck with Apache License 2.0 5 votes vote down vote up
public void visitPhiInsn(PhiInsn insn) {
    RegisterSpecList sources = insn.getSources();
    RegisterSpec result = insn.getResult();
    int sz = sources.size();

    for (int i = 0; i < sz; i++) {
        RegisterSpec source = sources.get(i);
        SsaBasicBlock predBlock = blocks.get(
                insn.predBlockIndexForSourcesIndex(i));

        predBlock.addMoveToEnd(result, source);
    }
}
 
Example #3
Source File: FirstFitLocalCombiningAllocator.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs instance.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param interference non-null interference graph for SSA registers
 * @param minimizeRegisters true if converter should take steps to
 * minimize rop-form registers
 */
public FirstFitLocalCombiningAllocator(
        SsaMethod ssaMeth, InterferenceGraph interference,
        boolean minimizeRegisters) {
    super(ssaMeth, interference);

    ssaRegsMapped = new BitSet(ssaMeth.getRegCount());

    mapper = new InterferenceRegisterMapper(
            interference, ssaMeth.getRegCount());

    this.minimizeRegisters = minimizeRegisters;

    /*
     * Reserve space for the params at the bottom of the register
     * space. Later, we'll flip the params to the end of the register
     * space.
     */

    paramRangeEnd = ssaMeth.getParamWidth();

    reservedRopRegs = new BitSet(paramRangeEnd * 2);
    reservedRopRegs.set(0, paramRangeEnd);
    usedRopRegs = new BitSet(paramRangeEnd * 2);
    localVariables = new TreeMap<LocalItem, ArrayList<RegisterSpec>>();
    moveResultPseudoInsns = new ArrayList<NormalSsaInsn>();
    invokeRangeInsns = new ArrayList<NormalSsaInsn>();
    phiInsns = new ArrayList<PhiInsn>();
}
 
Example #4
Source File: LivenessAnalyzer.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #5
Source File: SsaToRop.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
@Override
public void visitPhiInsn(PhiInsn insn) {
          RegisterSpecList sources = insn.getSources();
          RegisterSpec result = insn.getResult();
          int sz = sources.size();

          for (int i = 0; i < sz; i++) {
              RegisterSpec source = sources.get(i);
              SsaBasicBlock predBlock = blocks.get(
                      insn.predBlockIndexForSourcesIndex(i));

              predBlock.addMoveToEnd(result, source);
          }
      }
 
Example #6
Source File: FirstFitLocalCombiningAllocator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
   * Constructs instance.
   *
   * @param ssaMeth {@code non-null;} method to process
   * @param interference non-null interference graph for SSA registers
   * @param minimizeRegisters true if converter should take steps to
   * minimize rop-form registers
   */
  public FirstFitLocalCombiningAllocator(
          SsaMethod ssaMeth, InterferenceGraph interference,
          boolean minimizeRegisters) {
      super(ssaMeth, interference);

      ssaRegsMapped = new BitSet(ssaMeth.getRegCount());

      mapper = new InterferenceRegisterMapper(
              interference, ssaMeth.getRegCount());

/*
       * Reserve space for the params at the bottom of the register
       * space. Later, we'll flip the params to the end of the register
       * space.
       */

      paramRangeEnd = ssaMeth.getParamWidth();

      reservedRopRegs = new BitSet(paramRangeEnd * 2);
      reservedRopRegs.set(0, paramRangeEnd);
      usedRopRegs = new BitSet(paramRangeEnd * 2);
      localVariables = new TreeMap<LocalItem, ArrayList<RegisterSpec>>();
      moveResultPseudoInsns = new ArrayList<NormalSsaInsn>();
      invokeRangeInsns = new ArrayList<NormalSsaInsn>();
      phiInsns = new ArrayList<PhiInsn>();
  }
 
Example #7
Source File: LivenessAnalyzer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #8
Source File: SsaToRop.java    From Box with Apache License 2.0 5 votes vote down vote up
@Override
public void visitPhiInsn(PhiInsn insn) {
    RegisterSpecList sources = insn.getSources();
    RegisterSpec result = insn.getResult();
    int sz = sources.size();

    for (int i = 0; i < sz; i++) {
        RegisterSpec source = sources.get(i);
        SsaBasicBlock predBlock = blocks.get(
                insn.predBlockIndexForSourcesIndex(i));

        predBlock.addMoveToEnd(result, source);
    }
}
 
Example #9
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs instance.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param interference non-null interference graph for SSA registers
 * @param minimizeRegisters true if converter should take steps to
 * minimize rop-form registers
 */
public FirstFitLocalCombiningAllocator(
        SsaMethod ssaMeth, InterferenceGraph interference,
        boolean minimizeRegisters) {
    super(ssaMeth, interference);

    ssaRegsMapped = new BitSet(ssaMeth.getRegCount());

    mapper = new InterferenceRegisterMapper(
            interference, ssaMeth.getRegCount());

    this.minimizeRegisters = minimizeRegisters;

    /*
     * Reserve space for the params at the bottom of the register
     * space. Later, we'll flip the params to the end of the register
     * space.
     */

    paramRangeEnd = ssaMeth.getParamWidth();

    reservedRopRegs = new BitSet(paramRangeEnd * 2);
    reservedRopRegs.set(0, paramRangeEnd);
    usedRopRegs = new BitSet(paramRangeEnd * 2);
    localVariables = new TreeMap<LocalItem, ArrayList<RegisterSpec>>();
    moveResultPseudoInsns = new ArrayList<NormalSsaInsn>();
    invokeRangeInsns = new ArrayList<NormalSsaInsn>();
    phiInsns = new ArrayList<PhiInsn>();
}
 
Example #10
Source File: LivenessAnalyzer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #11
Source File: SsaToRop.java    From Box with Apache License 2.0 5 votes vote down vote up
@Override
public void visitPhiInsn(PhiInsn insn) {
    RegisterSpecList sources = insn.getSources();
    RegisterSpec result = insn.getResult();
    int sz = sources.size();

    for (int i = 0; i < sz; i++) {
        RegisterSpec source = sources.get(i);
        SsaBasicBlock predBlock = blocks.get(
                insn.predBlockIndexForSourcesIndex(i));

        predBlock.addMoveToEnd(result, source);
    }
}
 
Example #12
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs instance.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param interference non-null interference graph for SSA registers
 * @param minimizeRegisters true if converter should take steps to
 * minimize rop-form registers
 */
public FirstFitLocalCombiningAllocator(
        SsaMethod ssaMeth, InterferenceGraph interference,
        boolean minimizeRegisters) {
    super(ssaMeth, interference);

    ssaRegsMapped = new BitSet(ssaMeth.getRegCount());

    mapper = new InterferenceRegisterMapper(
            interference, ssaMeth.getRegCount());

    this.minimizeRegisters = minimizeRegisters;

    /*
     * Reserve space for the params at the bottom of the register
     * space. Later, we'll flip the params to the end of the register
     * space.
     */

    paramRangeEnd = ssaMeth.getParamWidth();

    reservedRopRegs = new BitSet(paramRangeEnd * 2);
    reservedRopRegs.set(0, paramRangeEnd);
    usedRopRegs = new BitSet(paramRangeEnd * 2);
    localVariables = new TreeMap<LocalItem, ArrayList<RegisterSpec>>();
    moveResultPseudoInsns = new ArrayList<NormalSsaInsn>();
    invokeRangeInsns = new ArrayList<NormalSsaInsn>();
    phiInsns = new ArrayList<PhiInsn>();
}
 
Example #13
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to map the sources and result of a phi to a common register.
 * Will try existing mappings first, from most to least common. If none
 * of the registers have mappings yet, a new mapping is created.
 */
private void processPhiInsn(PhiInsn insn) {
    RegisterSpec result = insn.getResult();
    int resultReg = result.getReg();
    int category = result.getCategory();

    RegisterSpecList sources = insn.getSources();
    int sourcesSize = sources.size();

    // List of phi sources / result that need mapping
    ArrayList<RegisterSpec> ssaRegs = new ArrayList<RegisterSpec>();

    // Track how many times a particular mapping is found
    Multiset mapSet = new Multiset(sourcesSize + 1);

    /*
     * If the result of the phi has an existing mapping, get it.
     * Otherwise, add it to the list of regs that need mapping.
     */
    if (ssaRegsMapped.get(resultReg)) {
        mapSet.add(mapper.oldToNew(resultReg));
    } else {
        ssaRegs.add(result);
    }

    for (int i = 0; i < sourcesSize; i++) {
        RegisterSpec source = sources.get(i);
        SsaInsn def = ssaMeth.getDefinitionForRegister(source.getReg());
        RegisterSpec sourceDef = def.getResult();
        int sourceReg = sourceDef.getReg();

        /*
         * If a source of the phi has an existing mapping, get it.
         * Otherwise, add it to the list of regs that need mapping.
         */
        if (ssaRegsMapped.get(sourceReg)) {
            mapSet.add(mapper.oldToNew(sourceReg));
        } else {
            ssaRegs.add(sourceDef);
        }
    }

    // Try all existing mappings, with the most common ones first
    for (int i = 0; i < mapSet.getSize(); i++) {
        int maxReg = mapSet.getAndRemoveHighestCount();
        tryMapRegs(ssaRegs, maxReg, category, false);
    }

    // Map any remaining unmapped regs with whatever fits
    int mapReg = findNextUnreservedRopReg(paramRangeEnd, category);
    while (!tryMapRegs(ssaRegs, mapReg, category, false)) {
        mapReg = findNextUnreservedRopReg(mapReg + 1, category);
    }
}
 
Example #14
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
* Handles all phi instructions, trying to map them to a common register.
*/
private void handlePhiInsns() {
    for (PhiInsn insn : phiInsns) {
        processPhiInsn(insn);
    }
}
 
Example #15
Source File: FirstFitLocalCombiningAllocator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
* Handles all phi instructions, trying to map them to a common register.
*/
private void handlePhiInsns() {
    for (PhiInsn insn : phiInsns) {
        processPhiInsn(insn);
    }
}
 
Example #16
Source File: FirstFitLocalCombiningAllocator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to map the sources and result of a phi to a common register.
 * Will try existing mappings first, from most to least common. If none
 * of the registers have mappings yet, a new mapping is created.
 */
private void processPhiInsn(PhiInsn insn) {
    RegisterSpec result = insn.getResult();
    int resultReg = result.getReg();
    int category = result.getCategory();

    RegisterSpecList sources = insn.getSources();
    int sourcesSize = sources.size();

    // List of phi sources / result that need mapping
    ArrayList<RegisterSpec> ssaRegs = new ArrayList<RegisterSpec>();

    // Track how many times a particular mapping is found
    Multiset mapSet = new Multiset(sourcesSize + 1);

    /*
     * If the result of the phi has an existing mapping, get it.
     * Otherwise, add it to the list of regs that need mapping.
     */
    if (ssaRegsMapped.get(resultReg)) {
        mapSet.add(mapper.oldToNew(resultReg));
    } else {
        ssaRegs.add(result);
    }

    for (int i = 0; i < sourcesSize; i++) {
        RegisterSpec source = sources.get(i);
        SsaInsn def = ssaMeth.getDefinitionForRegister(source.getReg());
        RegisterSpec sourceDef = def.getResult();
        int sourceReg = sourceDef.getReg();

        /*
         * If a source of the phi has an existing mapping, get it.
         * Otherwise, add it to the list of regs that need mapping.
         */
        if (ssaRegsMapped.get(sourceReg)) {
            mapSet.add(mapper.oldToNew(sourceReg));
        } else {
            ssaRegs.add(sourceDef);
        }
    }

    // Try all existing mappings, with the most common ones first
    for (int i = 0; i < mapSet.getSize(); i++) {
        int maxReg = mapSet.getAndRemoveHighestCount();
        tryMapRegs(ssaRegs, maxReg, category, false);
    }

    // Map any remaining unmapped regs with whatever fits
    int mapReg = findNextUnreservedRopReg(paramRangeEnd, category);
    while (!tryMapRegs(ssaRegs, mapReg, category, false)) {
        mapReg = findNextUnreservedRopReg(mapReg + 1, category);
    }
}
 
Example #17
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to map the sources and result of a phi to a common register.
 * Will try existing mappings first, from most to least common. If none
 * of the registers have mappings yet, a new mapping is created.
 */
private void processPhiInsn(PhiInsn insn) {
    RegisterSpec result = insn.getResult();
    int resultReg = result.getReg();
    int category = result.getCategory();

    RegisterSpecList sources = insn.getSources();
    int sourcesSize = sources.size();

    // List of phi sources / result that need mapping
    ArrayList<RegisterSpec> ssaRegs = new ArrayList<RegisterSpec>();

    // Track how many times a particular mapping is found
    Multiset mapSet = new Multiset(sourcesSize + 1);

    /*
     * If the result of the phi has an existing mapping, get it.
     * Otherwise, add it to the list of regs that need mapping.
     */
    if (ssaRegsMapped.get(resultReg)) {
        mapSet.add(mapper.oldToNew(resultReg));
    } else {
        ssaRegs.add(result);
    }

    for (int i = 0; i < sourcesSize; i++) {
        RegisterSpec source = sources.get(i);
        SsaInsn def = ssaMeth.getDefinitionForRegister(source.getReg());
        RegisterSpec sourceDef = def.getResult();
        int sourceReg = sourceDef.getReg();

        /*
         * If a source of the phi has an existing mapping, get it.
         * Otherwise, add it to the list of regs that need mapping.
         */
        if (ssaRegsMapped.get(sourceReg)) {
            mapSet.add(mapper.oldToNew(sourceReg));
        } else {
            ssaRegs.add(sourceDef);
        }
    }

    // Try all existing mappings, with the most common ones first
    for (int i = 0; i < mapSet.getSize(); i++) {
        int maxReg = mapSet.getAndRemoveHighestCount();
        tryMapRegs(ssaRegs, maxReg, category, false);
    }

    // Map any remaining unmapped regs with whatever fits
    int mapReg = findNextUnreservedRopReg(paramRangeEnd, category);
    while (!tryMapRegs(ssaRegs, mapReg, category, false)) {
        mapReg = findNextUnreservedRopReg(mapReg + 1, category);
    }
}
 
Example #18
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
* Handles all phi instructions, trying to map them to a common register.
*/
private void handlePhiInsns() {
    for (PhiInsn insn : phiInsns) {
        processPhiInsn(insn);
    }
}
 
Example #19
Source File: FirstFitLocalCombiningAllocator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
* Handles all phi instructions, trying to map them to a common register.
*/
private void handlePhiInsns() {
    for (PhiInsn insn : phiInsns) {
        processPhiInsn(insn);
    }
}
 
Example #20
Source File: FirstFitLocalCombiningAllocator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to map the sources and result of a phi to a common register.
 * Will try existing mappings first, from most to least common. If none
 * of the registers have mappings yet, a new mapping is created.
 */
private void processPhiInsn(PhiInsn insn) {
    RegisterSpec result = insn.getResult();
    int resultReg = result.getReg();
    int category = result.getCategory();

    RegisterSpecList sources = insn.getSources();
    int sourcesSize = sources.size();

    // List of phi sources / result that need mapping
    ArrayList<RegisterSpec> ssaRegs = new ArrayList<RegisterSpec>();

    // Track how many times a particular mapping is found
    Multiset mapSet = new Multiset(sourcesSize + 1);

    /*
     * If the result of the phi has an existing mapping, get it.
     * Otherwise, add it to the list of regs that need mapping.
     */
    if (ssaRegsMapped.get(resultReg)) {
        mapSet.add(mapper.oldToNew(resultReg));
    } else {
        ssaRegs.add(result);
    }

    for (int i = 0; i < sourcesSize; i++) {
        RegisterSpec source = sources.get(i);
        SsaInsn def = ssaMeth.getDefinitionForRegister(source.getReg());
        RegisterSpec sourceDef = def.getResult();
        int sourceReg = sourceDef.getReg();

        /*
         * If a source of the phi has an existing mapping, get it.
         * Otherwise, add it to the list of regs that need mapping.
         */
        if (ssaRegsMapped.get(sourceReg)) {
            mapSet.add(mapper.oldToNew(sourceReg));
        } else {
            ssaRegs.add(sourceDef);
        }
    }

    // Try all existing mappings, with the most common ones first
    for (int i = 0; i < mapSet.getSize(); i++) {
        int maxReg = mapSet.getAndRemoveHighestCount();
        tryMapRegs(ssaRegs, maxReg, category, false);
    }

    // Map any remaining unmapped regs with whatever fits
    int mapReg = findNextUnreservedRopReg(paramRangeEnd, category);
    while (!tryMapRegs(ssaRegs, mapReg, category, false)) {
        mapReg = findNextUnreservedRopReg(mapReg + 1, category);
    }
}