Search in sources :

Example 61 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class LICM method simplify.

private boolean simplify(Instruction inst, BasicBlock block) {
    // no phi
    if (!Phi.conforms(inst))
        return false;
    // if (Phi.getNumberOfValues (inst) != 2) return false; // want exactly 2 inputs
    // VM.sysWriteln ("Simplify " + inst);
    Operand resOp = Phi.getResult(inst);
    if (!(resOp instanceof HeapOperand)) {
        // scalar phi
        return false;
    }
    int xidx = -1;
    Instruction x = null;
    for (int i = Phi.getNumberOfValues(inst) - 1; i >= 0; --i) {
        Instruction in = definingInstruction(Phi.getValue(inst, i));
        if (getOrigBlock(in) != getOrigBlock(inst) && dominator.dominates(getOrigBlock(in), getOrigBlock(inst))) {
            if (xidx != -1)
                return false;
            xidx = i;
            x = in;
        } else if (!dominator.dominates(getOrigBlock(inst), getOrigBlock(in))) {
            return false;
        }
    }
    if (x == null)
        return false;
    replaceUses(inst, (HeapOperand<?>) Phi.getValue(inst, xidx), Phi.getPred(inst, xidx), true);
    // Cast to generic HeapOperand
    @SuppressWarnings("unchecked") HeapOperand<Object> hop = (HeapOperand) resOp;
    if (hop.value.isExceptionHeapType())
        return false;
    /* check that inside the loop, the heap variable is only used/defed
       by simple, non-volatile loads or only by stores

       if so, replace uses of inst (a memory phi) with its dominating input
    */
    int type = checkLoop(inst, hop, xidx, block);
    if (type == CL_LOADS_ONLY || type == CL_STORES_ONLY || type == CL_NONE) {
        replaceUses(inst, (HeapOperand<?>) Phi.getValue(inst, xidx), Phi.getPred(inst, xidx), false);
    }
    return false;
}
Also used : HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) BasicBlockOperand(org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand) HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 62 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class LeaveSSA method unSSAGuardsDetermineReg.

/**
 * Determine target register for guard phi operands
 *
 * @param ir the governing IR, currently in SSA form
 */
private void unSSAGuardsDetermineReg(IR ir) {
    Instruction inst = guardPhis;
    while (inst != null) {
        Register r = Phi.getResult(inst).asRegister().getRegister();
        int values = Phi.getNumberOfValues(inst);
        for (int i = 0; i < values; ++i) {
            Operand op = Phi.getValue(inst, i);
            if (op instanceof RegisterOperand) {
                guardUnion(op.asRegister().getRegister(), r);
            } else {
                if (VM.VerifyAssertions) {
                    VM._assert(op instanceof TrueGuardOperand || op instanceof UnreachableOperand);
                }
            }
        }
        inst = inst2guardPhi.get(inst);
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Register(org.jikesrvm.compilers.opt.ir.Register) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)

Example 63 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class LeaveSSA method performRename.

// substitute variables renamed in control parents
private void performRename(BasicBlock bb, DominatorTree dom, VariableStacks s) {
    if (DEBUG)
        VM.sysWriteln("performRename: " + bb);
    Enumeration<Instruction> e = bb.forwardRealInstrEnumerator();
    while (e.hasMoreElements()) {
        Instruction i = e.nextElement();
        Enumeration<Operand> ee = i.getUses();
        while (ee.hasMoreElements()) {
            Operand o = ee.nextElement();
            if (o instanceof RegisterOperand) {
                Register r1 = ((RegisterOperand) o).getRegister();
                if (r1.isValidation())
                    continue;
                Operand r2 = s.peek(r1);
                if (r2 != null) {
                    if (DEBUG) {
                        VM.sysWriteln("replace operand in " + i + "(" + r2 + " for " + o);
                    }
                    i.replaceOperand(o, r2.copy());
                }
            }
        }
    }
    // record renamings required in children
    e = bb.forwardRealInstrEnumerator();
    while (e.hasMoreElements()) {
        Instruction i = e.nextElement();
        if (globalRenameTable.contains(i)) {
            Register original = Move.getVal(i).asRegister().getRegister();
            RegisterOperand rename = Move.getResult(i);
            if (DEBUG)
                VM.sysWriteln("record rename " + rename + " for " + original);
            s.push(original, rename);
        }
    }
    // insert copies in control children
    Enumeration<TreeNode> children = dom.getChildren(bb);
    while (children.hasMoreElements()) {
        BasicBlock c = ((DominatorTreeNode) children.nextElement()).getBlock();
        performRename(c, dom, s);
    }
    // pop renamings from this block off stack
    e = bb.forwardRealInstrEnumerator();
    while (e.hasMoreElements()) {
        Instruction i = e.nextElement();
        if (globalRenameTable.contains(i)) {
            Register original = Move.getVal(i).asRegister().getRegister();
            s.pop(original);
        }
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Register(org.jikesrvm.compilers.opt.ir.Register) DominatorTreeNode(org.jikesrvm.compilers.opt.controlflow.DominatorTreeNode) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) TreeNode(org.jikesrvm.compilers.opt.util.TreeNode) DominatorTreeNode(org.jikesrvm.compilers.opt.controlflow.DominatorTreeNode) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 64 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class GenerationContextTest method buildLockObjectForStaticMethod.

private Operand buildLockObjectForStaticMethod(NormalMethod nm) {
    Class<?> klass = nm.getDeclaringClass().getClassForType();
    Offset offs = Offset.fromIntSignExtend(Statics.findOrCreateObjectLiteral(klass));
    Operand expectedLockObject = new ClassConstantOperand(klass, offs);
    return expectedLockObject;
}
Also used : ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) Offset(org.vmmagic.unboxed.Offset)

Example 65 with Operand

use of org.jikesrvm.compilers.opt.ir.operand.Operand in project JikesRVM by JikesRVM.

the class GenerationContextTest method assertThatRethrowBlockIsCorrect.

private void assertThatRethrowBlockIsCorrect(InlineSequence inlineSequence, Operand lockObject, ExceptionHandlerBasicBlock rethrow) {
    Enumeration<TypeOperand> exceptionTypes = rethrow.getExceptionTypes();
    TypeOperand firstHandledException = exceptionTypes.nextElement();
    assertThat(exceptionTypes.hasMoreElements(), is(false));
    assertTrue(firstHandledException.similar(new TypeOperand(RVMType.JavaLangThrowableType)));
    Enumeration<Instruction> rethrowInstructions = rethrow.forwardRealInstrEnumerator();
    Instruction firstInstructionInRethrow = rethrowInstructions.nextElement();
    assertThat(firstInstructionInRethrow.operator(), is(GET_CAUGHT_EXCEPTION));
    assertThat(firstInstructionInRethrow.getBytecodeIndex(), is(SYNTH_CATCH_BCI));
    assertTrue(firstInstructionInRethrow.position().equals(inlineSequence));
    RegisterOperand catchExceptionObject = Nullary.getResult(firstInstructionInRethrow);
    assertThat(catchExceptionObject.getType(), is(TypeReference.JavaLangThrowable));
    Instruction secondInstructionInRethrow = rethrowInstructions.nextElement();
    assertThatNoMoreInstructionsExist(rethrowInstructions);
    assertThat(secondInstructionInRethrow.operator(), is(CALL));
    MethodOperand methodOp = Call.getMethod(secondInstructionInRethrow);
    assertTrue(methodOp.getTarget().equals(Entrypoints.unlockAndThrowMethod));
    assertTrue(methodOp.isNonReturningCall());
    Operand callAddress = Call.getAddress(secondInstructionInRethrow);
    Address actualAddress = callAddress.asAddressConstant().value;
    Address expectedAddress = Entrypoints.unlockAndThrowMethod.getOffset().toWord().toAddress();
    assertTrue(actualAddress.EQ(expectedAddress));
    Operand lockObjectFromRethrow = Call.getParam(secondInstructionInRethrow, 0);
    assertTrue(lockObjectFromRethrow.similar(lockObject));
    RegisterOperand catchOperand = Call.getParam(secondInstructionInRethrow, 1).asRegister();
    assertTrue(catchOperand.sameRegisterPropertiesAs(catchExceptionObject));
    assertTrue(rethrow.mayThrowUncaughtException());
    assertTrue(rethrow.canThrowExceptions());
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Address(org.vmmagic.unboxed.Address) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand)

Aggregations

Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)355 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)328 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)242 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)217 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)212 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)210 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)207 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)185 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)174 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)165 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)153 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)144 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)143 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)141 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)128 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)121 UnreachableOperand (org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand)117 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)102 CodeConstantOperand (org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)98 Register (org.jikesrvm.compilers.opt.ir.Register)82