Search in sources :

Example 1 with AbstractBlockBase

use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.

the class TraceStatisticsPrinter method print.

@SuppressWarnings("try")
protected static void print(DebugContext debug, TraceBuilderResult result, String compilationUnitName) {
    List<Trace> traces = result.getTraces();
    int numTraces = traces.size();
    try (Indent indent0 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<tracestatistics>")) {
        debug.log(DebugContext.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null");
        try (Indent indent1 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<traces>")) {
            printRawLine(debug, "tracenumber", "total", "min", "max", "numBlocks");
            for (int i = 0; i < numTraces; i++) {
                AbstractBlockBase<?>[] t = traces.get(i).getBlocks();
                double total = 0;
                double max = Double.NEGATIVE_INFINITY;
                double min = Double.POSITIVE_INFINITY;
                for (AbstractBlockBase<?> block : t) {
                    double probability = block.probability();
                    total += probability;
                    if (probability < min) {
                        min = probability;
                    }
                    if (probability > max) {
                        max = probability;
                    }
                }
                printLine(debug, i, total, min, max, t.length);
            }
        }
        debug.log(DebugContext.VERBOSE_LEVEL, "</traces>");
    }
    debug.log(DebugContext.VERBOSE_LEVEL, "</tracestatistics>");
}
Also used : Indent(org.graalvm.compiler.debug.Indent) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase)

Example 2 with AbstractBlockBase

use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.

the class UniDirectionalTraceBuilder method findTrace.

/**
 * Build a new trace starting at {@code block}.
 */
@SuppressWarnings("try")
private List<AbstractBlockBase<?>> findTrace(DebugContext debug, AbstractBlockBase<?> traceStart) {
    assert checkPredecessorsProcessed(traceStart);
    ArrayList<AbstractBlockBase<?>> trace = new ArrayList<>();
    int blockNumber = 0;
    try (Indent i = debug.logAndIndent("StartTrace: %s", traceStart)) {
        for (AbstractBlockBase<?> block = traceStart; block != null; block = selectNext(block)) {
            debug.log("add %s (prob: %f)", block, block.probability());
            processed.set(block.getId());
            trace.add(block);
            unblock(block);
            block.setLinearScanNumber(blockNumber++);
        }
    }
    return trace;
}
Also used : Indent(org.graalvm.compiler.debug.Indent) ArrayList(java.util.ArrayList) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase)

Example 3 with AbstractBlockBase

use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.

the class ConstantTreeAnalyzer method analyzeBlocks.

/**
 * Queues all relevant blocks for {@linkplain #process processing}.
 *
 * This is a worklist-style algorithm because a (more elegant) recursive implementation may
 * cause {@linkplain StackOverflowError stack overflows} on larger graphs.
 *
 * @param startBlock The start block of the dominator subtree.
 */
@SuppressWarnings("try")
private void analyzeBlocks(DebugContext debug, AbstractBlockBase<?> startBlock) {
    Deque<AbstractBlockBase<?>> worklist = new ArrayDeque<>();
    worklist.offerLast(startBlock);
    while (!worklist.isEmpty()) {
        AbstractBlockBase<?> block = worklist.pollLast();
        try (Indent i = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "analyze: %s", block)) {
            assert block != null : "worklist is empty!";
            assert isMarked(block) : "Block not part of the dominator tree: " + block;
            if (isLeafBlock(block)) {
                debug.log(DebugContext.VERBOSE_LEVEL, "leaf block");
                leafCost(block);
                continue;
            }
            if (!visited.get(block.getId())) {
                // if not yet visited (and not a leaf block) process all children first!
                debug.log(DebugContext.VERBOSE_LEVEL, "not marked");
                worklist.offerLast(block);
                AbstractBlockBase<?> dominated = block.getFirstDominated();
                while (dominated != null) {
                    filteredPush(debug, worklist, dominated);
                    dominated = dominated.getDominatedSibling();
                }
                visited.set(block.getId());
            } else {
                debug.log(DebugContext.VERBOSE_LEVEL, "marked");
                // otherwise, process block
                process(block);
            }
        }
    }
}
Also used : Indent(org.graalvm.compiler.debug.Indent) ArrayDeque(java.util.ArrayDeque) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase)

Example 4 with AbstractBlockBase

use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.

the class GraalCompiler method emitLIR0.

@SuppressWarnings("try")
private static LIRGenerationResult emitLIR0(Backend backend, StructuredGraph graph, Object stub, RegisterConfig registerConfig, LIRSuites lirSuites, String[] allocationRestrictedTo) {
    DebugContext debug = graph.getDebug();
    try (DebugContext.Scope ds = debug.scope("EmitLIR");
        DebugCloseable a = EmitLIR.start(debug)) {
        assert !graph.hasValueProxies();
        ScheduleResult schedule = graph.getLastSchedule();
        Block[] blocks = schedule.getCFG().getBlocks();
        Block startBlock = schedule.getCFG().getStartBlock();
        assert startBlock != null;
        assert startBlock.getPredecessorCount() == 0;
        AbstractBlockBase<?>[] codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock);
        AbstractBlockBase<?>[] linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock);
        LIR lir = new LIR(schedule.getCFG(), linearScanOrder, codeEmittingOrder, graph.getOptions(), graph.getDebug());
        FrameMapBuilder frameMapBuilder = backend.newFrameMapBuilder(registerConfig);
        LIRGenerationResult lirGenRes = backend.newLIRGenerationResult(graph.compilationId(), lir, frameMapBuilder, graph, stub);
        LIRGeneratorTool lirGen = backend.newLIRGenerator(lirGenRes);
        NodeLIRBuilderTool nodeLirGen = backend.newNodeLIRBuilder(graph, lirGen);
        // LIR generation
        LIRGenerationContext context = new LIRGenerationContext(lirGen, nodeLirGen, graph, schedule);
        new LIRGenerationPhase().apply(backend.getTarget(), lirGenRes, context);
        try (DebugContext.Scope s = debug.scope("LIRStages", nodeLirGen, lirGenRes, lir)) {
            // Dump LIR along with HIR (the LIR is looked up from context)
            debug.dump(DebugContext.BASIC_LEVEL, graph.getLastSchedule(), "After LIR generation");
            LIRGenerationResult result = emitLowLevel(backend.getTarget(), lirGenRes, lirGen, lirSuites, backend.newRegisterAllocationConfig(registerConfig, allocationRestrictedTo));
            return result;
        } catch (Throwable e) {
            throw debug.handle(e);
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    } finally {
        graph.checkCancellation();
    }
}
Also used : ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) NodeLIRBuilderTool(org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool) LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) LIRGenerationContext(org.graalvm.compiler.core.LIRGenerationPhase.LIRGenerationContext) LIR(org.graalvm.compiler.lir.LIR) Block(org.graalvm.compiler.nodes.cfg.Block) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool)

Example 5 with AbstractBlockBase

use of org.graalvm.compiler.core.common.cfg.AbstractBlockBase in project graal by oracle.

the class SimpleStackSlotAllocator method updateLIR.

@SuppressWarnings("try")
protected void updateLIR(LIRGenerationResult res, StackSlot[] mapping) {
    DebugContext debug = res.getLIR().getDebug();
    try (DebugContext.Scope scope = debug.scope("StackSlotMappingLIR")) {
        ValueProcedure updateProc = (value, mode, flags) -> {
            if (isVirtualStackSlot(value)) {
                StackSlot stackSlot = mapping[asVirtualStackSlot(value).getId()];
                debug.log("map %s -> %s", value, stackSlot);
                return stackSlot;
            }
            return value;
        };
        for (AbstractBlockBase<?> block : res.getLIR().getControlFlowGraph().getBlocks()) {
            try (Indent indent0 = debug.logAndIndent("block: %s", block)) {
                for (LIRInstruction inst : res.getLIR().getLIRforBlock(block)) {
                    try (Indent indent1 = debug.logAndIndent("Inst: %d: %s", inst.id(), inst)) {
                        inst.forEachAlive(updateProc);
                        inst.forEachInput(updateProc);
                        inst.forEachOutput(updateProc);
                        inst.forEachTemp(updateProc);
                        inst.forEachState(updateProc);
                    }
                }
            }
        }
    }
}
Also used : ValueProcedure(org.graalvm.compiler.lir.ValueProcedure) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) FrameMapBuilderTool(org.graalvm.compiler.lir.framemap.FrameMapBuilderTool) AllocationPhase(org.graalvm.compiler.lir.phases.AllocationPhase) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) StackSlotAllocatorUtil.allocatedSlots(org.graalvm.compiler.lir.stackslotalloc.StackSlotAllocatorUtil.allocatedSlots) VirtualStackSlotRange(org.graalvm.compiler.lir.framemap.VirtualStackSlotRange) LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) TargetDescription(jdk.vm.ci.code.TargetDescription) LIRValueUtil.asVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot) SimpleVirtualStackSlot(org.graalvm.compiler.lir.framemap.SimpleVirtualStackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext) StackSlotAllocatorUtil.virtualFramesize(org.graalvm.compiler.lir.stackslotalloc.StackSlotAllocatorUtil.virtualFramesize) Indent(org.graalvm.compiler.debug.Indent) GraalError(org.graalvm.compiler.debug.GraalError) StackSlot(jdk.vm.ci.code.StackSlot) LIRValueUtil.isVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot) ValueProcedure(org.graalvm.compiler.lir.ValueProcedure) StackSlotAllocatorUtil.allocatedFramesize(org.graalvm.compiler.lir.stackslotalloc.StackSlotAllocatorUtil.allocatedFramesize) VirtualStackSlot(org.graalvm.compiler.lir.VirtualStackSlot) Indent(org.graalvm.compiler.debug.Indent) LIRInstruction(org.graalvm.compiler.lir.LIRInstruction) LIRValueUtil.asVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot) SimpleVirtualStackSlot(org.graalvm.compiler.lir.framemap.SimpleVirtualStackSlot) StackSlot(jdk.vm.ci.code.StackSlot) LIRValueUtil.isVirtualStackSlot(org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot) VirtualStackSlot(org.graalvm.compiler.lir.VirtualStackSlot) DebugContext(org.graalvm.compiler.debug.DebugContext)

Aggregations

AbstractBlockBase (org.graalvm.compiler.core.common.cfg.AbstractBlockBase)15 Indent (org.graalvm.compiler.debug.Indent)11 DebugContext (org.graalvm.compiler.debug.DebugContext)9 ArrayDeque (java.util.ArrayDeque)7 GraalError (org.graalvm.compiler.debug.GraalError)7 LIRInstruction (org.graalvm.compiler.lir.LIRInstruction)7 ArrayList (java.util.ArrayList)6 Value (jdk.vm.ci.meta.Value)6 LIRGenerationResult (org.graalvm.compiler.lir.gen.LIRGenerationResult)6 BitSet (java.util.BitSet)5 EnumSet (java.util.EnumSet)5 Register (jdk.vm.ci.code.Register)5 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)5 ValueUtil.isRegister (jdk.vm.ci.code.ValueUtil.isRegister)5 InstructionValueConsumer (org.graalvm.compiler.lir.InstructionValueConsumer)5 OperandFlag (org.graalvm.compiler.lir.LIRInstruction.OperandFlag)5 OperandMode (org.graalvm.compiler.lir.LIRInstruction.OperandMode)5 StackSlot (jdk.vm.ci.code.StackSlot)4 TargetDescription (jdk.vm.ci.code.TargetDescription)4 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)4