Search in sources :

Example 1 with OsrPoint

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

the class OsrPointConstructor method fixupCFGForOsr.

/**
 * Splits each OsrPoint, and connects it to the exit point.
 * @param ir the IR
 */
private void fixupCFGForOsr(IR ir) {
    for (int i = 0, n = osrPoints.size(); i < n; i++) {
        Instruction osr = osrPoints.get(i);
        BasicBlock bb = osr.getBasicBlock();
        BasicBlock newBB = bb.segregateInstruction(osr, ir);
        bb.recomputeNormalOut(ir);
        newBB.recomputeNormalOut(ir);
    }
}
Also used : BasicBlock(org.jikesrvm.compilers.opt.ir.BasicBlock) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) OsrPoint(org.jikesrvm.compilers.opt.ir.OsrPoint)

Example 2 with OsrPoint

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

the class OsrPointConstructor method renovateOsrPoints.

/**
 * For each OsrPoint instruction, traces its OsrBarriers created by
 * inlining. rebuild OsrPoint instruction to hold all necessary
 * information to recover from inlined activation.
 * @param ir the IR
 */
private void renovateOsrPoints(IR ir) {
    for (int osrIdx = 0, osrSize = osrPoints.size(); osrIdx < osrSize; osrIdx++) {
        Instruction osr = osrPoints.get(osrIdx);
        LinkedList<Instruction> barriers = new LinkedList<Instruction>();
        // Step 1: collect barriers put before inlined method
        // in the order of from inner to outer
        {
            GenerationContext gc = ir.getGc();
            Instruction bar = gc.getOSRBarrierFromInst(osr);
            if (osr.position() == null)
                osr.setPosition(bar.position());
            adjustBCIndex(osr);
            while (bar != null) {
                barriers.add(bar);
                // verify each barrier is clean
                if (VM.VerifyAssertions) {
                    if (!isBarrierClean(bar)) {
                        VM.sysWriteln("Barrier " + bar + " is not clean!");
                    }
                    VM._assert(isBarrierClean(bar));
                }
                Instruction callsite = bar.position().getCallSite();
                if (callsite != null) {
                    bar = gc.getOSRBarrierFromInst(callsite);
                    if (bar == null) {
                        VM.sysWrite("call site :" + callsite);
                        if (VM.VerifyAssertions)
                            VM._assert(VM.NOT_REACHED);
                    }
                    adjustBCIndex(bar);
                } else {
                    bar = null;
                }
            }
        }
        int inlineDepth = barriers.size();
        if (VM.VerifyAssertions) {
            if (inlineDepth == 0) {
                VM.sysWriteln("Inlining depth for " + osr + " is 0!");
            }
            VM._assert(inlineDepth != 0);
        }
        // Step 2: make a new InlinedOsrTypeOperand from barriers
        int[] methodids = new int[inlineDepth];
        int[] bcindexes = new int[inlineDepth];
        byte[][] localTypeCodes = new byte[inlineDepth][];
        byte[][] stackTypeCodes = new byte[inlineDepth][];
        int totalOperands = 0;
        // first iteration, count the size of total locals and stack sizes
        for (int barIdx = 0, barSize = barriers.size(); barIdx < barSize; barIdx++) {
            Instruction bar = barriers.get(barIdx);
            methodids[barIdx] = bar.position().method.getId();
            bcindexes[barIdx] = bar.getBytecodeIndex();
            OsrTypeInfoOperand typeInfo = OsrBarrier.getTypeInfo(bar);
            localTypeCodes[barIdx] = typeInfo.localTypeCodes;
            stackTypeCodes[barIdx] = typeInfo.stackTypeCodes;
            // count the number of operand, but ignore VoidTypeCode
            totalOperands += OsrBarrier.getNumberOfElements(bar);
        /*
        if (VM.TraceOnStackReplacement) {
          VM.sysWriteln("OsrBarrier : "+bar.bcIndex
                        +"@"+bar.position.method
                        +" "+typeInfo);
        }
        */
        }
        // new make InlinedOsrTypeInfoOperand
        InlinedOsrTypeInfoOperand typeInfo = new InlinedOsrTypeInfoOperand(methodids, bcindexes, localTypeCodes, stackTypeCodes);
        OsrPoint.mutate(osr, osr.operator(), typeInfo, totalOperands);
        // Step 3: second iteration, copy operands
        int opIndex = 0;
        for (int barIdx = 0, barSize = barriers.size(); barIdx < barSize; barIdx++) {
            Instruction bar = barriers.get(barIdx);
            for (int elmIdx = 0, elmSize = OsrBarrier.getNumberOfElements(bar); elmIdx < elmSize; elmIdx++) {
                Operand op = OsrBarrier.getElement(bar, elmIdx);
                if (VM.VerifyAssertions) {
                    if (op == null) {
                        VM.sysWriteln(elmIdx + "th Operand of " + bar + " is null!");
                    }
                    VM._assert(op != null);
                }
                if (op.isRegister()) {
                    op = op.asRegister().copyU2U();
                } else {
                    op = op.copy();
                }
                OsrPoint.setElement(osr, opIndex, op);
                opIndex++;
            }
        }
        // the last OsrBarrier should in the current method
        if (VM.VerifyAssertions) {
            Instruction lastBar = barriers.getLast();
            if (ir.method != lastBar.position().method) {
                VM.sysWriteln("The last barrier is not in the same method as osr:");
                VM.sysWriteln(lastBar + "@" + lastBar.position().method);
                VM.sysWriteln("current method @" + ir.method);
            }
            VM._assert(ir.method == lastBar.position().method);
            if (opIndex != totalOperands) {
                VM.sysWriteln("opIndex and totalOperands do not match:");
                VM.sysWriteln("opIndex = " + opIndex);
                VM.sysWriteln("totalOperands = " + totalOperands);
            }
            VM._assert(opIndex == totalOperands);
        }
    // end of assertion
    }
// end of for loop
}
Also used : InlinedOsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand) OsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.OsrTypeInfoOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) InlinedOsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand) OsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.OsrTypeInfoOperand) InlinedOsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand) Instruction(org.jikesrvm.compilers.opt.ir.Instruction) OsrPoint(org.jikesrvm.compilers.opt.ir.OsrPoint) LinkedList(java.util.LinkedList)

Example 3 with OsrPoint

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

the class BURS_Helpers method OSR.

/**
 * special case handling OSR instructions expand long type variables to two
 * integers
 * @param burs the burs instance
 * @param s an OSRPoint instruction
 */
protected void OSR(BURS burs, Instruction s) {
    if (VM.VerifyAssertions) {
        opt_assert(OsrPoint.conforms(s));
    }
    // Check type info first because this needs to be done
    // for both 32-bit and 64-bit cases.
    InlinedOsrTypeInfoOperand typeInfo;
    if (VM.BuildFor32Addr) {
        // Clearing type info is ok, because instruction will be mutated and the
        // info will be reinserted
        typeInfo = OsrPoint.getClearInlinedTypeInfo(s);
    } else {
        // Instruction won't be changed so info needs to be left in
        typeInfo = OsrPoint.getInlinedTypeInfo(s);
    }
    if (VM.VerifyAssertions) {
        if (typeInfo == null) {
            VM.sysWriteln("OsrPoint " + s + " has a <null> type info:");
            VM.sysWriteln("  position :" + s.getBytecodeIndex() + "@" + s.position().method);
        }
        opt_assert(typeInfo != null);
    }
    int numparam = OsrPoint.getNumberOfElements(s);
    if (VM.BuildFor32Addr) {
        // 1. how many params
        int numlong = 0;
        for (int i = 0; i < numparam; i++) {
            Operand param = OsrPoint.getElement(s, i);
            if (param.getType().isLongType()) {
                numlong++;
            }
        }
        // 2. collect params
        Operand[] params = new Operand[numparam];
        for (int i = 0; i < numparam; i++) {
            params[i] = OsrPoint.getClearElement(s, i);
        }
        // set the number of valid params in osr type info, used
        // in LinearScan
        typeInfo.validOps = numparam;
        // 3: only makes second half register of long being used
        // creates room for long types.
        burs.append(OsrPoint.mutate(s, s.operator(), typeInfo, numparam + numlong));
        int pidx = numparam;
        for (int i = 0; i < numparam; i++) {
            Operand param = params[i];
            OsrPoint.setElement(s, i, param);
            if (param instanceof RegisterOperand) {
                RegisterOperand rparam = (RegisterOperand) param;
                // LinearScan will update the map.
                if (rparam.getType().isLongType()) {
                    OsrPoint.setElement(s, pidx++, L(burs.ir.regpool.getSecondReg(rparam.getRegister())));
                }
            } else if (param instanceof LongConstantOperand) {
                LongConstantOperand val = (LongConstantOperand) param;
                if (VM.TraceOnStackReplacement) {
                    VM.sysWriteln("caught a long const " + val);
                }
                OsrPoint.setElement(s, i, IC(val.upper32()));
                OsrPoint.setElement(s, pidx++, IC(val.lower32()));
            } else if (param instanceof IntConstantOperand) {
            } else {
                throw new OptimizingCompilerException("BURS_Helpers", "unexpected parameter type" + param);
            }
        }
        if (pidx != (numparam + numlong)) {
            VM.sysWriteln("pidx = " + pidx);
            VM.sysWriteln("numparam = " + numparam);
            VM.sysWriteln("numlong = " + numlong);
        }
        if (VM.VerifyAssertions) {
            opt_assert(pidx == (numparam + numlong));
        }
    } else {
        // set the number of valid params in osr type info, used
        // in LinearScan
        typeInfo.validOps = numparam;
        burs.append(s);
    }
}
Also used : LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) LongConstantOperand(org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand) DoubleConstantOperand(org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand) RegisterOperand(org.jikesrvm.compilers.opt.ir.operand.RegisterOperand) IA32ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ia32.IA32ConditionOperand) FloatConstantOperand(org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand) StackLocationOperand(org.jikesrvm.compilers.opt.ir.operand.StackLocationOperand) LocationOperand(org.jikesrvm.compilers.opt.ir.operand.LocationOperand) MemoryOperand(org.jikesrvm.compilers.opt.ir.operand.MemoryOperand) IntConstantOperand(org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand) MethodOperand(org.jikesrvm.compilers.opt.ir.operand.MethodOperand) TrueGuardOperand(org.jikesrvm.compilers.opt.ir.operand.TrueGuardOperand) ConditionOperand(org.jikesrvm.compilers.opt.ir.operand.ConditionOperand) Operand(org.jikesrvm.compilers.opt.ir.operand.Operand) BranchProfileOperand(org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand) InlinedOsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand) TrapCodeOperand(org.jikesrvm.compilers.opt.ir.operand.TrapCodeOperand) BURSManagedFPROperand(org.jikesrvm.compilers.opt.ir.operand.ia32.BURSManagedFPROperand) BranchOperand(org.jikesrvm.compilers.opt.ir.operand.BranchOperand) ConstantOperand(org.jikesrvm.compilers.opt.ir.operand.ConstantOperand) InlinedOsrTypeInfoOperand(org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand) OptimizingCompilerException(org.jikesrvm.compilers.opt.OptimizingCompilerException) OsrPoint(org.jikesrvm.compilers.opt.ir.OsrPoint)

Aggregations

OsrPoint (org.jikesrvm.compilers.opt.ir.OsrPoint)3 Instruction (org.jikesrvm.compilers.opt.ir.Instruction)2 InlinedOsrTypeInfoOperand (org.jikesrvm.compilers.opt.ir.operand.InlinedOsrTypeInfoOperand)2 Operand (org.jikesrvm.compilers.opt.ir.operand.Operand)2 LinkedList (java.util.LinkedList)1 OptimizingCompilerException (org.jikesrvm.compilers.opt.OptimizingCompilerException)1 BasicBlock (org.jikesrvm.compilers.opt.ir.BasicBlock)1 BranchOperand (org.jikesrvm.compilers.opt.ir.operand.BranchOperand)1 BranchProfileOperand (org.jikesrvm.compilers.opt.ir.operand.BranchProfileOperand)1 ConditionOperand (org.jikesrvm.compilers.opt.ir.operand.ConditionOperand)1 ConstantOperand (org.jikesrvm.compilers.opt.ir.operand.ConstantOperand)1 DoubleConstantOperand (org.jikesrvm.compilers.opt.ir.operand.DoubleConstantOperand)1 FloatConstantOperand (org.jikesrvm.compilers.opt.ir.operand.FloatConstantOperand)1 IntConstantOperand (org.jikesrvm.compilers.opt.ir.operand.IntConstantOperand)1 LocationOperand (org.jikesrvm.compilers.opt.ir.operand.LocationOperand)1 LongConstantOperand (org.jikesrvm.compilers.opt.ir.operand.LongConstantOperand)1 MemoryOperand (org.jikesrvm.compilers.opt.ir.operand.MemoryOperand)1 MethodOperand (org.jikesrvm.compilers.opt.ir.operand.MethodOperand)1 OsrTypeInfoOperand (org.jikesrvm.compilers.opt.ir.operand.OsrTypeInfoOperand)1 RegisterOperand (org.jikesrvm.compilers.opt.ir.operand.RegisterOperand)1