Search in sources :

Example 11 with TIBConstantOperand

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

the class NormalizeConstants method perform.

/**
 * Only thing we do for IA32 is to restrict the usage of
 * String, Float, and Double constants.  The rules are prepared
 * to deal with everything else.
 *
 * @param ir IR to normalize
 */
public static void perform(IR ir) {
    for (Instruction s = ir.firstInstructionInCodeOrder(); s != null; s = s.nextInstructionInCodeOrder()) {
        // Get 'large' constants into a form the the BURS rules are
        // prepared to deal with.
        // Constants can't appear as defs, so only scan the uses.
        // 
        int numUses = s.getNumberOfUses();
        if (numUses > 0) {
            int numDefs = s.getNumberOfDefs();
            for (int idx = numDefs; idx < numUses + numDefs; idx++) {
                Operand use = s.getOperand(idx);
                if (use != null) {
                    if (use instanceof ObjectConstantOperand) {
                        ObjectConstantOperand oc = (ObjectConstantOperand) use;
                        if (oc.isMovableObjectConstant()) {
                            RegisterOperand rop = ir.regpool.makeTemp(use.getType());
                            Operand jtoc = ir.regpool.makeJTOCOp();
                            Offset offset = oc.offset;
                            if (offset.isZero()) {
                                if (use instanceof StringConstantOperand) {
                                    throw new OptimizingCompilerException("String constant w/o valid JTOC offset");
                                } else if (use instanceof ClassConstantOperand) {
                                    throw new OptimizingCompilerException("Class constant w/o valid JTOC offset");
                                }
                                offset = Offset.fromIntSignExtend(Statics.findOrCreateObjectLiteral(oc.value));
                            }
                            LocationOperand loc = new LocationOperand(offset);
                            s.insertBefore(Load.create(IA32_REF_LOAD, rop, jtoc, wordOperandForReference(offset.toWord()), loc));
                            s.putOperand(idx, rop.copyD2U());
                        } else {
                            // Ensure object is in JTOC to keep it alive
                            Statics.findOrCreateObjectLiteral(oc.value);
                            s.putOperand(idx, wordOperandForReference(Magic.objectAsAddress(oc.value).toWord()));
                        }
                    } else if (use instanceof DoubleConstantOperand) {
                        RegisterOperand rop = ir.regpool.makeTemp(TypeReference.Double);
                        Operand jtoc = ir.regpool.makeJTOCOp();
                        DoubleConstantOperand dc = (DoubleConstantOperand) use.copy();
                        if (dc.offset.isZero()) {
                            dc.offset = Offset.fromIntSignExtend(Statics.findOrCreateLongSizeLiteral(Double.doubleToLongBits(dc.value)));
                        }
                        s.insertBefore(Binary.create(MATERIALIZE_FP_CONSTANT, rop, jtoc, dc));
                        s.putOperand(idx, rop.copyD2U());
                    } else if (use instanceof FloatConstantOperand) {
                        RegisterOperand rop = ir.regpool.makeTemp(TypeReference.Float);
                        Operand jtoc = ir.regpool.makeJTOCOp();
                        FloatConstantOperand fc = (FloatConstantOperand) use.copy();
                        if (fc.offset.isZero()) {
                            fc.offset = Offset.fromIntSignExtend(Statics.findOrCreateIntSizeLiteral(Float.floatToIntBits(fc.value)));
                        }
                        s.insertBefore(Binary.create(MATERIALIZE_FP_CONSTANT, rop, jtoc, fc));
                        s.putOperand(idx, rop.copyD2U());
                    } else if (use instanceof NullConstantOperand) {
                        s.putOperand(idx, wordOperandForReference(Word.zero()));
                    } else if (use instanceof AddressConstantOperand) {
                        s.putOperand(idx, wordOperandForReference(((AddressConstantOperand) use).value.toWord()));
                    } else if (use instanceof TIBConstantOperand) {
                        RegisterOperand rop = ir.regpool.makeTemp(TypeReference.TIB);
                        Operand jtoc = ir.regpool.makeJTOCOp();
                        Offset offset = ((TIBConstantOperand) use).value.getTibOffset();
                        LocationOperand loc = new LocationOperand(offset);
                        s.insertBefore(Load.create(IA32_REF_LOAD, rop, jtoc, wordOperandForReference(offset.toWord()), loc));
                        s.putOperand(idx, rop.copyD2U());
                    } else if (use instanceof CodeConstantOperand) {
                        RegisterOperand rop = ir.regpool.makeTemp(TypeReference.CodeArray);
                        Operand jtoc = ir.regpool.makeJTOCOp();
                        Offset offset = ((CodeConstantOperand) use).value.findOrCreateJtocOffset();
                        LocationOperand loc = new LocationOperand(offset);
                        s.insertBefore(Load.create(IA32_REF_LOAD, rop, jtoc, wordOperandForReference(offset.toWord()), loc));
                        s.putOperand(idx, rop.copyD2U());
                    }
                }
            }
        }
    }
}
Also used : StringConstantOperand(org.jikesrvm.compilers.opt.ir.operand.StringConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) StringConstantOperand(org.jikesrvm.compilers.opt.ir.operand.StringConstantOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) Offset(org.vmmagic.unboxed.Offset) NullConstantOperand(org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) ClassConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) ObjectConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) CodeConstantOperand(org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)

Example 12 with TIBConstantOperand

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

the class ConvertToLowLevelIR method getTIB.

static Operand getTIB(Instruction s, IR ir, Operand obj, Operand guard) {
    if (obj.isObjectConstant()) {
        // NB Constant types must already be resolved
        try {
            RVMType type = obj.getType().resolve();
            return new TIBConstantOperand(type);
        } catch (NoClassDefFoundError e) {
            if (VM.runningVM)
                throw e;
        // Class not found during bootstrap due to chasing a class
        // only valid in the bootstrap JVM
        }
    }
    RegisterOperand res = ir.regpool.makeTemp(TypeReference.TIB);
    Instruction s2 = GuardedUnary.create(GET_OBJ_TIB, res, obj, guard);
    s.insertBefore(s2);
    return res.copyD2U();
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) RVMType(org.jikesrvm.classloader.RVMType) TIBConstantOperand(org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Aggregations

TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)12 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)10 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)9 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)9 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)8 CodeConstantOperand (org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)8 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)8 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)8 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)8 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)8 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)7 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)7 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)7 UnreachableOperand (org.jikesrvm.compilers.opt.ir.operand.UnreachableOperand)7 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)6 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)6 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)6 OptimizingCompilerException (org.jikesrvm.compilers.opt.OptimizingCompilerException)5 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)5 RVMType (org.jikesrvm.classloader.RVMType)3