Search in sources :

Example 46 with Instruction

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

the class PiNodes method insertPiCheckCastNodes.

/**
 * Insert Pi nodes for checkcast operations.
 *
 * <p>Each checkcast obj will be followed by
 * <pre> ref_move obj, obj </pre>
 *
 * @param ir the governing IR
 */
private void insertPiCheckCastNodes(IR ir) {
    Instruction nextInst = null;
    // for each instruction in the IR
    for (Instruction instr = ir.firstInstructionInCodeOrder(); instr != null; instr = nextInst) {
        // can't use iterator, since we modify instruction stream
        nextInst = instr.nextInstructionInCodeOrder();
        if (TypeCheck.conforms(instr)) {
            // get compared variables
            Operand obj = TypeCheck.getRef(instr);
            // create the instruction and insert it
            if (obj.isRegister()) {
                RegisterOperand lval = (RegisterOperand) obj.copy();
                lval.clearDeclaredType();
                if (lval.getType().isLoaded() && lval.getType().isClassType() && lval.getType().peekType().asClass().isFinal()) {
                    lval.setPreciseType(TypeCheck.getType(instr).getTypeRef());
                } else {
                    lval.clearPreciseType();
                    lval.setType(TypeCheck.getType(instr).getTypeRef());
                }
                Instruction s = GuardedUnary.create(PI, lval, obj.copy(), null);
                s.copyPosition(instr);
                Operand iGuard = TypeCheck.getGuard(instr);
                if (iGuard != null) {
                    Operand sGuard = iGuard.copy();
                    GuardedUnary.setGuard(s, sGuard);
                }
                instr.insertAfter(s);
            }
        }
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 47 with Instruction

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

the class PiNodes method cleanUp.

/**
 * Change all PI nodes to INT_MOVE instructions
 * <p> Side effect: invalidates SSA state
 *
 * @param ir the governing IR
 */
static void cleanUp(IR ir) {
    for (Enumeration<Instruction> e = ir.forwardInstrEnumerator(); e.hasMoreElements(); ) {
        Instruction s = e.nextElement();
        if (s.operator() == PI) {
            RegisterOperand result = GuardedUnary.getResult(s);
            Operator mv = IRTools.getMoveOp(result.getType());
            Operand val = GuardedUnary.getVal(s);
            Move.mutate(s, mv, result, val);
        }
    }
    // invalidate SSA state
    ir.actualSSAOptions = null;
}
Also used : Operator(org.jikesrvm.compilers.opt.ir.Operator) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 48 with Instruction

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

the class PiNodes method insertPiIfNodes.

/**
 *  Insert PI nodes corresponding to compare operations.
 *  Pi-nodes are represented as dummy assignments with a single
 *  argument inserted along each outedge of the conditional.
 *
 *  @param ir the governing IR
 */
private void insertPiIfNodes(IR ir) {
    Enumeration<Instruction> e = ir.forwardInstrEnumerator();
    while (e.hasMoreElements()) {
        Instruction instr = e.nextElement();
        // TODO: what other compareops generate useful assertions?
        if (IfCmp.conforms(instr) || InlineGuard.conforms(instr)) {
            BasicBlock thisbb = instr.getBasicBlock();
            // only handle the "normal" case
            if (thisbb.getNumberOfNormalOut() != 2) {
                continue;
            }
            // insert new basic blocks on each edge out of thisbb
            Enumeration<BasicBlock> outBB = thisbb.getNormalOut();
            BasicBlock out1 = outBB.nextElement();
            BasicBlock new1 = IRTools.makeBlockOnEdge(thisbb, out1, ir);
            BasicBlock out2 = outBB.nextElement();
            BasicBlock new2 = IRTools.makeBlockOnEdge(thisbb, out2, ir);
            // blocks made on the outgoing edges.
            if (InlineGuard.conforms(instr))
                continue;
            RegisterOperand ifGuard = IfCmp.getGuardResult(instr);
            if (VM.VerifyAssertions) {
                VM._assert(ifGuard != null);
            }
            // get compared variables
            Operand a = IfCmp.getVal1(instr);
            Operand b = IfCmp.getVal2(instr);
            // determine which block is "taken" on the branch
            BasicBlock takenBlock = IfCmp.getTarget(instr).target.getBasicBlock();
            boolean new1IsTaken = false;
            if (takenBlock == new1) {
                new1IsTaken = true;
            }
            // insert the PI-node instructions for a and b
            if (a.isRegister() && !a.asRegister().getRegister().isPhysical() && (a.asRegister().getRegister().isInteger() || a.asRegister().getRegister().isAddress())) {
                // insert pi-nodes only for variables, not constants
                Instruction s = GuardedUnary.create(PI, (RegisterOperand) a.copy(), a.copy(), null);
                RegisterOperand sGuard = (RegisterOperand) ifGuard.copy();
                if (new1IsTaken) {
                    sGuard.setTaken();
                } else {
                    sGuard.setNotTaken();
                }
                GuardedUnary.setGuard(s, sGuard);
                new1.prependInstruction(s);
                s = s.copyWithoutLinks();
                sGuard = (RegisterOperand) ifGuard.copy();
                if (new1IsTaken) {
                    sGuard.setNotTaken();
                } else {
                    sGuard.setTaken();
                }
                GuardedUnary.setGuard(s, sGuard);
                new2.prependInstruction(s);
            }
            if (b.isRegister() && !b.asRegister().getRegister().isPhysical() && (b.asRegister().getRegister().isInteger() || b.asRegister().getRegister().isAddress())) {
                Instruction s = GuardedUnary.create(PI, (RegisterOperand) b.copy(), b.copy(), null);
                RegisterOperand sGuard = (RegisterOperand) ifGuard.copy();
                if (new1IsTaken) {
                    sGuard.setTaken();
                } else {
                    sGuard.setNotTaken();
                }
                GuardedUnary.setGuard(s, sGuard);
                new1.prependInstruction(s);
                s = s.copyWithoutLinks();
                sGuard = (RegisterOperand) ifGuard.copy();
                if (new1IsTaken) {
                    sGuard.setNotTaken();
                } else {
                    sGuard.setTaken();
                }
                GuardedUnary.setGuard(s, sGuard);
                new2.prependInstruction(s);
            }
        }
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 49 with Instruction

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

the class SSA method addAtEnd.

/**
 * Add a move instruction at the end of a basic block, renaming
 * with a temporary register if needed to protect conditional branches
 * at the end of the block.
 *
 * @param ir governing IR
 * @param bb the basic block
 * @param c  the move instruction to insert
 * @param exp whether or not to respect exception control flow at the
 *            end of the block
 */
static void addAtEnd(IR ir, BasicBlock bb, Instruction c, boolean exp) {
    if (exp) {
        bb.appendInstructionRespectingTerminalBranchOrPEI(c);
    } else {
        bb.appendInstructionRespectingTerminalBranch(c);
    }
    RegisterOperand aux = null;
    if (VM.VerifyAssertions) {
        VM._assert(Move.conforms(c));
    }
    RegisterOperand lhs = Move.getResult(c);
    Instruction i = c.nextInstructionInCodeOrder();
    while (!BBend.conforms(i)) {
        Enumeration<Operand> os = i.getUses();
        while (os.hasMoreElements()) {
            Operand op = os.nextElement();
            if (lhs.similar(op)) {
                if (aux == null) {
                    aux = ir.regpool.makeTemp(lhs);
                    c.insertBefore(makeMoveInstruction(ir, aux.getRegister(), lhs.getRegister(), lhs.getType()));
                }
                op.asRegister().setRegister(aux.getRegister());
            }
        }
        i = i.nextInstructionInCodeOrder();
    }
}
Also used : RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) BasicBlockOperand(org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand) HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Example 50 with Instruction

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

the class SSA method printInstructions.

/**
 * Print the instructions in SSA form.
 *
 * @param ir the IR, assumed to be in SSA form
 */
public static void printInstructions(IR ir) {
    SSADictionary dictionary = ir.HIRInfo.dictionary;
    System.out.println("********* START OF IR DUMP in SSA FOR " + ir.method);
    for (Enumeration<BasicBlock> be = ir.forwardBlockEnumerator(); be.hasMoreElements(); ) {
        BasicBlock bb = be.nextElement();
        // print the explicit instructions for basic block bb
        for (Enumeration<Instruction> e = dictionary.getAllInstructions(bb); e.hasMoreElements(); ) {
            Instruction s = e.nextElement();
            System.out.print(s.getBytecodeIndex() + "\t" + s);
            if (dictionary.defsHeapVariable(s) && s.operator() != PHI) {
                System.out.print("  (Implicit Defs: ");
                HeapOperand<?>[] defs = dictionary.getHeapDefs(s);
                if (defs != null) {
                    for (HeapOperand<?> def : defs) System.out.print(def + " ");
                }
                System.out.print(" )");
            }
            if (dictionary.usesHeapVariable(s) && s.operator() != PHI) {
                System.out.print("  (Implicit Uses: ");
                HeapOperand<?>[] uses = dictionary.getHeapUses(s);
                if (uses != null) {
                    for (HeapOperand<?> use : uses) System.out.print(use + " ");
                }
                System.out.print(" )");
            }
            System.out.println();
        }
    }
    System.out.println("*********   END OF IR DUMP in SSA FOR " + ir.method);
}
Also used : HeapOperand(org.jikesrvm.compilers.opt.ir.operand.HeapOperand) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction)

Aggregations

Instruction (org.jikesrvm.compilers.opt.ir.Instruction)356 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)204 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)144 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)117 Register (org.jikesrvm.compilers.opt.ir.Register)106 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)72 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)61 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)61 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)54 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)53 Test (org.junit.Test)49 TrueGuardOperand (org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand)46 TypeReference (org.jikesrvm.classloader.TypeReference)38 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)38 NullConstantOperand (org.jikesrvm.compilers.opt.ir.operand.NullConstantOperand)35 BasicBlockOperand (org.jikesrvm.compilers.opt.ir.operand.BasicBlockOperand)33 HeapOperand (org.jikesrvm.compilers.opt.ir.operand.HeapOperand)33 TrapCodeOperand (org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand)31 AddressConstantOperand (org.jikesrvm.compilers.opt.ir.operand.AddressConstantOperand)28 TypeOperand (org.jikesrvm.compilers.opt.ir.operand.TypeOperand)27