Search in sources :

Example 1 with Pair

use of org.jikesrvm.util.Pair in project JikesRVM by JikesRVM.

the class EnterSSA method patchPEIgeneratedValues.

/**
 * Work around some problems with PEI-generated values and
 * handlers.  Namely, if a PEI has a return value, rename the
 * result register before and after the PEI in order to reflect the fact
 * that the PEI may not actually assign the result register.
 */
private void patchPEIgeneratedValues() {
    // this only applies if there are exception handlers
    if (!ir.hasReachableExceptionHandlers())
        return;
    HashSet<Pair<BasicBlock, RegisterOperand>> needed = new HashSet<Pair<BasicBlock, RegisterOperand>>(4);
    Enumeration<BasicBlock> blocks = ir.getBasicBlocks();
    while (blocks.hasMoreElements()) {
        BasicBlock block = blocks.nextElement();
        if (block.getExceptionalOut().hasMoreElements()) {
            Instruction pei = block.lastRealInstruction();
            if (pei != null && pei.isPEI() && ResultCarrier.conforms(pei)) {
                boolean copyNeeded = false;
                RegisterOperand v = ResultCarrier.getResult(pei);
                // void calls and the like... :(
                if (v != null) {
                    Register orig = v.getRegister();
                    {
                        Enumeration<BasicBlock> out = block.getApplicableExceptionalOut(pei);
                        while (out.hasMoreElements()) {
                            BasicBlock exp = out.nextElement();
                            LiveSet explive = live.getLiveInfo(exp).getIn();
                            if (explive.contains(orig)) {
                                copyNeeded = true;
                                break;
                            }
                        }
                    }
                    if (copyNeeded) {
                        Enumeration<BasicBlock> out = block.getApplicableExceptionalOut(pei);
                        while (out.hasMoreElements()) {
                            BasicBlock exp = out.nextElement();
                            needed.add(new Pair<BasicBlock, RegisterOperand>(exp, v));
                        }
                    }
                }
            }
        }
    }
    // having determine where copies should be inserted, now insert them.
    if (!needed.isEmpty()) {
        for (Pair<BasicBlock, RegisterOperand> copy : needed) {
            BasicBlock inBlock = copy.first;
            RegisterOperand registerOp = copy.second;
            TypeReference type = registerOp.getType();
            Register register = registerOp.getRegister();
            Register temp = ir.regpool.getReg(register);
            inBlock.prependInstruction(SSA.makeMoveInstruction(ir, register, temp, type));
            Enumeration<BasicBlock> outBlocks = inBlock.getIn();
            while (outBlocks.hasMoreElements()) {
                BasicBlock outBlock = outBlocks.nextElement();
                Instruction x = SSA.makeMoveInstruction(ir, temp, register, type);
                SSA.addAtEnd(ir, outBlock, x, true);
            }
        }
        // Recompute liveness information.  You might be tempted to incrementally
        // update it, but it's tricky, so resist.....do the obvious, but easy thing!
        prepare();
    }
}
Also used : LiveSet(org.jikesrvm.compilers.opt.liveness.LiveSet) Enumeration(java.util.Enumeration) BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) Register(org.jikesrvm.compilers.opt.ir.Register) TypeReference(org.jikesrvm.classloader.TypeReference) Pair(org.jikesrvm.util.Pair) HashSet(java.util.HashSet)

Aggregations

Enumeration (java.util.Enumeration)1 HashSet (java.util.HashSet)1 TypeReference (org.jikesrvm.classloader.TypeReference)1 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)1 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)1 Register (org.jikesrvm.compilers.opt.ir.Register)1 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)1 LiveSet (org.jikesrvm.compilers.opt.liveness.LiveSet)1 Pair (org.jikesrvm.util.Pair)1