# HG changeset patch # User Gilles Duboscq # Date 1306760109 -7200 # Node ID b003ea36fa12bad3151764439e7c395aa1e46815 # Parent 189ffb7d1d846348c72b6b91ce9c74286b788481 Add block structure to ideal graph visualizer diff -r 189ffb7d1d84 -r b003ea36fa12 graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java --- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompilation.java Mon May 30 14:55:09 2011 +0200 @@ -282,7 +282,7 @@ } if (compiler.isObserved()) { - compiler.fireCompilationEvent(new CompilationEvent(this, "After code generation", hir.getHIRStartBlock(), false, true, targetMethod)); + compiler.fireCompilationEvent(new CompilationEvent(this, "After code generation", graph, false, true, targetMethod)); } if (C1XOptions.PrintTimers) { diff -r 189ffb7d1d84 -r b003ea36fa12 graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java --- a/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/alloc/LinearScan.java Mon May 30 14:55:09 2011 +0200 @@ -2152,7 +2152,7 @@ } if (compilation.compiler.isObserved()) { - compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, label, compilation.hir().getHIRStartBlock(), hirValid, true)); + compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, label, compilation.graph, hirValid, true)); } } diff -r 189ffb7d1d84 -r b003ea36fa12 graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java Mon May 30 14:55:09 2011 +0200 @@ -57,8 +57,8 @@ } public void compilationEvent(CompilationEvent event) { - if (event.getStartBlock() != null && !TTY.isSuppressed()) { - Graph graph = event.getStartBlock().graph(); + if (event.getGraph() != null && !TTY.isSuppressed()) { + Graph graph = event.getGraph(); String name = event.getMethod().holder().name(); name = name.substring(1, name.length() - 1).replace('/', '.'); diff -r 189ffb7d1d84 -r b003ea36fa12 graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java Mon May 30 14:55:09 2011 +0200 @@ -27,6 +27,7 @@ import java.util.Map.Entry; import com.oracle.graal.graph.*; +import com.oracle.max.graal.schedule.*; /** * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the > omittedClasses = new HashSet>(); private final PrintStream stream; + private final List noBlockNodes = new LinkedList(); /** * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream. @@ -109,8 +111,10 @@ public void print(Graph graph, String title, boolean shortNames) { stream.printf(" %n", escape(title)); + Schedule schedule = new Schedule(graph); + stream.println(" "); - List edges = printNodes(graph.getNodes(), shortNames); + List edges = printNodes(graph.getNodes(), shortNames, schedule.getNodeToBlock()); stream.println(" "); stream.println(" "); @@ -119,10 +123,17 @@ } stream.println(" "); + stream.println(" "); + for (Block block : schedule.getBlocks()) { + printBlock(block); + } + printNoBlock(); + stream.println(" "); + stream.println(" "); } - private List printNodes(Collection nodes, boolean shortNames) { + private List printNodes(Collection nodes, boolean shortNames, NodeMap nodeToBlock) { ArrayList edges = new ArrayList(); for (Node node : nodes) { @@ -143,6 +154,13 @@ } stream.printf("

%s

%n", escape(name)); } + Block block = nodeToBlock.get(node); + if (block != null) { + stream.printf("

%d

%n", block.blockID()); + } else { + stream.printf("

noBlock

%n"); + noBlockNodes.add(node); + } for (Entry entry : props.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue().toString(); @@ -177,6 +195,33 @@ stream.printf(" %n", edge.from, edge.fromIndex, edge.to, edge.toIndex); } + private void printBlock(Block block) { + stream.printf(" %n", block.blockID()); + stream.printf(" %n"); + for (Block sux : block.getSuccessors()) { + stream.printf(" %n", sux.blockID()); + } + stream.printf(" %n"); + stream.printf(" %n"); + for (Node node : block.getInstructions()) { + stream.printf(" %n", node.id()); + } + stream.printf(" %n"); + stream.printf(" %n", block.blockID()); + } + + private void printNoBlock() { + if (!noBlockNodes.isEmpty()) { + stream.printf(" %n"); + stream.printf(" %n"); + for (Node node : noBlockNodes) { + stream.printf(" %n", node.id()); + } + stream.printf(" %n"); + stream.printf(" %n"); + } + } + private String escape(String s) { s = s.replace("&", "&"); s = s.replace("<", "<"); diff -r 189ffb7d1d84 -r b003ea36fa12 graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java --- a/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinterObserver.java Mon May 30 14:55:09 2011 +0200 @@ -140,8 +140,8 @@ @Override public void compilationEvent(CompilationEvent event) { - if (printer != null && event.getStartBlock() != null) { - Graph graph = event.getStartBlock().graph(); + if (printer != null && event.getGraph() != null) { + Graph graph = event.getGraph(); printer.print(graph, event.getLabel(), true); } } diff -r 189ffb7d1d84 -r b003ea36fa12 graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Mon May 30 14:55:09 2011 +0200 @@ -194,7 +194,7 @@ } if (compilation.compiler.isObserved()) { - compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, getHIRStartBlock(), true, false)); + compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, compilation.graph, true, false)); } } diff -r 189ffb7d1d84 -r b003ea36fa12 graal/GraalCompiler/src/com/sun/c1x/observer/CompilationEvent.java --- a/graal/GraalCompiler/src/com/sun/c1x/observer/CompilationEvent.java Mon May 30 13:42:23 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/observer/CompilationEvent.java Mon May 30 14:55:09 2011 +0200 @@ -24,10 +24,10 @@ import java.util.*; +import com.oracle.graal.graph.*; import com.sun.c1x.*; import com.sun.c1x.alloc.*; import com.sun.c1x.graph.*; -import com.sun.c1x.ir.*; import com.sun.cri.ci.*; import com.sun.cri.ri.*; @@ -43,7 +43,7 @@ private final C1XCompilation compilation; private final String label; - private Instruction startBlock; + private Graph graph; private BlockMap blockMap; private int codeSize = -1; @@ -67,15 +67,15 @@ this.compilation = compilation; } - public CompilationEvent(C1XCompilation compilation, String label, Instruction startBlock, boolean hirValid, boolean lirValid) { + public CompilationEvent(C1XCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid) { this(compilation, label); - this.startBlock = startBlock; + this.graph = graph; this.hirValid = hirValid; this.lirValid = lirValid; } - public CompilationEvent(C1XCompilation compilation, String label, Instruction startBlock, boolean hirValid, boolean lirValid, CiTargetMethod targetMethod) { - this(compilation, label, startBlock, hirValid, lirValid); + public CompilationEvent(C1XCompilation compilation, String label, Graph graph, boolean hirValid, boolean lirValid, CiTargetMethod targetMethod) { + this(compilation, label, graph, hirValid, lirValid); this.targetMethod = targetMethod; } @@ -108,8 +108,8 @@ return blockMap; } - public Instruction getStartBlock() { - return startBlock; + public Graph getGraph() { + return graph; } public LinearScan getAllocator() {