Search in sources :

Example 1 with PhiValueVisitor

use of org.graalvm.compiler.lir.ssa.SSAUtil.PhiValueVisitor in project graal by oracle.

the class SSALinearScanResolveDataFlowPhase method resolveCollectMappings.

@Override
protected void resolveCollectMappings(AbstractBlockBase<?> fromBlock, AbstractBlockBase<?> toBlock, AbstractBlockBase<?> midBlock, MoveResolver moveResolver) {
    super.resolveCollectMappings(fromBlock, toBlock, midBlock, moveResolver);
    if (toBlock.getPredecessorCount() > 1) {
        int toBlockFirstInstructionId = allocator.getFirstLirInstructionId(toBlock);
        int fromBlockLastInstructionId = allocator.getLastLirInstructionId(fromBlock) + 1;
        AbstractBlockBase<?> phiOutBlock = midBlock != null ? midBlock : fromBlock;
        ArrayList<LIRInstruction> instructions = allocator.getLIR().getLIRforBlock(phiOutBlock);
        int phiOutIdx = SSAUtil.phiOutIndex(allocator.getLIR(), phiOutBlock);
        int phiOutId = midBlock != null ? fromBlockLastInstructionId : instructions.get(phiOutIdx).id();
        assert phiOutId >= 0;
        PhiValueVisitor visitor = new PhiValueVisitor() {

            @Override
            public void visit(Value phiIn, Value phiOut) {
                assert !isRegister(phiOut) : "phiOut is a register: " + phiOut;
                assert !isRegister(phiIn) : "phiIn is a register: " + phiIn;
                Interval toInterval = allocator.splitChildAtOpId(allocator.intervalFor(phiIn), toBlockFirstInstructionId, LIRInstruction.OperandMode.DEF);
                DebugContext debug = allocator.getDebug();
                if (isConstantValue(phiOut)) {
                    numPhiResolutionMoves.increment(debug);
                    moveResolver.addMapping(asConstant(phiOut), toInterval);
                } else {
                    Interval fromInterval = allocator.splitChildAtOpId(allocator.intervalFor(phiOut), phiOutId, LIRInstruction.OperandMode.DEF);
                    if (fromInterval != toInterval && !fromInterval.location().equals(toInterval.location())) {
                        numPhiResolutionMoves.increment(debug);
                        if (!(isStackSlotValue(toInterval.location()) && isStackSlotValue(fromInterval.location()))) {
                            moveResolver.addMapping(fromInterval, toInterval);
                        } else {
                            numStackToStackMoves.increment(debug);
                            moveResolver.addMapping(fromInterval, toInterval);
                        }
                    }
                }
            }
        };
        SSAUtil.forEachPhiValuePair(allocator.getLIR(), toBlock, phiOutBlock, visitor);
        SSAUtil.removePhiOut(allocator.getLIR(), phiOutBlock);
    }
}
Also used : LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) LIRValueUtil.isStackSlotValue(org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue) LIRValueUtil.isConstantValue(org.graalvm.compiler.lir.LIRValueUtil.isConstantValue) Value(jdk.vm.ci.meta.Value) DebugContext(org.graalvm.compiler.debug.DebugContext) PhiValueVisitor(org.graalvm.compiler.lir.ssa.SSAUtil.PhiValueVisitor) Interval(org.graalvm.compiler.lir.alloc.lsra.Interval)

Aggregations

Value (jdk.vm.ci.meta.Value)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)1 LIRValueUtil.isConstantValue (org.graalvm.compiler.lir.LIRValueUtil.isConstantValue)1 LIRValueUtil.isStackSlotValue (org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue)1 Interval (org.graalvm.compiler.lir.alloc.lsra.Interval)1 PhiValueVisitor (org.graalvm.compiler.lir.ssa.SSAUtil.PhiValueVisitor)1