Search in sources :

Example 1 with ObjectCell

use of org.jikesrvm.compilers.opt.ssa.IndexPropagation.ObjectCell in project JikesRVM by JikesRVM.

the class LoadElimination method replaceLoads.

/**
 * Walk over each instruction.  If its a USE (load) of a heap
 * variable and the value is available, then replace the load
 * with a move from a register.
 * <p>
 * POSTCONDITION: sets up the mapping 'registers' from value number
 *                 to temporary register
 * @param ir the IR
 * @param available information on which values are available
 * @param registers a place to store information about temp registers
 * @return mapping from heap variables to value numbers
 */
static UseRecordSet replaceLoads(IR ir, DF_Solution available, HashMap<UseRecord, Register> registers) {
    UseRecordSet result = new UseRecordSet();
    SSADictionary ssa = ir.HIRInfo.dictionary;
    GlobalValueNumberState valueNumbers = ir.HIRInfo.valueNumbers;
    for (Enumeration<Instruction> e = ir.forwardInstrEnumerator(); e.hasMoreElements(); ) {
        Instruction s = e.nextElement();
        if (!GetField.conforms(s) && !GetStatic.conforms(s) && !ALoad.conforms(s)) {
            continue;
        }
        // this instruction is a USE of heap variable H.
        // get the lattice cell that holds the available indices
        // for this heap variable
        HeapOperand<?>[] H = ssa.getHeapUses(s);
        if (H == null) {
            // TODO: clean up HIR representation of these magics
            continue;
        }
        if (H.length != 1) {
            throw new OptimizingCompilerException("LoadElimination: load with wrong number of heap uses");
        }
        if (GetField.conforms(s) || GetStatic.conforms(s)) {
            int valueNumber = -1;
            if (GetField.conforms(s)) {
                Object address = GetField.getRef(s);
                valueNumber = valueNumbers.getValueNumber(address);
            } else {
                // for getStatic, always use the value number 0
                valueNumber = 0;
            }
            ObjectCell cell = (ObjectCell) available.lookup(H[0].getHeapVariable());
            if (cell == null) {
                // nothing available
                continue;
            }
            // .. if H{valueNumber} is available ...
            if (cell.contains(valueNumber)) {
                result.add(H[0].getHeapVariable(), valueNumber);
                TypeReference type = ResultCarrier.getResult(s).getType();
                Register r = findOrCreateRegister(H[0].getHeapType(), valueNumber, registers, ir.regpool, type);
                if (DEBUG) {
                    System.out.println("ELIMINATING LOAD " + s);
                }
                replaceLoadWithMove(r, s);
            }
        } else {
            // ALoad.conforms(s)
            Object array = ALoad.getArray(s);
            Object index = ALoad.getIndex(s);
            ArrayCell cell = (ArrayCell) available.lookup(H[0].getHeapVariable());
            if (cell == null) {
                // nothing available
                continue;
            }
            int v1 = valueNumbers.getValueNumber(array);
            int v2 = valueNumbers.getValueNumber(index);
            // .. if H{<v1,v2>} is available ...
            if (cell.contains(v1, v2)) {
                result.add(H[0].getHeapVariable(), v1, v2);
                TypeReference type = ALoad.getResult(s).getType();
                Register r = findOrCreateRegister(H[0].getHeapVariable().getHeapType(), v1, v2, registers, ir.regpool, type);
                if (DEBUG) {
                    System.out.println("ELIMINATING LOAD " + s);
                }
                replaceLoadWithMove(r, s);
            }
        }
    }
    return result;
}
Also used : ArrayCell(org.jikesrvm.compilers.opt.ssa.IndexPropagation.ArrayCell) ObjectCell(org.jikesrvm.compilers.opt.ssa.IndexPropagation.ObjectCell) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) Register(org.jikesrvm.compilers.opt.ir.Register) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 2 with ObjectCell

use of org.jikesrvm.compilers.opt.ssa.IndexPropagation.ObjectCell in project JikesRVM by JikesRVM.

the class IndexPropagationSystem method initializeLatticeCells.

/**
 * Initialize the lattice variables.
 */
@Override
protected void initializeLatticeCells() {
    // set the lattice cells that are exposed on entry to BOTTOM
    for (DF_LatticeCell c : cells.values()) {
        if (c instanceof ObjectCell) {
            ObjectCell c1 = (ObjectCell) c;
            HeapVariable<?> key = c1.getKey();
            if (key.isExposedOnEntry()) {
                c1.setBOTTOM();
            }
        } else {
            ArrayCell c1 = (ArrayCell) c;
            HeapVariable<?> key = c1.getKey();
            if (key.isExposedOnEntry()) {
                c1.setBOTTOM();
            }
        }
    }
}
Also used : ArrayCell(org.jikesrvm.compilers.opt.ssa.IndexPropagation.ArrayCell) DF_LatticeCell(org.jikesrvm.compilers.opt.dfsolver.DF_LatticeCell) ObjectCell(org.jikesrvm.compilers.opt.ssa.IndexPropagation.ObjectCell)

Example 3 with ObjectCell

use of org.jikesrvm.compilers.opt.ssa.IndexPropagation.ObjectCell in project JikesRVM by JikesRVM.

the class IndexPropagationSystem method makeCell.

/**
 * Create an DF_LatticeCell corresponding to an HeapVariable
 * @param o the heap variable
 * @return a new lattice cell corresponding to this heap variable
 */
@Override
protected DF_LatticeCell makeCell(Object o) {
    if (!(o instanceof HeapVariable)) {
        throw new OptimizingCompilerException("IndexPropagation:makeCell");
    }
    DF_LatticeCell result = null;
    Object heapType = ((HeapVariable<?>) o).getHeapType();
    if (heapType instanceof TypeReference) {
        result = new ArrayCell((HeapVariable<?>) o);
    } else {
        result = new ObjectCell((HeapVariable<?>) o);
    }
    return result;
}
Also used : ArrayCell(org.jikesrvm.compilers.opt.ssa.IndexPropagation.ArrayCell) DF_LatticeCell(org.jikesrvm.compilers.opt.dfsolver.DF_LatticeCell) ObjectCell(org.jikesrvm.compilers.opt.ssa.IndexPropagation.ObjectCell) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) TypeReference(org.jikesrvm.classloader.TypeReference)

Aggregations

ArrayCell (org.jikesrvm.compilers.opt.ssa.IndexPropagation.ArrayCell)3 ObjectCell (org.jikesrvm.compilers.opt.ssa.IndexPropagation.ObjectCell)3 TypeReference (org.jikesrvm.classloader.TypeReference)2 OptimizingCompilerException (org.jikesrvm.compilers.opt.OptimizingCompilerException)2 DF_LatticeCell (org.jikesrvm.compilers.opt.dfsolver.DF_LatticeCell)2 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)1 Register (org.jikesrvm.compilers.opt.ir.Register)1 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)1