Search in sources :

Example 1 with TraceBuilderResult

use of org.graalvm.compiler.core.common.alloc.TraceBuilderResult in project graal by oracle.

the class TraceBuilderPhase method getTraceBuilderResult.

private static TraceBuilderResult getTraceBuilderResult(LIR lir, AbstractBlockBase<?> startBlock, AbstractBlockBase<?>[] linearScanOrder) {
    TraceBuilderResult.TrivialTracePredicate pred = getTrivialTracePredicate(lir);
    OptionValues options = lir.getOptions();
    TraceBuilder selectedTraceBuilder = Options.TraceBuilding.getValue(options);
    DebugContext debug = lir.getDebug();
    debug.log(DebugContext.BASIC_LEVEL, "Building Traces using %s", selectedTraceBuilder);
    switch(Options.TraceBuilding.getValue(options)) {
        case SingleBlock:
            return SingleBlockTraceBuilder.computeTraces(debug, startBlock, linearScanOrder, pred);
        case BiDirectional:
            return BiDirectionalTraceBuilder.computeTraces(debug, startBlock, linearScanOrder, pred);
        case UniDirectional:
            return UniDirectionalTraceBuilder.computeTraces(debug, startBlock, linearScanOrder, pred);
    }
    throw GraalError.shouldNotReachHere("Unknown trace building algorithm: " + Options.TraceBuilding.getValue(options));
}
Also used : OptionValues(org.graalvm.compiler.options.OptionValues) TrivialTracePredicate(org.graalvm.compiler.core.common.alloc.TraceBuilderResult.TrivialTracePredicate) SingleBlockTraceBuilder(org.graalvm.compiler.core.common.alloc.SingleBlockTraceBuilder) UniDirectionalTraceBuilder(org.graalvm.compiler.core.common.alloc.UniDirectionalTraceBuilder) BiDirectionalTraceBuilder(org.graalvm.compiler.core.common.alloc.BiDirectionalTraceBuilder) DebugContext(org.graalvm.compiler.debug.DebugContext) TraceBuilderResult(org.graalvm.compiler.core.common.alloc.TraceBuilderResult)

Example 2 with TraceBuilderResult

use of org.graalvm.compiler.core.common.alloc.TraceBuilderResult in project graal by oracle.

the class TraceRegisterAllocationPhase method run.

@Override
@SuppressWarnings("try")
protected void run(TargetDescription target, LIRGenerationResult lirGenRes, AllocationContext context) {
    MoveFactory spillMoveFactory = context.spillMoveFactory;
    RegisterAllocationConfig registerAllocationConfig = context.registerAllocationConfig;
    LIR lir = lirGenRes.getLIR();
    DebugContext debug = lir.getDebug();
    TraceBuilderResult resultTraces = context.contextLookup(TraceBuilderResult.class);
    GlobalLivenessInfo livenessInfo = context.contextLookup(GlobalLivenessInfo.class);
    assert livenessInfo != null;
    TraceAllocationContext traceContext = new TraceAllocationContext(spillMoveFactory, registerAllocationConfig, resultTraces, livenessInfo);
    AllocatableValue[] cachedStackSlots = Options.TraceRACacheStackSlots.getValue(lir.getOptions()) ? new AllocatableValue[lir.numVariables()] : null;
    // currently this is not supported
    boolean neverSpillConstant = false;
    final TraceRegisterAllocationPolicy plan = DefaultTraceRegisterAllocationPolicy.allocationPolicy(target, lirGenRes, spillMoveFactory, registerAllocationConfig, cachedStackSlots, resultTraces, neverSpillConstant, livenessInfo, lir.getOptions());
    try (DebugContext.Scope s0 = debug.scope("AllocateTraces", resultTraces, livenessInfo)) {
        for (Trace trace : resultTraces.getTraces()) {
            tracesCounter.increment(debug);
            TraceAllocationPhase<TraceAllocationContext> allocator = plan.selectStrategy(trace);
            try (Indent i = debug.logAndIndent("Allocating Trace%d: %s (%s)", trace.getId(), trace, allocator);
                DebugContext.Scope s = debug.scope("AllocateTrace", trace)) {
                allocator.apply(target, lirGenRes, trace, traceContext);
            }
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    TraceGlobalMoveResolutionPhase.resolve(target, lirGenRes, traceContext);
    deconstructSSAForm(lir);
}
Also used : Indent(org.graalvm.compiler.debug.Indent) DebugContext(org.graalvm.compiler.debug.DebugContext) TraceAllocationContext(org.graalvm.compiler.lir.alloc.trace.TraceAllocationPhase.TraceAllocationContext) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) Trace(org.graalvm.compiler.core.common.alloc.Trace) LIR(org.graalvm.compiler.lir.LIR) RegisterAllocationConfig(org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig) TraceBuilderResult(org.graalvm.compiler.core.common.alloc.TraceBuilderResult) MoveFactory(org.graalvm.compiler.lir.gen.LIRGeneratorTool.MoveFactory)

Example 3 with TraceBuilderResult

use of org.graalvm.compiler.core.common.alloc.TraceBuilderResult in project graal by oracle.

the class TraceBuilderPhase method run.

@Override
protected void run(TargetDescription target, LIRGenerationResult lirGenRes, AllocationContext context) {
    AbstractBlockBase<?>[] linearScanOrder = lirGenRes.getLIR().linearScanOrder();
    AbstractBlockBase<?> startBlock = linearScanOrder[0];
    LIR lir = lirGenRes.getLIR();
    assert startBlock.equals(lir.getControlFlowGraph().getStartBlock());
    final TraceBuilderResult traceBuilderResult = getTraceBuilderResult(lir, startBlock, linearScanOrder);
    DebugContext debug = lir.getDebug();
    if (debug.isLogEnabled(DebugContext.BASIC_LEVEL)) {
        ArrayList<Trace> traces = traceBuilderResult.getTraces();
        for (int i = 0; i < traces.size(); i++) {
            Trace trace = traces.get(i);
            debug.log(DebugContext.BASIC_LEVEL, "Trace %5d: %s%s", i, trace, isTrivialTrace(lirGenRes.getLIR(), trace) ? " (trivial)" : "");
        }
    }
    TraceStatisticsPrinter.printTraceStatistics(debug, traceBuilderResult, lirGenRes.getCompilationUnitName());
    debug.dump(DebugContext.VERBOSE_LEVEL, traceBuilderResult, "TraceBuilderResult");
    context.contextAdd(traceBuilderResult);
}
Also used : TraceUtil.isTrivialTrace(org.graalvm.compiler.lir.alloc.trace.TraceUtil.isTrivialTrace) Trace(org.graalvm.compiler.core.common.alloc.Trace) LIR(org.graalvm.compiler.lir.LIR) DebugContext(org.graalvm.compiler.debug.DebugContext) TraceBuilderResult(org.graalvm.compiler.core.common.alloc.TraceBuilderResult) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase)

Example 4 with TraceBuilderResult

use of org.graalvm.compiler.core.common.alloc.TraceBuilderResult in project graal by oracle.

the class CFGPrinterObserver method dumpSandboxed.

public void dumpSandboxed(DebugContext debug, Object object, String message) {
    OptionValues options = debug.getOptions();
    boolean dumpFrontend = PrintCFG.getValue(options);
    if (!dumpFrontend && isFrontendObject(object)) {
        return;
    }
    if (cfgPrinter == null) {
        try {
            Path dumpFile = debug.getDumpPath(".cfg", false);
            cfgFile = dumpFile.toFile();
            OutputStream out = new BufferedOutputStream(new FileOutputStream(cfgFile));
            cfgPrinter = new CFGPrinter(out);
        } catch (IOException e) {
            throw (GraalError) new GraalError("Could not open %s", cfgFile == null ? "[null]" : cfgFile.getAbsolutePath()).initCause(e);
        }
    }
    if (!checkMethodScope(debug)) {
        return;
    }
    try {
        if (curMethod instanceof ResolvedJavaMethod) {
            cfgPrinter.method = (ResolvedJavaMethod) curMethod;
        }
        if (object instanceof LIR) {
            cfgPrinter.lir = (LIR) object;
        } else {
            cfgPrinter.lir = debug.contextLookup(LIR.class);
        }
        cfgPrinter.nodeLirGenerator = debug.contextLookup(NodeLIRBuilder.class);
        cfgPrinter.livenessInfo = debug.contextLookup(GlobalLivenessInfo.class);
        cfgPrinter.res = debug.contextLookup(LIRGenerationResult.class);
        if (cfgPrinter.nodeLirGenerator != null) {
            cfgPrinter.target = cfgPrinter.nodeLirGenerator.getLIRGeneratorTool().target();
        }
        if (cfgPrinter.lir != null && cfgPrinter.lir.getControlFlowGraph() instanceof ControlFlowGraph) {
            cfgPrinter.cfg = (ControlFlowGraph) cfgPrinter.lir.getControlFlowGraph();
        }
        CodeCacheProvider codeCache = debug.contextLookup(CodeCacheProvider.class);
        if (codeCache != null) {
            cfgPrinter.target = codeCache.getTarget();
        }
        if (object instanceof BciBlockMapping) {
            BciBlockMapping blockMap = (BciBlockMapping) object;
            cfgPrinter.printCFG(message, blockMap);
            if (blockMap.code.getCode() != null) {
                cfgPrinter.printBytecodes(new BytecodeDisassembler(false).disassemble(blockMap.code));
            }
        } else if (object instanceof LIR) {
            // Currently no node printing for lir
            cfgPrinter.printCFG(message, cfgPrinter.lir.codeEmittingOrder(), false);
            lastLIR = (LIR) object;
            if (delayedIntervals != null) {
                cfgPrinter.printIntervals(message, delayedIntervals);
                delayedIntervals = null;
            }
        } else if (object instanceof ScheduleResult) {
            cfgPrinter.printSchedule(message, (ScheduleResult) object);
        } else if (object instanceof StructuredGraph) {
            if (cfgPrinter.cfg == null) {
                StructuredGraph graph = (StructuredGraph) object;
                cfgPrinter.cfg = ControlFlowGraph.compute(graph, true, true, true, false);
                cfgPrinter.printCFG(message, cfgPrinter.cfg.getBlocks(), true);
            } else {
                cfgPrinter.printCFG(message, cfgPrinter.cfg.getBlocks(), true);
            }
        } else if (object instanceof CompilationResult) {
            final CompilationResult compResult = (CompilationResult) object;
            cfgPrinter.printMachineCode(disassemble(codeCache, compResult, null), message);
        } else if (object instanceof InstalledCode) {
            CompilationResult compResult = debug.contextLookup(CompilationResult.class);
            if (compResult != null) {
                cfgPrinter.printMachineCode(disassemble(codeCache, compResult, (InstalledCode) object), message);
            }
        } else if (object instanceof IntervalDumper) {
            if (lastLIR == cfgPrinter.lir) {
                cfgPrinter.printIntervals(message, (IntervalDumper) object);
            } else {
                if (delayedIntervals != null) {
                    debug.log("Some delayed intervals were dropped (%s)", delayedIntervals);
                }
                delayedIntervals = (IntervalDumper) object;
            }
        } else if (object instanceof AbstractBlockBase<?>[]) {
            cfgPrinter.printCFG(message, (AbstractBlockBase<?>[]) object, false);
        } else if (object instanceof Trace) {
            cfgPrinter.printCFG(message, ((Trace) object).getBlocks(), false);
        } else if (object instanceof TraceBuilderResult) {
            cfgPrinter.printTraces(message, (TraceBuilderResult) object);
        }
    } finally {
        cfgPrinter.target = null;
        cfgPrinter.lir = null;
        cfgPrinter.res = null;
        cfgPrinter.nodeLirGenerator = null;
        cfgPrinter.livenessInfo = null;
        cfgPrinter.cfg = null;
        cfgPrinter.flush();
    }
}
Also used : BytecodeDisassembler(org.graalvm.compiler.bytecode.BytecodeDisassembler) IntervalDumper(org.graalvm.compiler.lir.debug.IntervalDumper) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) OptionValues(org.graalvm.compiler.options.OptionValues) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) CodeCacheProvider(jdk.vm.ci.code.CodeCacheProvider) AbstractBlockBase(org.graalvm.compiler.core.common.cfg.AbstractBlockBase) LIRGenerationResult(org.graalvm.compiler.lir.gen.LIRGenerationResult) GraalError(org.graalvm.compiler.debug.GraalError) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) TraceBuilderResult(org.graalvm.compiler.core.common.alloc.TraceBuilderResult) BufferedOutputStream(java.io.BufferedOutputStream) Path(java.nio.file.Path) BciBlockMapping(org.graalvm.compiler.java.BciBlockMapping) GlobalLivenessInfo(org.graalvm.compiler.lir.alloc.trace.GlobalLivenessInfo) IOException(java.io.IOException) Trace(org.graalvm.compiler.core.common.alloc.Trace) LIR(org.graalvm.compiler.lir.LIR) FileOutputStream(java.io.FileOutputStream) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) NodeLIRBuilder(org.graalvm.compiler.core.gen.NodeLIRBuilder) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

TraceBuilderResult (org.graalvm.compiler.core.common.alloc.TraceBuilderResult)4 Trace (org.graalvm.compiler.core.common.alloc.Trace)3 DebugContext (org.graalvm.compiler.debug.DebugContext)3 LIR (org.graalvm.compiler.lir.LIR)3 AbstractBlockBase (org.graalvm.compiler.core.common.cfg.AbstractBlockBase)2 OptionValues (org.graalvm.compiler.options.OptionValues)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 CodeCacheProvider (jdk.vm.ci.code.CodeCacheProvider)1 InstalledCode (jdk.vm.ci.code.InstalledCode)1 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 BytecodeDisassembler (org.graalvm.compiler.bytecode.BytecodeDisassembler)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1 BiDirectionalTraceBuilder (org.graalvm.compiler.core.common.alloc.BiDirectionalTraceBuilder)1 RegisterAllocationConfig (org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig)1 SingleBlockTraceBuilder (org.graalvm.compiler.core.common.alloc.SingleBlockTraceBuilder)1