Search in sources :

Example 1 with UnreachableOperand

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

the class EnterSSA method removeUnreachableOperands.

@SuppressWarnings("unused")
private void removeUnreachableOperands(HashSet<Instruction> scalarPhis) {
    for (Instruction phi : scalarPhis) {
        boolean didSomething = true;
        while (didSomething) {
            didSomething = false;
            for (int j = 0; j < Phi.getNumberOfValues(phi); j++) {
                Operand v = Phi.getValue(phi, j);
                if (v instanceof UnreachableOperand) {
                    // rewrite the phi instruction to remove the unreachable
                    // operand
                    didSomething = true;
                    Instruction tmpPhi = phi.copyWithoutLinks();
                    Phi.mutate(phi, PHI, Phi.getResult(tmpPhi), Phi.getNumberOfValues(phi) - 1);
                    int m = 0;
                    for (int k = 0; k < Phi.getNumberOfValues(phi); k++) {
                        if (k == j)
                            continue;
                        Phi.setValue(phi, m, Phi.getValue(tmpPhi, k));
                        Phi.setPred(phi, m, Phi.getPred(tmpPhi, k));
                        m++;
                    }
                }
            }
        }
    }
}
Also used : UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) BasicBlockOperand(org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 2 with UnreachableOperand

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

the class EnterSSA method meetPhiType.

/**
 * Return the meet of the types on the rhs of a phi instruction
 *
 * @param s phi instruction
 * @param phiTypes TODO
 * @return the meet of the types
 */
private static TypeReference meetPhiType(Instruction s, Map<Instruction, PhiTypeInformation> phiTypes) {
    TypeReference result = null;
    for (int i = 0; i < Phi.getNumberOfValues(s); i++) {
        Operand val = Phi.getValue(s, i);
        if (val instanceof UnreachableOperand)
            continue;
        TypeReference t = val.getType();
        if (t == null) {
            phiTypes.put(s, PhiTypeInformation.FOUND_NULL_TYPE);
        } else if (result == null) {
            result = t;
        } else {
            TypeReference meet = ClassLoaderProxy.findCommonSuperclass(result, t);
            if (meet == null) {
                // TODO: This horrific kludge should go away once we get rid of Address.toInt()
                if ((result.isIntLikeType() && (t.isReferenceType() || t.isWordLikeType())) || ((result.isReferenceType() || result.isWordLikeType()) && t.isIntLikeType())) {
                    meet = TypeReference.Int;
                } else if (result.isReferenceType() && t.isWordLikeType()) {
                    meet = t;
                } else if (result.isWordLikeType() && t.isReferenceType()) {
                    meet = result;
                }
            }
            if (VM.VerifyAssertions && meet == null) {
                String msg = result + " and " + t + " meet to null";
                VM._assert(VM.NOT_REACHED, msg);
            }
            result = meet;
        }
    }
    return result;
}
Also used : UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) BasicBlockOperand(org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) TypeReference(org.jikesrvm.classloader.TypeReference)

Example 3 with UnreachableOperand

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

the class ValueGraph method findOrCreateVertex.

/**
 * Find or create an ValueGraphVertex corresponding to a
 * given constant operand
 *
 * @param op the constant operand
 * @return a value graph vertex corresponding to this variable
 */
private ValueGraphVertex findOrCreateVertex(ConstantOperand op) {
    Object name;
    if (op.isAddressConstant()) {
        name = (VM.BuildFor32Addr) ? op.asAddressConstant().value.toInt() : op.asAddressConstant().value.toLong();
    } else if (op.isIntConstant()) {
        name = op.asIntConstant().value;
    } else if (op.isFloatConstant()) {
        name = op.asFloatConstant().value;
    } else if (op.isLongConstant()) {
        name = op.asLongConstant().value;
    } else if (op.isDoubleConstant()) {
        name = op.asDoubleConstant().value;
    } else if (op instanceof ObjectConstantOperand) {
        name = op.asObjectConstant().value;
    } else if (op instanceof TIBConstantOperand) {
        name = op.asTIBConstant().value;
    } else if (op.isNullConstant()) {
        name = op;
    } else if (op instanceof TrueGuardOperand) {
        name = op;
    } else if (op instanceof UnreachableOperand) {
        name = op;
    } else {
        throw new OptimizingCompilerException("ValueGraph.findOrCreateVertex: unexpected constant operand: " + op);
    }
    ValueGraphVertex v = getVertex(name);
    if (v == null) {
        v = new ValueGraphVertex(op);
        v.setLabel(op, 0);
        graph.addGraphNode(v);
        nameMap.put(name, v);
    }
    return v;
}
Also used : ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)

Example 4 with UnreachableOperand

use of org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand 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 5 with UnreachableOperand

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

the class Simplifier method getField.

private static DefUseEffect getField(Instruction s, OptOptions opts) {
    if (opts.SIMPLIFY_FIELD_OPS) {
        Operand ref = GetField.getRef(s);
        if (VM.VerifyAssertions && ref.isNullConstant()) {
            // Simplify to an unreachable operand, this instruction is dead code
            // guarded by a nullcheck that should already have been simplified
            RegisterOperand result = GetField.getClearResult(s);
            Move.mutate(s, IRTools.getMoveOp(result.getType()), result, new UnreachableOperand());
            return DefUseEffect.MOVE_FOLDED;
        } else if (opts.SIMPLIFY_CHASE_FINAL_FIELDS && ref.isObjectConstant()) {
            // A constant object references this field which is
            // final. As the reference is final the constructor
            // of the referred object MUST have already completed.
            // This also implies that the type MUST have been resolved.
            RVMField field = GetField.getLocation(s).getFieldRef().resolve();
            if (field.isFinal() && field.getDeclaringClass().isInitialized()) {
                try {
                    ConstantOperand op = StaticFieldReader.getFieldValueAsConstant(field, ref.asObjectConstant().value);
                    Move.mutate(s, IRTools.getMoveOp(field.getType()), GetField.getClearResult(s), op);
                    return DefUseEffect.MOVE_FOLDED;
                } catch (NoSuchFieldException e) {
                    if (VM.runningVM) {
                        // this is unexpected
                        throw new Error("Unexpected exception", e);
                    } else {
                    // Field not found during bootstrap due to chasing a field
                    // only valid in the bootstrap JVM
                    }
                }
            }
        }
    }
    return DefUseEffect.UNCHANGED;
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) TypeOperand(org.jikesrvm.compilers.opt.ir.operand.TypeOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) UnreachableOperand(org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand) RVMField(org.jikesrvm.classloader.RVMField)

Aggregations

UnreachableOperand (org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand)10 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)9 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)9 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)7 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)6 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)6 Register (org.jikesrvm.compilers.opt.ir.Register)5 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)4 TypeReference (org.jikesrvm.classloader.TypeReference)3 BasicBlockOperand (org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand)3 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)3 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)3 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)3 HashMap (java.util.HashMap)2 OptimizingCompilerException (org.jikesrvm.compilers.opt.OptimizingCompilerException)2 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)2 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)2 CodeConstantOperand (org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)2 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)2 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)2