Java Code Examples for com.android.dx.rop.code.RegisterSpec#withType()

The following examples show how to use com.android.dx.rop.code.RegisterSpec#withType() . 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: SCCP.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces TypeBearers in source register specs with constant type
 * bearers if possible. These are then referenced in later optimization
 * steps.
 */
private void replaceConstants() {
    for (int reg = 0; reg < regCount; reg++) {
        if (latticeValues[reg] != CONSTANT) {
            continue;
        }
        if (!(latticeConstants[reg] instanceof TypedConstant)) {
            // We can't do much with these
            continue;
        }

        SsaInsn defn = ssaMeth.getDefinitionForRegister(reg);
        TypeBearer typeBearer = defn.getResult().getTypeBearer();

        if (typeBearer.isConstant()) {
            /*
             * The definition was a constant already.
             * The uses should be as well.
             */
            continue;
        }

        // Update the destination RegisterSpec with the constant value
        RegisterSpec dest = defn.getResult();
        RegisterSpec newDest
                = dest.withType((TypedConstant)latticeConstants[reg]);
        defn.setResult(newDest);

        /*
         * Update the sources RegisterSpec's of all non-move uses.
         * These will be used in later steps.
         */
        for (SsaInsn insn : ssaMeth.getUseListForRegister(reg)) {
            if (insn.isPhiOrMove()) {
                continue;
            }

            NormalSsaInsn nInsn = (NormalSsaInsn) insn;
            RegisterSpecList sources = insn.getSources();

            int index = sources.indexOfRegister(reg);

            RegisterSpec spec = sources.get(index);
            RegisterSpec newSpec
                    = spec.withType((TypedConstant)latticeConstants[reg]);

            nInsn.changeOneSource(index, newSpec);
        }
    }
}
 
Example 2
Source File: SCCP.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces TypeBearers in source register specs with constant type
 * bearers if possible. These are then referenced in later optimization
 * steps.
 */
private void replaceConstants() {
    for (int reg = 0; reg < regCount; reg++) {
        if (latticeValues[reg] != CONSTANT) {
            continue;
        }
        if (!(latticeConstants[reg] instanceof TypedConstant)) {
            // We can't do much with these
            continue;
        }

        SsaInsn defn = ssaMeth.getDefinitionForRegister(reg);
        TypeBearer typeBearer = defn.getResult().getTypeBearer();

        if (typeBearer.isConstant()) {
            /*
             * The definition was a constant already.
             * The uses should be as well.
             */
            continue;
        }

        // Update the destination RegisterSpec with the constant value
        RegisterSpec dest = defn.getResult();
        RegisterSpec newDest
                = dest.withType((TypedConstant)latticeConstants[reg]);
        defn.setResult(newDest);

        /*
         * Update the sources RegisterSpec's of all non-move uses.
         * These will be used in later steps.
         */
        for (SsaInsn insn : ssaMeth.getUseListForRegister(reg)) {
            if (insn.isPhiOrMove()) {
                continue;
            }

            NormalSsaInsn nInsn = (NormalSsaInsn) insn;
            RegisterSpecList sources = insn.getSources();

            int index = sources.indexOfRegister(reg);

            RegisterSpec spec = sources.get(index);
            RegisterSpec newSpec
                    = spec.withType((TypedConstant)latticeConstants[reg]);

            nInsn.changeOneSource(index, newSpec);
        }
    }
}
 
Example 3
Source File: SCCP.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces TypeBearers in source register specs with constant type
 * bearers if possible. These are then referenced in later optimization
 * steps.
 */
private void replaceConstants() {
    for (int reg = 0; reg < regCount; reg++) {
        if (latticeValues[reg] != CONSTANT) {
            continue;
        }
        if (!(latticeConstants[reg] instanceof TypedConstant)) {
            // We can't do much with these
            continue;
        }

        SsaInsn defn = ssaMeth.getDefinitionForRegister(reg);
        TypeBearer typeBearer = defn.getResult().getTypeBearer();

        if (typeBearer.isConstant()) {
            /*
             * The definition was a constant already.
             * The uses should be as well.
             */
            continue;
        }

        // Update the destination RegisterSpec with the constant value
        RegisterSpec dest = defn.getResult();
        RegisterSpec newDest
                = dest.withType((TypedConstant)latticeConstants[reg]);
        defn.setResult(newDest);

        /*
         * Update the sources RegisterSpec's of all non-move uses.
         * These will be used in later steps.
         */
        for (SsaInsn insn : ssaMeth.getUseListForRegister(reg)) {
            if (insn.isPhiOrMove()) {
                continue;
            }

            NormalSsaInsn nInsn = (NormalSsaInsn) insn;
            RegisterSpecList sources = insn.getSources();

            int index = sources.indexOfRegister(reg);

            RegisterSpec spec = sources.get(index);
            RegisterSpec newSpec
                    = spec.withType((TypedConstant)latticeConstants[reg]);

            nInsn.changeOneSource(index, newSpec);
        }
    }
}
 
Example 4
Source File: SCCP.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces TypeBearers in source register specs with constant type
 * bearers if possible. These are then referenced in later optimization
 * steps.
 */
private void replaceConstants() {
    for (int reg = 0; reg < regCount; reg++) {
        if (latticeValues[reg] != CONSTANT) {
            continue;
        }
        if (!(latticeConstants[reg] instanceof TypedConstant)) {
            // We can't do much with these
            continue;
        }

        SsaInsn defn = ssaMeth.getDefinitionForRegister(reg);
        TypeBearer typeBearer = defn.getResult().getTypeBearer();

        if (typeBearer.isConstant()) {
            /*
             * The definition was a constant already.
             * The uses should be as well.
             */
            continue;
        }

        // Update the destination RegisterSpec with the constant value
        RegisterSpec dest = defn.getResult();
        RegisterSpec newDest
                = dest.withType((TypedConstant)latticeConstants[reg]);
        defn.setResult(newDest);

        /*
         * Update the sources RegisterSpec's of all non-move uses.
         * These will be used in later steps.
         */
        for (SsaInsn insn : ssaMeth.getUseListForRegister(reg)) {
            if (insn.isPhiOrMove()) {
                continue;
            }

            NormalSsaInsn nInsn = (NormalSsaInsn) insn;
            RegisterSpecList sources = insn.getSources();

            int index = sources.indexOfRegister(reg);

            RegisterSpec spec = sources.get(index);
            RegisterSpec newSpec
                    = spec.withType((TypedConstant)latticeConstants[reg]);

            nInsn.changeOneSource(index, newSpec);
        }
    }
}
 
Example 5
Source File: LocalList.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a given spec into the form acceptable for use in a
 * local list. This, in particular, transforms the "known
 * null" type into simply {@code Object}. This method needs to
 * be called for any spec that is on its way into a locals
 * list.
 *
 * <p>This isn't necessarily the cleanest way to achieve the
 * goal of not representing known nulls in a locals list, but
 * it gets the job done.</p>
 *
 * @param orig {@code null-ok;} the original spec
 * @return {@code null-ok;} an appropriately modified spec, or the
 * original if nothing needs to be done
 */
private static RegisterSpec filterSpec(RegisterSpec orig) {
    if ((orig != null) && (orig.getType() == Type.KNOWN_NULL)) {
        return orig.withType(Type.OBJECT);
    }

    return orig;
}
 
Example 6
Source File: LocalList.java    From Box with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a given spec into the form acceptable for use in a
 * local list. This, in particular, transforms the "known
 * null" type into simply {@code Object}. This method needs to
 * be called for any spec that is on its way into a locals
 * list.
 *
 * <p>This isn't necessarily the cleanest way to achieve the
 * goal of not representing known nulls in a locals list, but
 * it gets the job done.</p>
 *
 * @param orig {@code null-ok;} the original spec
 * @return {@code null-ok;} an appropriately modified spec, or the
 * original if nothing needs to be done
 */
private static RegisterSpec filterSpec(RegisterSpec orig) {
    if ((orig != null) && (orig.getType() == Type.KNOWN_NULL)) {
        return orig.withType(Type.OBJECT);
    }

    return orig;
}
 
Example 7
Source File: LocalList.java    From J2ME-Loader with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a given spec into the form acceptable for use in a
 * local list. This, in particular, transforms the "known
 * null" type into simply {@code Object}. This method needs to
 * be called for any spec that is on its way into a locals
 * list.
 *
 * <p>This isn't necessarily the cleanest way to achieve the
 * goal of not representing known nulls in a locals list, but
 * it gets the job done.</p>
 *
 * @param orig {@code null-ok;} the original spec
 * @return {@code null-ok;} an appropriately modified spec, or the
 * original if nothing needs to be done
 */
private static RegisterSpec filterSpec(RegisterSpec orig) {
    if ((orig != null) && (orig.getType() == Type.KNOWN_NULL)) {
        return orig.withType(Type.OBJECT);
    }

    return orig;
}
 
Example 8
Source File: LocalList.java    From buck with Apache License 2.0 3 votes vote down vote up
/**
 * Converts a given spec into the form acceptable for use in a
 * local list. This, in particular, transforms the "known
 * null" type into simply {@code Object}. This method needs to
 * be called for any spec that is on its way into a locals
 * list.
 *
 * <p>This isn't necessarily the cleanest way to achieve the
 * goal of not representing known nulls in a locals list, but
 * it gets the job done.</p>
 *
 * @param orig {@code null-ok;} the original spec
 * @return {@code null-ok;} an appropriately modified spec, or the
 * original if nothing needs to be done
 */
private static RegisterSpec filterSpec(RegisterSpec orig) {
    if ((orig != null) && (orig.getType() == Type.KNOWN_NULL)) {
        return orig.withType(Type.OBJECT);
    }

    return orig;
}