use of org.graalvm.compiler.graph.Graph in project graal by oracle.
the class UnsafeEATest method postEACanonicalizeGraph.
@Override
protected void postEACanonicalizeGraph() {
// Simplify any UnpackEndianHalfNode so we end up with constants.
Graph.Mark mark = graph.getMark();
for (UnpackEndianHalfNode node : graph.getNodes().filter(UnpackEndianHalfNode.class)) {
node.lower(getTarget().arch.getByteOrder());
}
new CanonicalizerPhase().applyIncremental(graph, context, mark);
}
use of org.graalvm.compiler.graph.Graph in project graal by oracle.
the class GraphPrinterDumpHandler method getInlineContext.
private List<String> getInlineContext(Graph graph) {
List<String> result = inlineContextMap.get(graph);
if (result == null) {
result = new ArrayList<>();
Object lastMethodOrGraph = null;
boolean graphSeen = false;
DebugContext debug = graph.getDebug();
for (Object o : debug.context()) {
if (o == graph) {
graphSeen = true;
}
if (o instanceof DebugDumpScope) {
DebugDumpScope debugDumpScope = (DebugDumpScope) o;
if (debugDumpScope.decorator && !result.isEmpty()) {
result.set(result.size() - 1, debugDumpScope.name + ":" + result.get(result.size() - 1));
} else {
result.add(debugDumpScope.name);
}
} else {
addMethodContext(result, o, lastMethodOrGraph);
}
if (o instanceof JavaMethod || o instanceof Graph) {
lastMethodOrGraph = o;
}
}
if (result.size() == 2 && result.get(1).startsWith("TruffleGraal")) {
result.clear();
result.add("Graal Graphs");
}
if (result.isEmpty()) {
result.add(graph.toString());
graphSeen = true;
}
// Reverse list such that inner method comes after outer method.
Collections.reverse(result);
if (!graphSeen) {
/*
* The graph isn't in any context but is being processed within another graph so add
* it to the end of the scopes.
*/
if (asJavaMethod(graph) != null) {
addMethodContext(result, graph, lastMethodOrGraph);
} else {
result.add(graph.toString());
}
}
inlineContextMap.put(graph, result);
}
return result;
}
use of org.graalvm.compiler.graph.Graph in project graal by oracle.
the class GraphPrinterDumpHandler method dump.
@Override
@SuppressWarnings("try")
public void dump(DebugContext debug, Object object, final String format, Object... arguments) {
OptionValues options = debug.getOptions();
if (object instanceof Graph && DebugOptions.PrintGraph.getValue(options)) {
final Graph graph = (Graph) object;
ensureInitialized(debug, graph);
if (printer == null) {
return;
}
// Get all current JavaMethod instances in the context.
List<String> inlineContext = getInlineContext(graph);
if (inlineContext != previousInlineContext) {
Map<Object, Object> properties = new HashMap<>();
properties.put("graph", graph.toString());
addCompilationId(properties, graph);
if (inlineContext.equals(previousInlineContext)) {
/*
* two different graphs have the same inline context, so make sure they appear
* in different folders by closing and reopening the top scope.
*/
int inlineDepth = previousInlineContext.size() - 1;
closeScope(debug, inlineDepth);
openScope(debug, inlineContext.get(inlineDepth), inlineDepth, properties);
} else {
// Check for method scopes that must be closed since the previous dump.
for (int i = 0; i < previousInlineContext.size(); ++i) {
if (i >= inlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
for (int inlineDepth = previousInlineContext.size() - 1; inlineDepth >= i; --inlineDepth) {
closeScope(debug, inlineDepth);
}
break;
}
}
// Check for method scopes that must be opened since the previous dump.
for (int i = 0; i < inlineContext.size(); ++i) {
if (i >= previousInlineContext.size() || !inlineContext.get(i).equals(previousInlineContext.get(i))) {
for (int inlineDepth = i; inlineDepth < inlineContext.size(); ++inlineDepth) {
openScope(debug, inlineContext.get(inlineDepth), inlineDepth, inlineDepth == inlineContext.size() - 1 ? properties : null);
}
break;
}
}
}
}
// Save inline context for next dump.
previousInlineContext = inlineContext;
// Capture before creating the sandbox
String currentScopeName = debug.getCurrentScopeName();
try (DebugContext.Scope s = debug.sandbox("PrintingGraph", null)) {
// Finally, output the graph.
Map<Object, Object> properties = new HashMap<>();
properties.put("graph", graph.toString());
properties.put("scope", currentScopeName);
if (graph instanceof StructuredGraph) {
properties.put("compilationIdentifier", ((StructuredGraph) graph).compilationId());
try {
int size = NodeCostUtil.computeGraphSize((StructuredGraph) graph);
properties.put("node-cost graph size", size);
} catch (Throwable t) {
properties.put("node-cost-exception", t.getMessage());
}
}
printer.print(debug, graph, properties, nextDumpId(), format, arguments);
} catch (IOException e) {
handleException(debug, e);
} catch (Throwable e) {
throw debug.handle(e);
}
}
}
Aggregations