Search in sources :

Example 16 with AddressConstantOperand

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

the class NormalizeConstants method asImmediateOrRegPolymorphic.

static Operand asImmediateOrRegPolymorphic(Operand addr, Instruction s, IR ir, boolean signed) {
    if (addr instanceof IntConstantOperand) {
        if (!canBeImmediate(((IntConstantOperand) addr).value, signed)) {
            RegisterOperand rop = ir.regpool.makeTempInt();
            s.insertBefore(Move.create(REF_MOVE, rop, addr));
            return rop.copyD2U();
        }
    } else if (addr instanceof AddressConstantOperand) {
        if (!canBeImmediate(((AddressConstantOperand) addr).value, signed)) {
            RegisterOperand rop = ir.regpool.makeTempAddress();
            s.insertBefore(Move.create(REF_MOVE, rop, addr));
            return rop.copyD2U();
        } else {
            // can be immediate --> convert to int
            return new IntConstantOperand(((AddressConstantOperand) addr).value.toInt());
        }
    } else if (VM.BuildFor64Addr && (addr instanceof LongConstantOperand)) {
        if (!canBeImmediate(((LongConstantOperand) addr).value, signed)) {
            RegisterOperand rop = ir.regpool.makeTempLong();
            s.insertBefore(Move.create(REF_MOVE, rop, addr));
            return rop.copyD2U();
        } else {
            // can be immediate --> convert to int
            return new IntConstantOperand((int) ((LongConstantOperand) addr).value);
        }
    }
    // Operand was OK as is.
    return addr;
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)

Example 17 with AddressConstantOperand

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

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

the class NormalBURS method buildTrees.

/**
 * Stage 1: Complete the expression trees and identify tree roots.
 * Complete BURS trees by adding leaf nodes as needed, and
 * creating tree edges by calling insertChild1() or insertChild2()
 * This step is also where we introduce intermediate tree nodes for
 * any LIR instruction that has &gt; 2 "real" operands e.g., a CALL.
 * We also mark nodes that must be tree roots.
 *
 * @param dg  The dependence graph.
 */
private void buildTrees(DepGraph dg) {
    DepGraphNode bbNodes = (DepGraphNode) dg.firstNode();
    for (DepGraphNode n = bbNodes; n != null; n = (DepGraphNode) n.getNext()) {
        // Initialize n.treeNode
        AbstractBURS_TreeNode cur_parent = AbstractBURS_TreeNode.create(n);
        castNode(n).setCurrentParent(cur_parent);
        Instruction instr = n.instruction();
        // loop for USES of an instruction
        for (Enumeration<Operand> uses = instr.getUses(); uses.hasMoreElements(); ) {
            // Create tree edge for next use.
            Operand op = uses.nextElement();
            if (op == null)
                continue;
            // Set child = AbstractBURS_TreeNode for operand op
            AbstractBURS_TreeNode child;
            if (op instanceof RegisterOperand) {
                RegisterOperand regOp = (RegisterOperand) op;
                // ignore validation registers
                if (regOp.getRegister().isValidation())
                    continue;
                DepGraphEdge e = DepGraphEdge.findInputEdge(n, op);
                if (e == null) {
                    // operand is leaf
                    child = Register;
                } else {
                    child = castNode(e.fromNode()).getCurrentParent();
                }
            } else if (op instanceof IntConstantOperand) {
                child = new BURS_IntConstantTreeNode(((IntConstantOperand) op).value);
            } else if (op instanceof LongConstantOperand) {
                child = LongConstant;
            } else if (op instanceof AddressConstantOperand) {
                child = AddressConstant;
            } else if (op instanceof BranchOperand && instr.isCall()) {
                child = BranchTarget;
            } else if (op instanceof InlinedOsrTypeInfoOperand && instr.isYieldPoint()) {
                child = NullTreeNode;
            } else {
                continue;
            }
            // Attach child as child of cur_parent in correct position
            if (cur_parent.getChild1() == null) {
                cur_parent.setChild1(child);
            } else if (cur_parent.getChild2() == null) {
                cur_parent.setChild2(child);
            } else {
                // Create auxiliary node so as to represent
                // a instruction with arity > 2 in a binary tree.
                AbstractBURS_TreeNode child1 = cur_parent.getChild2();
                AbstractBURS_TreeNode aux = AbstractBURS_TreeNode.create(OTHER_OPERAND_opcode);
                cur_parent.setChild2(aux);
                cur_parent = aux;
                cur_parent.setChild1(child1);
                cur_parent.setChild2(child);
            }
        }
        // patch for calls & return
        switch(instr.getOpcode()) {
            case CALL_opcode:
            case SYSCALL_opcode:
            case YIELDPOINT_OSR_opcode:
                if (cur_parent.getChild2() == null) {
                    cur_parent.setChild2(NullTreeNode);
                }
            // fall through
            case RETURN_opcode:
                if (cur_parent.getChild1() == null) {
                    cur_parent.setChild1(NullTreeNode);
                }
        }
        if (mustBeTreeRoot(n)) {
            makeTreeRoot(castNode(n).getCurrentParent());
        }
    }
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) InlinedOsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) BranchOperand(org.jikesrvm.compilers.opt.ir.operand.BranchOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) AddressConstantOperand(org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand) DepGraphNode(org.jikesrvm.compilers.opt.depgraph.DepGraphNode) InlinedOsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) BranchOperand(org.jikesrvm.compilers.opt.ir.operand.BranchOperand) DepGraphEdge(org.jikesrvm.compilers.opt.depgraph.DepGraphEdge)

Aggregations

AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)18 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)15 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)15 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)13 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)10 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)9 DoubleConstantOperand (org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand)8 FloatConstantOperand (org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand)8 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)8 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)7 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)6 ClassConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ClassConstantOperand)6 ObjectConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ObjectConstantOperand)6 TypeReference (org.jikesrvm.classloader.TypeReference)5 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)5 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)5 StringConstantOperand (org.jikesrvm.compilers.opt.ir.operand.StringConstantOperand)5 CodeConstantOperand (org.jikesrvm.compilers.opt.ir.operand.CodeConstantOperand)4 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)4 TIBConstantOperand (org.jikesrvm.compilers.opt.ir.operand.TIBConstantOperand)4