Search in sources :

Example 41 with DebugContext

use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.

the class MoveResolver method printMapping.

@SuppressWarnings("try")
private void printMapping() {
    DebugContext debug = allocator.getDebug();
    try (Indent indent = debug.logAndIndent("Mapping")) {
        for (int i = mappingFrom.size() - 1; i >= 0; i--) {
            Interval fromInterval = mappingFrom.get(i);
            Interval toInterval = mappingTo.get(i);
            String from;
            Value to = toInterval.location();
            if (fromInterval == null) {
                from = mappingFromOpr.get(i).toString();
            } else {
                from = fromInterval.location().toString();
            }
            debug.log("move %s <- %s", from, to);
        }
    }
}
Also used : Indent(org.graalvm.compiler.debug.Indent) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 42 with DebugContext

use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.

the class MoveResolver method resolveMappings.

@SuppressWarnings("try")
private void resolveMappings() {
    DebugContext debug = allocator.getDebug();
    try (Indent indent = debug.logAndIndent("resolveMapping")) {
        assert verifyBeforeResolve();
        if (debug.isLogEnabled()) {
            printMapping();
        }
        // Block all registers that are used as input operands of a move.
        // When a register is blocked, no move to this register is emitted.
        // This is necessary for detecting cycles in moves.
        int i;
        for (i = mappingFrom.size() - 1; i >= 0; i--) {
            Interval fromInterval = mappingFrom.get(i);
            if (fromInterval != null) {
                blockRegisters(fromInterval);
            }
        }
        ArrayList<AllocatableValue> busySpillSlots = null;
        while (mappingFrom.size() > 0) {
            boolean processedInterval = false;
            int spillCandidate = -1;
            for (i = mappingFrom.size() - 1; i >= 0; i--) {
                Interval fromInterval = mappingFrom.get(i);
                Interval toInterval = mappingTo.get(i);
                if (safeToProcessMove(fromInterval, toInterval)) {
                    // this interval can be processed because target is free
                    final LIRInstruction move;
                    if (fromInterval != null) {
                        move = insertMove(fromInterval, toInterval);
                        unblockRegisters(fromInterval);
                    } else {
                        move = insertMove(mappingFromOpr.get(i), toInterval);
                    }
                    move.setComment(res, "MoveResolver resolve mapping");
                    if (LIRValueUtil.isStackSlotValue(toInterval.location())) {
                        if (busySpillSlots == null) {
                            busySpillSlots = new ArrayList<>(2);
                        }
                        busySpillSlots.add(toInterval.location());
                    }
                    mappingFrom.remove(i);
                    mappingFromOpr.remove(i);
                    mappingTo.remove(i);
                    processedInterval = true;
                } else if (fromInterval != null && isRegister(fromInterval.location()) && (busySpillSlots == null || !busySpillSlots.contains(fromInterval.spillSlot()))) {
                    // this interval cannot be processed now because target is not free
                    // it starts in a register, so it is a possible candidate for spilling
                    spillCandidate = i;
                }
            }
            if (!processedInterval) {
                breakCycle(spillCandidate);
            }
        }
    }
    // reset to default value
    multipleReadsAllowed = false;
    // check that all intervals have been processed
    assert checkEmpty();
}
Also used : Indent(org.graalvm.compiler.debug.Indent) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) DebugContext(org.graalvm.compiler.debug.DebugContext) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 43 with DebugContext

use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.

the class OptimizingLinearScanWalker method handleSpillSlot.

@SuppressWarnings("try")
@Override
protected void handleSpillSlot(Interval interval) {
    assert interval.location() != null : "interval  not assigned " + interval;
    if (interval.canMaterialize()) {
        assert !isStackSlotValue(interval.location()) : "interval can materialize but assigned to a stack slot " + interval;
        return;
    }
    assert isStackSlotValue(interval.location()) : "interval not assigned to a stack slot " + interval;
    DebugContext debug = allocator.getDebug();
    try (DebugContext.Scope s1 = debug.scope("LSRAOptimization")) {
        debug.log("adding stack to unhandled list %s", interval);
        unhandledLists.addToListSortedByStartAndUsePositions(RegisterBinding.Stack, interval);
    }
}
Also used : DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 44 with DebugContext

use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.

the class RegisterVerifier method processSuccessor.

private void processSuccessor(AbstractBlockBase<?> block, Interval[] inputState) {
    DebugContext debug = allocator.getDebug();
    Interval[] savedState = stateForBlock(block);
    if (savedState != null) {
        // this block was already processed before.
        // check if new inputState is consistent with savedState
        boolean savedStateCorrect = true;
        for (int i = 0; i < stateSize(); i++) {
            if (inputState[i] != savedState[i]) {
                // interval in this register . assume that this register is invalid
                if (savedState[i] != null) {
                    // invalidate old calculation only if it assumed that
                    // register was valid. when the register was already invalid,
                    // then the old calculation was correct.
                    savedStateCorrect = false;
                    savedState[i] = null;
                    debug.log("processSuccessor B%d: invalidating slot %d", block.getId(), i);
                }
            }
        }
        if (savedStateCorrect) {
            // already processed block with correct inputState
            debug.log("processSuccessor B%d: previous visit already correct", block.getId());
        } else {
            // must re-visit this block
            debug.log("processSuccessor B%d: must re-visit because input state changed", block.getId());
            addToWorkList(block);
        }
    } else {
        // block was not processed before, so set initial inputState
        debug.log("processSuccessor B%d: initial visit", block.getId());
        setStateForBlock(block, copy(inputState));
        addToWorkList(block);
    }
}
Also used : DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 45 with DebugContext

use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.

the class RegisterVerifier method verify.

@SuppressWarnings("try")
void verify(AbstractBlockBase<?> start) {
    DebugContext debug = allocator.getDebug();
    try (DebugContext.Scope s = debug.scope("RegisterVerifier")) {
        // setup input registers (method arguments) for first block
        Interval[] inputState = new Interval[stateSize()];
        setStateForBlock(start, inputState);
        addToWorkList(start);
        // main loop for verification
        do {
            AbstractBlockBase<?> block = workList.get(0);
            workList.remove(0);
            processBlock(block);
        } while (!workList.isEmpty());
    }
}
Also used : DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

DebugContext (org.graalvm.compiler.debug.DebugContext)234 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)87 OptionValues (org.graalvm.compiler.options.OptionValues)50 Indent (org.graalvm.compiler.debug.Indent)37 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)31 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)29 Test (org.junit.Test)27 Node (org.graalvm.compiler.graph.Node)24 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)24 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)22 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)20 Scope (org.graalvm.compiler.debug.DebugContext.Scope)18 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)18 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)17 ValueNode (org.graalvm.compiler.nodes.ValueNode)16 FixedNode (org.graalvm.compiler.nodes.FixedNode)14 CompilationResult (org.graalvm.compiler.code.CompilationResult)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)12 LIR (org.graalvm.compiler.lir.LIR)11