# HG changeset patch # User Thomas Wuerthinger # Date 1307520765 -7200 # Node ID 3570f1f7903e492f9f9bdc17028d6e357ccb27e0 # Parent d90bf514d647549650a802dcc42ce047550b9046 Changed GraphBuilder to inherit from Phase. diff -r d90bf514d647 -r 3570f1f7903e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/GraphBuilder.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/GraphBuilder.java Wed Jun 08 08:59:54 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/GraphBuilder.java Wed Jun 08 10:12:45 2011 +0200 @@ -47,7 +47,7 @@ * A number of optimizations may be performed during parsing of the bytecode, including value * numbering, inlining, constant folding, strength reduction, etc. */ -public final class GraphBuilder { +public final class GraphBuilder extends Phase { /** * The minimum value to which {@link C1XOptions#TraceBytecodeParserLevel} must be set to trace @@ -62,7 +62,7 @@ public static final int TRACELEVEL_STATE = 2; private final C1XCompilation compilation; - private final CompilerGraph graph; + private CompilerGraph graph; private final CiStatistics stats; private final RiRuntime runtime; @@ -71,7 +71,7 @@ private final BytecodeStream stream; // the bytecode stream private final LogStream log; - private final FrameStateBuilder frameState; // the current execution state + private FrameStateBuilder frameState; // the current execution state // bci-to-block mapping private Block[] blockFromBci; @@ -97,6 +97,8 @@ private final Set blocksOnWorklist = new HashSet(); private final Set blocksVisited = new HashSet(); + private final boolean createUnwind; + /** * Creates a new, initialized, {@code GraphBuilder} instance for a given compilation. @@ -105,9 +107,8 @@ * @param ir the IR to build the graph into * @param graph */ - public GraphBuilder(C1XCompilation compilation, RiMethod method, CompilerGraph graph) { + public GraphBuilder(C1XCompilation compilation, RiMethod method, boolean createUnwind) { this.compilation = compilation; - this.graph = graph; this.runtime = compilation.runtime; this.method = method; @@ -116,7 +117,15 @@ this.stream = new BytecodeStream(method.code()); this.constantPool = runtime.getConstantPool(method); + this.createUnwind = createUnwind; + } + + @Override + protected void run(Graph graph) { + assert graph != null; + this.graph = (CompilerGraph) graph; this.frameState = new FrameStateBuilder(method, graph); + build(); } /** @@ -125,7 +134,7 @@ * @param createUnwind setting this to true will always generate an unwind block, even if there is no exception * handler and the method is not synchronized */ - public void build(boolean createUnwind) { + private void build() { if (log != null) { log.println(); log.println("Compiling " + method); diff -r d90bf514d647 -r 3570f1f7903e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Wed Jun 08 08:59:54 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Wed Jun 08 10:12:45 2011 +0200 @@ -157,7 +157,7 @@ private void buildGraph() { // Graph builder must set the startBlock and the osrEntryBlock - new GraphBuilder(compilation, compilation.method, compilation.graph).build(false); + new GraphBuilder(compilation, compilation.method, false).apply(compilation.graph); // CompilerGraph duplicate = new CompilerGraph(); // Map replacements = new HashMap(); diff -r d90bf514d647 -r 3570f1f7903e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/Inlining.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/Inlining.java Wed Jun 08 08:59:54 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/Inlining.java Wed Jun 08 10:12:45 2011 +0200 @@ -158,7 +158,7 @@ } CompilerGraph graph = new CompilerGraph(); - new GraphBuilder(compilation, method, graph).build(true); + new GraphBuilder(compilation, method, true).apply(graph); boolean withReceiver = !Modifier.isStatic(method.accessFlags()); diff -r d90bf514d647 -r 3570f1f7903e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Or.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Or.java Wed Jun 08 08:59:54 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Or.java Wed Jun 08 10:12:45 2011 +0200 @@ -52,8 +52,7 @@ @Override public Node copy(Graph into) { - Or x = new Or(kind, null, null, into); - return x; + return new Or(kind, null, null, into); } @SuppressWarnings("unchecked") @@ -68,7 +67,6 @@ private static class OrCanonicalizerOp implements CanonicalizerOp { @Override public Node canonical(Node node) { - assert node instanceof Or; Or or = (Or) node; CiKind kind = or.kind; Graph graph = or.graph(); diff -r d90bf514d647 -r 3570f1f7903e graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java Wed Jun 08 08:59:54 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/value/FrameStateBuilder.java Wed Jun 08 10:12:45 2011 +0200 @@ -46,6 +46,7 @@ private final RiMethod method; public FrameStateBuilder(RiMethod method, Graph graph) { + assert graph != null; this.method = method; this.graph = graph; this.locals = new Value[method.maxLocals()]; diff -r d90bf514d647 -r 3570f1f7903e graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Wed Jun 08 08:59:54 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Wed Jun 08 10:12:45 2011 +0200 @@ -42,7 +42,7 @@ final ArrayList predecessorsIndex; public Node(int inputCount, int successorCount, Graph graph) { - assert graph != null; + assert graph != null : "cannot create a node for a null graph"; this.graph = graph; this.id = graph.register(this); this.inputs = new NodeArray(this, inputCount);