com.android.dx.ssa.SsaMethod Java Examples

The following examples show how to use com.android.dx.ssa.SsaMethod. 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 vote down vote up
/**
 * 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 #2
Source File: LivenessAnalyzer.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #3
Source File: LivenessAnalyzer.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * 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: LivenessAnalyzer.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: LivenessAnalyzer.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Runs register liveness algorithm for a method, updating the
 * live in/out information in {@code SsaBasicBlock} instances and
 * returning an interference graph.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @return {@code non-null;} interference graph indexed by SSA
 * registers in both directions
 */
public static InterferenceGraph constructInterferenceGraph(
        SsaMethod ssaMeth) {
    int szRegs = ssaMeth.getRegCount();
    InterferenceGraph interference = new InterferenceGraph(szRegs);

    for (int i = 0; i < szRegs; i++) {
        new LivenessAnalyzer(ssaMeth, i, interference).run();
    }

    coInterferePhis(ssaMeth, interference);

    return interference;
}
 
Example #6
Source File: FirstFitAllocator.java    From buck with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public FirstFitAllocator(
        final SsaMethod ssaMeth, final InterferenceGraph interference) {
    super(ssaMeth, interference);

    mapped = new BitSet(ssaMeth.getRegCount());
}
 
Example #7
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 #8
Source File: LivenessAnalyzer.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Makes liveness analyzer instance for specific register.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param reg register whose liveness to analyze
 * @param interference {@code non-null;} indexed by SSA reg in
 * both dimensions; graph to update
 *
 */
private LivenessAnalyzer(SsaMethod ssaMeth, int reg,
        InterferenceGraph interference) {
    int blocksSz = ssaMeth.getBlocks().size();

    this.ssaMeth = ssaMeth;
    this.regV = reg;
    visitedBlocks = new BitSet(blocksSz);
    liveOutBlocks = new BitSet(blocksSz);
    this.interference = interference;
}
 
Example #9
Source File: LivenessAnalyzer.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Runs register liveness algorithm for a method, updating the
 * live in/out information in {@code SsaBasicBlock} instances and
 * returning an interference graph.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @return {@code non-null;} interference graph indexed by SSA
 * registers in both directions
 */
public static InterferenceGraph constructInterferenceGraph(
        SsaMethod ssaMeth) {
    int szRegs = ssaMeth.getRegCount();
    InterferenceGraph interference = new InterferenceGraph(szRegs);

    for (int i = 0; i < szRegs; i++) {
        new LivenessAnalyzer(ssaMeth, i, interference).run();
    }

    coInterferePhis(ssaMeth, interference);

    return interference;
}
 
Example #10
Source File: FirstFitAllocator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public FirstFitAllocator(
        final SsaMethod ssaMeth, final InterferenceGraph interference) {
    super(ssaMeth, interference);

    mapped = new BitSet(ssaMeth.getRegCount());
}
 
Example #11
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 #12
Source File: LivenessAnalyzer.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Makes liveness analyzer instance for specific register.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param reg register whose liveness to analyze
 * @param interference {@code non-null;} indexed by SSA reg in
 * both dimensions; graph to update
 *
 */
private LivenessAnalyzer(SsaMethod ssaMeth, int reg,
        InterferenceGraph interference) {
    int blocksSz = ssaMeth.getBlocks().size();

    this.ssaMeth = ssaMeth;
    this.regV = reg;
    visitedBlocks = new BitSet(blocksSz);
    liveOutBlocks = new BitSet(blocksSz);
    this.interference = interference;
}
 
Example #13
Source File: LivenessAnalyzer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Runs register liveness algorithm for a method, updating the
 * live in/out information in {@code SsaBasicBlock} instances and
 * returning an interference graph.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @return {@code non-null;} interference graph indexed by SSA
 * registers in both directions
 */
public static InterferenceGraph constructInterferenceGraph(
        SsaMethod ssaMeth) {
    int szRegs = ssaMeth.getRegCount();
    InterferenceGraph interference = new InterferenceGraph(szRegs);

    for (int i = 0; i < szRegs; i++) {
        new LivenessAnalyzer(ssaMeth, i, interference).run();
    }

    coInterferePhis(ssaMeth, interference);

    return interference;
}
 
Example #14
Source File: FirstFitAllocator.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public FirstFitAllocator(
        final SsaMethod ssaMeth, final InterferenceGraph interference) {
    super(ssaMeth, interference);

    mapped = new BitSet(ssaMeth.getRegCount());
}
 
Example #15
Source File: LivenessAnalyzer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Makes liveness analyzer instance for specific register.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param reg register whose liveness to analyze
 * @param interference {@code non-null;} indexed by SSA reg in
 * both dimensions; graph to update
 *
 */
private LivenessAnalyzer(SsaMethod ssaMeth, int reg,
        InterferenceGraph interference) {
    int blocksSz = ssaMeth.getBlocks().size();

    this.ssaMeth = ssaMeth;
    this.regV = reg;
    visitedBlocks = new BitSet(blocksSz);
    liveOutBlocks = new BitSet(blocksSz);
    this.interference = interference;
}
 
Example #16
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 #17
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 #18
Source File: LivenessAnalyzer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Makes liveness analyzer instance for specific register.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param reg register whose liveness to analyze
 * @param interference {@code non-null;} indexed by SSA reg in
 * both dimensions; graph to update
 *
 */
private LivenessAnalyzer(SsaMethod ssaMeth, int reg,
        InterferenceGraph interference) {
    int blocksSz = ssaMeth.getBlocks().size();

    this.ssaMeth = ssaMeth;
    this.regV = reg;
    visitedBlocks = new BitSet(blocksSz);
    liveOutBlocks = new BitSet(blocksSz);
    this.interference = interference;
}
 
Example #19
Source File: LivenessAnalyzer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Runs register liveness algorithm for a method, updating the
 * live in/out information in {@code SsaBasicBlock} instances and
 * returning an interference graph.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @return {@code non-null;} interference graph indexed by SSA
 * registers in both directions
 */
public static InterferenceGraph constructInterferenceGraph(
        SsaMethod ssaMeth) {
    int szRegs = ssaMeth.getRegCount();
    InterferenceGraph interference = new InterferenceGraph(szRegs);

    for (int i = 0; i < szRegs; i++) {
        new LivenessAnalyzer(ssaMeth, i, interference).run();
    }

    coInterferePhis(ssaMeth, interference);

    return interference;
}
 
Example #20
Source File: FirstFitAllocator.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public FirstFitAllocator(
        final SsaMethod ssaMeth, final InterferenceGraph interference) {
    super(ssaMeth, interference);

    mapped = new BitSet(ssaMeth.getRegCount());
}
 
Example #21
Source File: NullRegisterAllocator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public NullRegisterAllocator(SsaMethod ssaMeth,
        InterferenceGraph interference) {
    super(ssaMeth, interference);
}
 
Example #22
Source File: NullRegisterAllocator.java    From buck with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public NullRegisterAllocator(SsaMethod ssaMeth,
        InterferenceGraph interference) {
    super(ssaMeth, interference);
}
 
Example #23
Source File: NullRegisterAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public NullRegisterAllocator(SsaMethod ssaMeth,
        InterferenceGraph interference) {
    super(ssaMeth, interference);
}
 
Example #24
Source File: NullRegisterAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public NullRegisterAllocator(SsaMethod ssaMeth,
        InterferenceGraph interference) {
    super(ssaMeth, interference);
}
 
Example #25
Source File: SsaToRop.java    From J2ME-Loader with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param minimizeRegisters {@code true} if the converter should
 * attempt to minimize the rop-form register count
 */
private SsaToRop(SsaMethod ssaMethod, boolean minimizeRegisters) {
    this.minimizeRegisters = minimizeRegisters;
    this.ssaMeth = ssaMethod;
    this.interference =
        LivenessAnalyzer.constructInterferenceGraph(ssaMethod);
}
 
Example #26
Source File: SsaToRop.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ssaMethod {@code non-null;} method to process
 * @param minimizeRegisters {@code true} if the converter should
 * attempt to minimize the rop-form register count
 */
private SsaToRop(SsaMethod ssaMethod, boolean minimizeRegisters) {
    this.minimizeRegisters = minimizeRegisters;
    this.ssaMeth = ssaMethod;
    this.interference =
        LivenessAnalyzer.constructInterferenceGraph(ssaMethod);
}
 
Example #27
Source File: SsaToRop.java    From buck with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param minimizeRegisters {@code true} if the converter should
 * attempt to minimize the rop-form register count
 */
private SsaToRop(SsaMethod ssaMethod, boolean minimizeRegisters) {
    this.minimizeRegisters = minimizeRegisters;
    this.ssaMeth = ssaMethod;
    this.interference =
        LivenessAnalyzer.constructInterferenceGraph(ssaMethod);
}
 
Example #28
Source File: SsaToRop.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs an instance.
 *
 * @param ssaMethod {@code non-null;} method to process
 * @param minimizeRegisters {@code true} if the converter should
 * attempt to minimize the rop-form register count
 */
private SsaToRop(SsaMethod ssaMethod, boolean minimizeRegisters) {
    this.minimizeRegisters = minimizeRegisters;
    this.ssaMeth = ssaMethod;
    this.interference =
        LivenessAnalyzer.constructInterferenceGraph(ssaMethod);
}
 
Example #29
Source File: SsaToRop.java    From J2ME-Loader with Apache License 2.0 2 votes vote down vote up
/**
 * Converts a method in SSA form to ROP form.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param minimizeRegisters {@code true} if the converter should
 * attempt to minimize the rop-form register count
 * @return {@code non-null;} rop-form output
 */
public static RopMethod convertToRopMethod(SsaMethod ssaMeth,
        boolean minimizeRegisters) {
    return new SsaToRop(ssaMeth, minimizeRegisters).convert();
}
 
Example #30
Source File: SsaToRop.java    From Box with Apache License 2.0 2 votes vote down vote up
/**
 * Converts a method in SSA form to ROP form.
 *
 * @param ssaMeth {@code non-null;} method to process
 * @param minimizeRegisters {@code true} if the converter should
 * attempt to minimize the rop-form register count
 * @return {@code non-null;} rop-form output
 */
public static RopMethod convertToRopMethod(SsaMethod ssaMeth,
        boolean minimizeRegisters) {
    return new SsaToRop(ssaMeth, minimizeRegisters).convert();
}