Java Code Examples for com.android.dx.rop.code.RegisterSpecList#indexOfRegister()

The following examples show how to use com.android.dx.rop.code.RegisterSpecList#indexOfRegister() . 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: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Maps the source registers of the specified instruction such that they
 * will fall in a contiguous range in rop form. Moves are inserted as
 * necessary to allow the range to be allocated.
 *
 * @param insn {@code non-null;} insn whos sources to process
 */
private void adjustAndMapSourceRangeRange(NormalSsaInsn insn) {
    int newRegStart = findRangeAndAdjust(insn);

    RegisterSpecList sources = insn.getSources();
    int szSources = sources.size();
    int nextRopReg = newRegStart;

    for (int i = 0; i < szSources; i++) {
        RegisterSpec source = sources.get(i);
        int sourceReg = source.getReg();
        int category = source.getCategory();
        int curRopReg = nextRopReg;
        nextRopReg += category;

        if (ssaRegsMapped.get(sourceReg)) {
            continue;
        }

        LocalItem localItem = getLocalItemForReg(sourceReg);
        addMapping(source, curRopReg);

        if (localItem != null) {
            markReserved(curRopReg, category);
            ArrayList<RegisterSpec> similarRegisters
                    = localVariables.get(localItem);

            int szSimilar = similarRegisters.size();

            /*
             * Try to map all SSA registers also associated with
             * this local.
             */
            for (int j = 0; j < szSimilar; j++) {
                RegisterSpec similarSpec = similarRegisters.get(j);
                int similarReg = similarSpec.getReg();

                // Don't map anything that's also a source.
                if (-1 != sources.indexOfRegister(similarReg)) {
                    continue;
                }

                // Registers left unmapped will get handled later.
                tryMapReg(similarSpec, curRopReg, category);
            }
        }
    }
}
 
Example 3
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 4
Source File: FirstFitLocalCombiningAllocator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Maps the source registers of the specified instruction such that they
 * will fall in a contiguous range in rop form. Moves are inserted as
 * necessary to allow the range to be allocated.
 *
 * @param insn {@code non-null;} insn whos sources to process
 */
private void adjustAndMapSourceRangeRange(NormalSsaInsn insn) {
    int newRegStart = findRangeAndAdjust(insn);

    RegisterSpecList sources = insn.getSources();
    int szSources = sources.size();
    int nextRopReg = newRegStart;

    for (int i = 0; i < szSources; i++) {
        RegisterSpec source = sources.get(i);
        int sourceReg = source.getReg();
        int category = source.getCategory();
        int curRopReg = nextRopReg;
        nextRopReg += category;

        if (ssaRegsMapped.get(sourceReg)) {
            continue;
        }

        LocalItem localItem = getLocalItemForReg(sourceReg);
        addMapping(source, curRopReg);

        if (localItem != null) {
            markReserved(curRopReg, category);
            ArrayList<RegisterSpec> similarRegisters
                    = localVariables.get(localItem);

            int szSimilar = similarRegisters.size();

            /*
             * Try to map all SSA registers also associated with
             * this local.
             */
            for (int j = 0; j < szSimilar; j++) {
                RegisterSpec similarSpec = similarRegisters.get(j);
                int similarReg = similarSpec.getReg();

                // Don't map anything that's also a source.
                if (-1 != sources.indexOfRegister(similarReg)) {
                    continue;
                }

                // Registers left unmapped will get handled later.
                tryMapReg(similarSpec, curRopReg, category);
            }
        }
    }
}
 
Example 5
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 6
Source File: FirstFitLocalCombiningAllocator.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Maps the source registers of the specified instruction such that they
 * will fall in a contiguous range in rop form. Moves are inserted as
 * necessary to allow the range to be allocated.
 *
 * @param insn {@code non-null;} insn whos sources to process
 */
private void adjustAndMapSourceRangeRange(NormalSsaInsn insn) {
    int newRegStart = findRangeAndAdjust(insn);

    RegisterSpecList sources = insn.getSources();
    int szSources = sources.size();
    int nextRopReg = newRegStart;

    for (int i = 0; i < szSources; i++) {
        RegisterSpec source = sources.get(i);
        int sourceReg = source.getReg();
        int category = source.getCategory();
        int curRopReg = nextRopReg;
        nextRopReg += category;

        if (ssaRegsMapped.get(sourceReg)) {
            continue;
        }

        LocalItem localItem = getLocalItemForReg(sourceReg);
        addMapping(source, curRopReg);

        if (localItem != null) {
            markReserved(curRopReg, category);
            ArrayList<RegisterSpec> similarRegisters
                    = localVariables.get(localItem);

            int szSimilar = similarRegisters.size();

            /*
             * Try to map all SSA registers also associated with
             * this local.
             */
            for (int j = 0; j < szSimilar; j++) {
                RegisterSpec similarSpec = similarRegisters.get(j);
                int similarReg = similarSpec.getReg();

                // Don't map anything that's also a source.
                if (-1 != sources.indexOfRegister(similarReg)) {
                    continue;
                }

                // Registers left unmapped will get handled later.
                tryMapReg(similarSpec, curRopReg, category);
            }
        }
    }
}
 
Example 7
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 8
Source File: FirstFitLocalCombiningAllocator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Maps the source registers of the specified instruction such that they
 * will fall in a contiguous range in rop form. Moves are inserted as
 * necessary to allow the range to be allocated.
 *
 * @param insn {@code non-null;} insn whos sources to process
 */
private void adjustAndMapSourceRangeRange(NormalSsaInsn insn) {
    int newRegStart = findRangeAndAdjust(insn);

    RegisterSpecList sources = insn.getSources();
    int szSources = sources.size();
    int nextRopReg = newRegStart;

    for (int i = 0; i < szSources; i++) {
        RegisterSpec source = sources.get(i);
        int sourceReg = source.getReg();
        int category = source.getCategory();
        int curRopReg = nextRopReg;
        nextRopReg += category;

        if (ssaRegsMapped.get(sourceReg)) {
            continue;
        }

        LocalItem localItem = getLocalItemForReg(sourceReg);
        addMapping(source, curRopReg);

        if (localItem != null) {
            markReserved(curRopReg, category);
            ArrayList<RegisterSpec> similarRegisters
                    = localVariables.get(localItem);

            int szSimilar = similarRegisters.size();

            /*
             * Try to map all SSA registers also associated with
             * this local.
             */
            for (int j = 0; j < szSimilar; j++) {
                RegisterSpec similarSpec = similarRegisters.get(j);
                int similarReg = similarSpec.getReg();

                // Don't map anything that's also a source.
                if (-1 != sources.indexOfRegister(similarReg)) {
                    continue;
                }

                // Registers left unmapped will get handled later.
                tryMapReg(similarSpec, curRopReg, category);
            }
        }
    }
}