com.android.dx.rop.code.LocalItem Java Examples

The following examples show how to use com.android.dx.rop.code.LocalItem. 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: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Dumps local variable table to stdout for debugging.
 */
private void printLocalVars() {
    System.out.println("Printing local vars");
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> e :
            localVariables.entrySet()) {
        StringBuilder regs = new StringBuilder();

        regs.append('{');
        regs.append(' ');
        for (RegisterSpec reg : e.getValue()) {
            regs.append('v');
            regs.append(reg.getReg());
            regs.append(' ');
        }
        regs.append('}');
        System.out.printf("Local: %s Registers: %s\n", e.getKey(), regs);
    }
}
 
Example #2
Source File: NormalSsaInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public RegisterSpec getLocalAssignment() {
    RegisterSpec assignment;

    if (insn.getOpcode().getOpcode() == RegOps.MARK_LOCAL) {
        assignment = insn.getSources().get(0);
    } else {
        assignment = getResult();
    }

    if (assignment == null) {
        return null;
    }

    LocalItem local = assignment.getLocalItem();

    if (local == null) {
        return null;
    }

    return assignment;
}
 
Example #3
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Dumps local variable table to stdout for debugging.
 */
private void printLocalVars() {
    System.out.println("Printing local vars");
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> e :
            localVariables.entrySet()) {
        StringBuilder regs = new StringBuilder();

        regs.append('{');
        regs.append(' ');
        for (RegisterSpec reg : e.getValue()) {
            regs.append('v');
            regs.append(reg.getReg());
            regs.append(' ');
        }
        regs.append('}');
        System.out.printf("Local: %s Registers: %s\n", e.getKey(), regs);
    }
}
 
Example #4
Source File: FirstFitLocalCombiningAllocator.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Dumps local variable table to stdout for debugging.
 */
private void printLocalVars() {
    System.out.println("Printing local vars");
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> e :
            localVariables.entrySet()) {
        StringBuilder regs = new StringBuilder();

        regs.append('{');
        regs.append(' ');
        for (RegisterSpec reg : e.getValue()) {
            regs.append('v');
            regs.append(reg.getReg());
            regs.append(' ');
        }
        regs.append('}');
        System.out.printf("Local: %s Registers: %s\n", e.getKey(), regs);
    }
}
 
Example #5
Source File: FirstFitLocalCombiningAllocator.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Dumps local variable table to stdout for debugging.
 */
private void printLocalVars() {
    System.out.println("Printing local vars");
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> e :
            localVariables.entrySet()) {
        StringBuilder regs = new StringBuilder();

        regs.append('{');
        regs.append(' ');
        for (RegisterSpec reg : e.getValue()) {
            regs.append('v');
            regs.append(reg.getReg());
            regs.append(' ');
        }
        regs.append('}');
        System.out.printf("Local: %s Registers: %s\n", e.getKey(), regs);
    }
}
 
Example #6
Source File: NormalSsaInsn.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public RegisterSpec getLocalAssignment() {
    RegisterSpec assignment;

    if (insn.getOpcode().getOpcode() == RegOps.MARK_LOCAL) {
        assignment = insn.getSources().get(0);
    } else {
        assignment = getResult();
    }

    if (assignment == null) {
        return null;
    }

    LocalItem local = assignment.getLocalItem();

    if (local == null) {
        return null;
    }

    return assignment;
}
 
Example #7
Source File: NormalSsaInsn.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public RegisterSpec getLocalAssignment() {
    RegisterSpec assignment;

    if (insn.getOpcode().getOpcode() == RegOps.MARK_LOCAL) {
        assignment = insn.getSources().get(0);
    } else {
        assignment = getResult();
    }

    if (assignment == null) {
        return null;
    }

    LocalItem local = assignment.getLocalItem();

    if (local == null) {
        return null;
    }

    return assignment;
}
 
Example #8
Source File: NormalSsaInsn.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public RegisterSpec getLocalAssignment() {
    RegisterSpec assignment;

    if (insn.getOpcode().getOpcode() == RegOps.MARK_LOCAL) {
        assignment = insn.getSources().get(0);
    } else {
        assignment = getResult();
    }

    if (assignment == null) {
        return null;
    }

    LocalItem local = assignment.getLocalItem();

    if (local == null) {
        return null;
    }

    return assignment;
}
 
Example #9
Source File: OutputFinisher.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Helper for {@link #getAllConstants} which adds all the info for
 * a single {@code RegisterSpec}.
 *
 * @param result {@code non-null;} result set to add to
 * @param spec {@code null-ok;} register spec to add
 */
private static void addConstants(HashSet<Constant> result,
        RegisterSpec spec) {
    if (spec == null) {
        return;
    }

    LocalItem local = spec.getLocalItem();
    CstString name = local.getName();
    CstString signature = local.getSignature();
    Type type = spec.getType();

    if (type != Type.KNOWN_NULL) {
        result.add(CstType.intern(type));
    }

    if (name != null) {
        result.add(name);
    }

    if (signature != null) {
        result.add(signature);
    }
}
 
Example #10
Source File: SsaRenamer.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Records a debug (local variable) name for a specified register.
 *
 * @param ssaReg non-null named register spec in SSA name space
 */
private void setNameForSsaReg(RegisterSpec ssaReg) {
    int reg = ssaReg.getReg();
    LocalItem local = ssaReg.getLocalItem();

    ssaRegToLocalItems.ensureCapacity(reg + 1);
    while (ssaRegToLocalItems.size() <= reg) {
        ssaRegToLocalItems.add(null);
    }

    ssaRegToLocalItems.set(reg, local);
}
 
Example #11
Source File: OutputFinisher.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #getAllConstants} which adds all the info for
 * a single {@code RegisterSpec}.
 *
 * @param result {@code non-null;} result set to add to
 * @param spec {@code null-ok;} register spec to add
 */
private static void addConstants(HashSet<Constant> result,
        RegisterSpec spec) {
    if (spec == null) {
        return;
    }

    LocalItem local = spec.getLocalItem();
    CstString name = local.getName();
    CstString signature = local.getSignature();
    Type type = spec.getType();

    if (type != Type.KNOWN_NULL) {
        result.add(CstType.intern(type));
    } else {
        /* If this a "known null", let's use "Object" because that's going to be the
         * resulting type in {@link LocalList.MakeState#filterSpec} */
        result.add(CstType.intern(Type.OBJECT));
    }

    if (name != null) {
        result.add(name);
    }

    if (signature != null) {
        result.add(signature);
    }
}
 
Example #12
Source File: SsaInsn.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the local association for the result of this insn. This is
 * sometimes updated during the SsaRenamer process.
 *
 * @param local {@code null-ok;} new debug/local variable info
 */
public final void setResultLocal(LocalItem local) {
    LocalItem oldItem = result.getLocalItem();

    if (local != oldItem && (local == null
            || !local.equals(result.getLocalItem()))) {
        result = RegisterSpec.makeLocalOptional(
                result.getReg(), result.getType(), local);
    }
}
 
Example #13
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a local item associated with an ssa register, if one exists.
 *
 * @param ssaReg {@code >= 0;} SSA register
 * @return {@code null-ok;} associated local item or null
 */
private LocalItem getLocalItemForReg(int ssaReg) {
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> entry :
             localVariables.entrySet()) {
        for (RegisterSpec spec : entry.getValue()) {
            if (spec.getReg() == ssaReg) {
                return entry.getKey();
            }
        }
    }

    return null;
}
 
Example #14
Source File: ConstCollector.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts mark-locals if necessary when changing a register. If
 * the definition of {@code origReg} is associated with a local
 * variable, then insert a mark-local for {@code newReg} just below
 * it. We expect the definition of  {@code origReg} to ultimately
 * be removed by the dead code eliminator
 *
 * @param origReg {@code non-null;} original register
 * @param newReg {@code non-null;} new register that will replace
 * {@code origReg}
 */
private void fixLocalAssignment(RegisterSpec origReg,
        RegisterSpec newReg) {
    for (SsaInsn use : ssaMeth.getUseListForRegister(origReg.getReg())) {
        RegisterSpec localAssignment = use.getLocalAssignment();
        if (localAssignment == null) {
            continue;
        }

        if (use.getResult() == null) {
            /*
             * This is a mark-local. it will be updated when all uses
             * are updated.
             */
            continue;
        }

        LocalItem local = localAssignment.getLocalItem();

        // Un-associate original use.
        use.setResultLocal(null);

        // Now add a mark-local to the new reg immediately after.
        newReg = newReg.withLocalItem(local);

        SsaInsn newInsn
                = SsaInsn.makeFromRop(
                    new PlainInsn(Rops.opMarkLocal(newReg),
                    SourcePosition.NO_INFO, null,
                            RegisterSpecList.make(newReg)),
                use.getBlock());

        ArrayList<SsaInsn> insns = use.getBlock().getInsns();

        insns.add(insns.indexOf(use) + 1, newInsn);
    }
}
 
Example #15
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 #16
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a local item associated with an ssa register, if one exists.
 *
 * @param ssaReg {@code >= 0;} SSA register
 * @return {@code null-ok;} associated local item or null
 */
private LocalItem getLocalItemForReg(int ssaReg) {
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> entry :
             localVariables.entrySet()) {
        for (RegisterSpec spec : entry.getValue()) {
            if (spec.getReg() == ssaReg) {
                return entry.getKey();
            }
        }
    }

    return null;
}
 
Example #17
Source File: SsaInsn.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the local association for the result of this insn. This is
 * sometimes updated during the SsaRenamer process.
 *
 * @param local {@code null-ok;} new debug/local variable info
 */
public final void setResultLocal(LocalItem local) {
    LocalItem oldItem = result.getLocalItem();

    if (local != oldItem && (local == null
            || !local.equals(result.getLocalItem()))) {
        result = RegisterSpec.makeLocalOptional(
                result.getReg(), result.getType(), local);
    }
}
 
Example #18
Source File: SsaInsn.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the local association for the result of this insn. This is
 * sometimes updated during the SsaRenamer process.
 *
 * @param local {@code null-ok;} new debug/local variable info
 */
public final void setResultLocal(LocalItem local) {
    LocalItem oldItem = result.getLocalItem();

    if (local != oldItem && (local == null
            || !local.equals(result.getLocalItem()))) {
        result = RegisterSpec.makeLocalOptional(
                result.getReg(), result.getType(), local);
    }
}
 
Example #19
Source File: SsaRenamer.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Records a debug (local variable) name for a specified register.
 *
 * @param ssaReg non-null named register spec in SSA name space
 */
private void setNameForSsaReg(RegisterSpec ssaReg) {
    int reg = ssaReg.getReg();
    LocalItem local = ssaReg.getLocalItem();

    ssaRegToLocalItems.ensureCapacity(reg + 1);
    while (ssaRegToLocalItems.size() <= reg) {
        ssaRegToLocalItems.add(null);
    }

    ssaRegToLocalItems.set(reg, local);
}
 
Example #20
Source File: ConstCollector.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts mark-locals if necessary when changing a register. If
 * the definition of {@code origReg} is associated with a local
 * variable, then insert a mark-local for {@code newReg} just below
 * it. We expect the definition of  {@code origReg} to ultimately
 * be removed by the dead code eliminator
 *
 * @param origReg {@code non-null;} original register
 * @param newReg {@code non-null;} new register that will replace
 * {@code origReg}
 */
private void fixLocalAssignment(RegisterSpec origReg,
        RegisterSpec newReg) {
    for (SsaInsn use : ssaMeth.getUseListForRegister(origReg.getReg())) {
        RegisterSpec localAssignment = use.getLocalAssignment();
        if (localAssignment == null) {
            continue;
        }

        if (use.getResult() == null) {
            /*
             * This is a mark-local. it will be updated when all uses
             * are updated.
             */
            continue;
        }

        LocalItem local = localAssignment.getLocalItem();

        // Un-associate original use.
        use.setResultLocal(null);

        // Now add a mark-local to the new reg immediately after.
        newReg = newReg.withLocalItem(local);

        SsaInsn newInsn
                = SsaInsn.makeFromRop(
                    new PlainInsn(Rops.opMarkLocal(newReg),
                    SourcePosition.NO_INFO, null,
                            RegisterSpecList.make(newReg)),
                use.getBlock());

        ArrayList<SsaInsn> insns = use.getBlock().getInsns();

        insns.add(insns.indexOf(use) + 1, newInsn);
    }
}
 
Example #21
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 #22
Source File: FirstFitLocalCombiningAllocator.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a local item associated with an ssa register, if one exists.
 *
 * @param ssaReg {@code >= 0;} SSA register
 * @return {@code null-ok;} associated local item or null
 */
private LocalItem getLocalItemForReg(int ssaReg) {
    for (Map.Entry<LocalItem, ArrayList<RegisterSpec>> entry :
             localVariables.entrySet()) {
        for (RegisterSpec spec : entry.getValue()) {
            if (spec.getReg() == ssaReg) {
                return entry.getKey();
            }
        }
    }

    return null;
}
 
Example #23
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 #24
Source File: SsaRenamer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a local variable item for a specified register.
 *
 * @param ssaReg register in SSA name space
 * @return {@code null-ok;} Local variable name or null if none
 */
private LocalItem getLocalForNewReg(int ssaReg) {
    if (ssaReg < ssaRegToLocalItems.size()) {
        return ssaRegToLocalItems.get(ssaReg);
    } else {
        return null;
    }
}
 
Example #25
Source File: SsaRenamer.java    From Box with Apache License 2.0 5 votes vote down vote up
/**
 * Records a debug (local variable) name for a specified register.
 *
 * @param ssaReg non-null named register spec in SSA name space
 */
private void setNameForSsaReg(RegisterSpec ssaReg) {
    int reg = ssaReg.getReg();
    LocalItem local = ssaReg.getLocalItem();

    ssaRegToLocalItems.ensureCapacity(reg + 1);
    while (ssaRegToLocalItems.size() <= reg) {
        ssaRegToLocalItems.add(null);
    }

    ssaRegToLocalItems.set(reg, local);
}
 
Example #26
Source File: ConstCollector.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts mark-locals if necessary when changing a register. If
 * the definition of {@code origReg} is associated with a local
 * variable, then insert a mark-local for {@code newReg} just below
 * it. We expect the definition of  {@code origReg} to ultimately
 * be removed by the dead code eliminator
 *
 * @param origReg {@code non-null;} original register
 * @param newReg {@code non-null;} new register that will replace
 * {@code origReg}
 */
private void fixLocalAssignment(RegisterSpec origReg,
        RegisterSpec newReg) {
    for (SsaInsn use : ssaMeth.getUseListForRegister(origReg.getReg())) {
        RegisterSpec localAssignment = use.getLocalAssignment();
        if (localAssignment == null) {
            continue;
        }

        if (use.getResult() == null) {
            /*
             * This is a mark-local. it will be updated when all uses
             * are updated.
             */
            continue;
        }

        LocalItem local = localAssignment.getLocalItem();

        // Un-associate original use.
        use.setResultLocal(null);

        // Now add a mark-local to the new reg immediately after.
        newReg = newReg.withLocalItem(local);

        SsaInsn newInsn
                = SsaInsn.makeFromRop(
                    new PlainInsn(Rops.opMarkLocal(newReg),
                    SourcePosition.NO_INFO, null,
                            RegisterSpecList.make(newReg)),
                use.getBlock());

        ArrayList<SsaInsn> insns = use.getBlock().getInsns();

        insns.add(insns.indexOf(use) + 1, newInsn);
    }
}
 
Example #27
Source File: OutputFinisher.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Helper for {@link #getAllConstants} which adds all the info for
 * a single {@code RegisterSpec}.
 *
 * @param result {@code non-null;} result set to add to
 * @param spec {@code null-ok;} register spec to add
 */
private static void addConstants(HashSet<Constant> result,
        RegisterSpec spec) {
    if (spec == null) {
        return;
    }

    LocalItem local = spec.getLocalItem();
    CstString name = local.getName();
    CstString signature = local.getSignature();
    Type type = spec.getType();

    if (type != Type.KNOWN_NULL) {
        result.add(CstType.intern(type));
    } else {
        /* If this a "known null", let's use "Object" because that's going to be the
         * resulting type in {@link LocalList.MakeState#filterSpec} */
        result.add(CstType.intern(Type.OBJECT));
    }

    if (name != null) {
        result.add(name);
    }

    if (signature != null) {
        result.add(signature);
    }
}
 
Example #28
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 #29
Source File: ConstCollector.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts mark-locals if necessary when changing a register. If
 * the definition of {@code origReg} is associated with a local
 * variable, then insert a mark-local for {@code newReg} just below
 * it. We expect the definition of  {@code origReg} to ultimately
 * be removed by the dead code eliminator
 *
 * @param origReg {@code non-null;} original register
 * @param newReg {@code non-null;} new register that will replace
 * {@code origReg}
 */
private void fixLocalAssignment(RegisterSpec origReg,
        RegisterSpec newReg) {
    for (SsaInsn use : ssaMeth.getUseListForRegister(origReg.getReg())) {
        RegisterSpec localAssignment = use.getLocalAssignment();
        if (localAssignment == null) {
            continue;
        }

        if (use.getResult() == null) {
            /*
             * This is a mark-local. it will be updated when all uses
             * are updated.
             */
            continue;
        }

        LocalItem local = localAssignment.getLocalItem();

        // Un-associate original use.
        use.setResultLocal(null);

        // Now add a mark-local to the new reg immediately after.
        newReg = newReg.withLocalItem(local);

        SsaInsn newInsn
                = SsaInsn.makeFromRop(
                    new PlainInsn(Rops.opMarkLocal(newReg),
                    SourcePosition.NO_INFO, null,
                            RegisterSpecList.make(newReg)),
                use.getBlock());

        ArrayList<SsaInsn> insns = use.getBlock().getInsns();

        insns.add(insns.indexOf(use) + 1, newInsn);
    }
}
 
Example #30
Source File: SsaInsn.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the local association for the result of this insn. This is
 * sometimes updated during the SsaRenamer process.
 *
 * @param local {@code null-ok;} new debug/local variable info
 */
public final void setResultLocal(LocalItem local) {
    LocalItem oldItem = result.getLocalItem();

    if (local != oldItem && (local == null
            || !local.equals(result.getLocalItem()))) {
        result = RegisterSpec.makeLocalOptional(
                result.getReg(), result.getType(), local);
    }
}