Search in sources :

Example 1 with Queue

use of org.jikesrvm.compilers.opt.util.Queue in project JikesRVM by JikesRVM.

the class CallingConvention method expandCallingConventions.

/**
 * Expands calling conventions to make physical registers explicit in the
 * IR when required for calls, returns, and the prologue.
 *
 * @param ir the governing IR
 */
public static void expandCallingConventions(IR ir) {
    Queue<Instruction> calls = new Queue<Instruction>();
    // occur because the newly copied syscalls would be processed, too.
    for (Instruction inst = ir.firstInstructionInCodeOrder(); inst != null; inst = inst.nextInstructionInCodeOrder()) {
        if (inst.isCall()) {
            calls.insert(inst);
        } else if (inst.isReturn()) {
            returnExpand(inst, ir);
        }
    }
    for (Instruction call : calls) {
        callExpand(call, ir);
    }
    // expand the prologue instruction
    expandPrologue(ir);
    if (VM.BuildFor64Addr && ir.stackManager.hasSysCall()) {
        // Recompute def-use data structures due to added blocks
        // for syscall expansion.
        DefUse.computeDU(ir);
        // Temporaries used for parameters might now be in two blocks.
        DefUse.recomputeSpansBasicBlock(ir);
        // The SSA property might be invalidated by two definitions
        // for a temporary used for a return value.
        DefUse.recomputeSSA(ir);
    }
}
Also used : Instruction(org.jikesrvm.compilers.opt.ir.Instruction) Queue(org.jikesrvm.compilers.opt.util.Queue)

Example 2 with Queue

use of org.jikesrvm.compilers.opt.util.Queue in project JikesRVM by JikesRVM.

the class LICM method checkLoop.

/*
   * TODO document xidx parameter and turn this comment into proper JavaDoc.
   * <p>
   * Checks that inside the loop, the heap variable is only used/defed
   * by simple, non-volatile loads/stores
   *
   * @param inst a phi instruction
   * @param hop the result operand of the phi instruction
   * @param xidx
   * @param block the block that contains the phi instruction
   *
   * @return one of {@link #CL_LOADS_ONLY}, {@link #CL_STORES_ONLY},
   * {@link #CL_LOADS_AND_STORES}, {@link #CL_COMPLEX}
   */
private int checkLoop(Instruction inst, HeapOperand<Object> hop, int xidx, BasicBlock block) {
    HashSet<Instruction> seen = new HashSet<Instruction>();
    Queue<Instruction> workList = new Queue<Instruction>();
    int _state = CL_NONE;
    int instUses = 0;
    seen.add(inst);
    for (int i = Phi.getNumberOfValues(inst) - 1; i >= 0; --i) {
        if (i == xidx)
            continue;
        Instruction y = definingInstruction(Phi.getValue(inst, i));
        if (y == inst)
            instUses++;
        if (!(seen.contains(y))) {
            seen.add(y);
            workList.insert(y);
        }
    }
    while (!(workList.isEmpty())) {
        Instruction y = workList.remove();
        if (Phi.conforms(y)) {
            for (int i = Phi.getNumberOfValues(y) - 1; i >= 0; --i) {
                Instruction z = definingInstruction(Phi.getValue(y, i));
                if (z == inst)
                    instUses++;
                if (!(seen.contains(z))) {
                    seen.add(z);
                    workList.insert(z);
                }
            }
        } else if ((y.isPEI()) || !LocationCarrier.conforms(y) || y.operator().isAcquire() || y.operator().isRelease()) {
            return CL_COMPLEX;
        } else {
            // check for access to volatile field
            LocationOperand loc = LocationCarrier.getLocation(y);
            if (loc == null || loc.mayBeVolatile()) {
                // VM.sysWriteln (" no loc or volatile field");
                return CL_COMPLEX;
            }
            if (y.isImplicitStore()) {
                // conservatively estimate loop-invariance by header domination
                if (!inVariantLocation(y, block))
                    return CL_COMPLEX;
                _state |= CL_STORES_ONLY;
            } else {
                _state |= CL_LOADS_ONLY;
            }
            for (HeapOperand<?> op : ssad.getHeapUses(y)) {
                if (op.value.isExceptionHeapType())
                    continue;
                if (op.getHeapType() != hop.getHeapType())
                    return CL_COMPLEX;
                y = definingInstruction(op);
                if (y == inst)
                    instUses++;
                if (!(seen.contains(y))) {
                    seen.add(y);
                    workList.insert(y);
                }
            }
        }
    }
    if (_state == CL_STORES_ONLY && ssad.getNumberOfUses(hop.value) != instUses) {
        return CL_COMPLEX;
    }
    return _state;
}
Also used : HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) Queue(org.jikesrvm.compilers.opt.util.Queue) HashSet(java.util.HashSet)

Aggregations

Instruction (org.jikesrvm.compilers.opt.ir.Instruction)2 Queue (org.jikesrvm.compilers.opt.util.Queue)2 HashSet (java.util.HashSet)1 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)1 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)1