use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class NodeLIRBuilder method matchComplexExpressions.
@SuppressWarnings("try")
protected void matchComplexExpressions(List<Node> nodes) {
if (matchRules != null) {
DebugContext debug = gen.getResult().getLIR().getDebug();
try (DebugContext.Scope s = debug.scope("MatchComplexExpressions")) {
if (LogVerbose.getValue(nodeOperands.graph().getOptions())) {
int i = 0;
for (Node node : nodes) {
debug.log("%d: (%s) %1S", i++, node.getUsageCount(), node);
}
}
// Match the nodes in backwards order to encourage longer matches.
for (int index = nodes.size() - 1; index >= 0; index--) {
Node node = nodes.get(index);
if (getOperand(node) != null) {
continue;
}
// See if this node is the root of any MatchStatements
List<MatchStatement> statements = matchRules.get(node.getClass());
if (statements != null) {
for (MatchStatement statement : statements) {
if (statement.generate(this, index, node, nodes)) {
// Found a match so skip to the next
break;
}
}
}
}
}
}
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class NodeLIRBuilder method doBlock.
@Override
@SuppressWarnings("try")
public void doBlock(Block block, StructuredGraph graph, BlockMap<List<Node>> blockMap) {
OptionValues options = graph.getOptions();
try (BlockScope blockScope = gen.getBlockScope(block)) {
setSourcePosition(null);
if (block == gen.getResult().getLIR().getControlFlowGraph().getStartBlock()) {
assert block.getPredecessorCount() == 0;
emitPrologue(graph);
} else {
assert block.getPredecessorCount() > 0;
// create phi-in value array
AbstractBeginNode begin = block.getBeginNode();
if (begin instanceof AbstractMergeNode) {
AbstractMergeNode merge = (AbstractMergeNode) begin;
LabelOp label = (LabelOp) gen.getResult().getLIR().getLIRforBlock(block).get(0);
label.setPhiValues(createPhiIn(merge));
if (Options.PrintIRWithLIR.getValue(options) && !TTY.isSuppressed()) {
TTY.println("Created PhiIn: " + label);
}
}
}
doBlockPrologue(block, options);
List<Node> nodes = blockMap.get(block);
// Allow NodeLIRBuilder subclass to specialize code generation of any interesting groups
// of instructions
matchComplexExpressions(nodes);
boolean trace = traceLIRGeneratorLevel >= 3;
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
if (node instanceof ValueNode) {
DebugContext debug = node.getDebug();
ValueNode valueNode = (ValueNode) node;
if (trace) {
TTY.println("LIRGen for " + valueNode);
}
Value operand = getOperand(valueNode);
if (operand == null) {
if (!peephole(valueNode)) {
try {
doRoot(valueNode);
} catch (GraalError e) {
throw GraalGraphError.transformAndAddContext(e, valueNode);
} catch (Throwable e) {
throw new GraalGraphError(e).addContext(valueNode);
}
}
} else if (ComplexMatchValue.INTERIOR_MATCH.equals(operand)) {
// Doesn't need to be evaluated
debug.log("interior match for %s", valueNode);
} else if (operand instanceof ComplexMatchValue) {
debug.log("complex match for %s", valueNode);
ComplexMatchValue match = (ComplexMatchValue) operand;
operand = match.evaluate(this);
if (operand != null) {
setResult(valueNode, operand);
}
} else {
// There can be cases in which the result of an instruction is already set
// before by other instructions.
}
}
}
if (!gen.hasBlockEnd(block)) {
NodeIterable<Node> successors = block.getEndNode().successors();
assert successors.count() == block.getSuccessorCount();
if (block.getSuccessorCount() != 1) {
/*
* If we have more than one successor, we cannot just use the first one. Since
* successors are unordered, this would be a random choice.
*/
throw new GraalError("Block without BlockEndOp: " + block.getEndNode());
}
gen.emitJump(getLIRBlock((FixedNode) successors.first()));
}
assert verifyBlock(gen.getResult().getLIR(), block);
}
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class NodeLIRBuilder method doRoot.
private void doRoot(ValueNode instr) {
if (traceLIRGeneratorLevel >= 2) {
TTY.println("Emitting LIR for instruction " + instr);
}
currentInstruction = instr;
DebugContext debug = instr.getDebug();
debug.log("Visiting %s", instr);
emitNode(instr);
debug.log("Operand for %s = %s", instr, getOperand(instr));
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class InvokeGraal method compileAndInstallMethod.
/**
* The simplest way to compile a method, using the default behavior for everything.
*/
@SuppressWarnings("try")
protected InstalledCode compileAndInstallMethod(ResolvedJavaMethod method) {
/* Create a unique compilation identifier, visible in IGV. */
CompilationIdentifier compilationId = backend.getCompilationIdentifier(method);
OptionValues options = getInitialOptions();
DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
try (DebugContext.Scope s = debug.scope("compileAndInstallMethod", new DebugDumpScope(String.valueOf(compilationId), true))) {
/*
* The graph that is compiled. We leave it empty (no nodes added yet). This means that
* it will be filled according to the graphBuilderSuite defined below. We also specify
* that we want the compilation to make optimistic assumptions about runtime state such
* as the loaded class hierarchy.
*/
StructuredGraph graph = new StructuredGraph.Builder(options, debug, AllowAssumptions.YES).method(method).compilationId(compilationId).build();
/*
* The phases used to build the graph. Usually this is just the GraphBuilderPhase. If
* the graph already contains nodes, it is ignored.
*/
PhaseSuite<HighTierContext> graphBuilderSuite = backend.getSuites().getDefaultGraphBuilderSuite();
/*
* The optimization phases that are applied to the graph. This is the main configuration
* point for Graal. Add or remove phases to customize your compilation.
*/
Suites suites = backend.getSuites().getDefaultSuites(options);
/*
* The low-level phases that are applied to the low-level representation.
*/
LIRSuites lirSuites = backend.getSuites().getDefaultLIRSuites(options);
/*
* We want Graal to perform all speculative optimistic optimizations, using the
* profiling information that comes with the method (collected by the interpreter) for
* speculation.
*/
OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL;
ProfilingInfo profilingInfo = graph.getProfilingInfo(method);
/* The default class and configuration for compilation results. */
CompilationResult compilationResult = new CompilationResult(graph.compilationId());
CompilationResultBuilderFactory factory = CompilationResultBuilderFactory.Default;
/* Invoke the whole Graal compilation pipeline. */
GraalCompiler.compileGraph(graph, method, providers, backend, graphBuilderSuite, optimisticOpts, profilingInfo, suites, lirSuites, compilationResult, factory);
/*
* Install the compilation result into the VM, i.e., copy the byte[] array that contains
* the machine code into an actual executable memory location.
*/
return backend.addInstalledCode(debug, method, asCompilationRequest(compilationId), compilationResult);
} catch (Throwable ex) {
throw debug.handle(ex);
}
}
use of org.graalvm.compiler.debug.DebugContext in project graal by oracle.
the class GraalCompiler method compile.
/**
* Services a given compilation request.
*
* @return the result of the compilation
*/
@SuppressWarnings("try")
public static <T extends CompilationResult> T compile(Request<T> r) {
DebugContext debug = r.graph.getDebug();
try (CompilationAlarm alarm = CompilationAlarm.trackCompilationPeriod(r.graph.getOptions())) {
assert !r.graph.isFrozen();
try (DebugContext.Scope s0 = debug.scope("GraalCompiler", r.graph, r.providers.getCodeCache());
DebugCloseable a = CompilerTimer.start(debug)) {
emitFrontEnd(r.providers, r.backend, r.graph, r.graphBuilderSuite, r.optimisticOpts, r.profilingInfo, r.suites);
emitBackEnd(r.graph, null, r.installedCodeOwner, r.backend, r.compilationResult, r.factory, null, r.lirSuites);
} catch (Throwable e) {
throw debug.handle(e);
}
checkForRequestedCrash(r.graph);
return r.compilationResult;
}
}
Aggregations