# HG changeset patch # User Thomas Wuerthinger # Date 1307527194 -7200 # Node ID 385a4d7c2a785e397a2303d950fbccab2056277e # Parent 7f584bf507ed8f32c0e75c9b9a00446ac06a3d0c Added new duplication phase (for verification). Fixes in Node.copy method implementations. diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/C1XOptions.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/C1XOptions.java Wed Jun 08 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/C1XOptions.java Wed Jun 08 11:59:54 2011 +0200 @@ -62,7 +62,6 @@ public static String PrintFilter = null; // printing settings - public static boolean PrintHIR = ____; public static boolean PrintLIR = ____; public static boolean PrintCFGToFile = ____; diff -r 7f584bf507ed -r 385a4d7c2a78 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 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Wed Jun 08 11:59:54 2011 +0200 @@ -84,7 +84,6 @@ if (C1XOptions.OptCanonicalizer) { new CanonicalizerPhase().apply(graph); - verifyAndPrint("After canonicalization"); } // Split critical edges. @@ -165,7 +164,7 @@ // duplicate.addDuplicate(compilation.graph.getNodes(), replacements); // compilation.graph = duplicate; - verifyAndPrint("After graph building"); + new DuplicationPhase().apply(compilation.graph); DeadCodeEliminationPhase dce = new DeadCodeEliminationPhase(); dce.apply(compilation.graph); @@ -190,36 +189,17 @@ return orderedBlocks; } - private void print(boolean cfgOnly) { - if (!TTY.isSuppressed()) { - TTY.println("IR for " + compilation.method); - final InstructionPrinter ip = new InstructionPrinter(TTY.out()); - final BlockPrinter bp = new BlockPrinter(this, ip, cfgOnly); - //getHIRStartBlock().iteratePreOrder(bp); - } - } - /** * Verifies the IR and prints it out if the relevant options are set. * @param phase the name of the phase for printing */ public void verifyAndPrint(String phase) { - if (C1XOptions.PrintHIR && !TTY.isSuppressed()) { - TTY.println(phase); - print(false); - } - if (compilation.compiler.isObserved()) { compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, compilation.graph, true, false)); } } public void printGraph(String phase, Graph graph) { - if (C1XOptions.PrintHIR && !TTY.isSuppressed()) { - TTY.println(phase); - print(false); - } - if (compilation.compiler.isObserved()) { compilation.compiler.fireCompilationEvent(new CompilationEvent(compilation, phase, graph, true, false)); } diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/If.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/If.java Wed Jun 08 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/If.java Wed Jun 08 11:59:54 2011 +0200 @@ -114,6 +114,6 @@ @Override public Node copy(Graph into) { - return new If(compare(), into); + return new If(null, into); } } diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LeftShift.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LeftShift.java Wed Jun 08 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LeftShift.java Wed Jun 08 11:59:54 2011 +0200 @@ -47,7 +47,7 @@ @Override public Node copy(Graph into) { - LeftShift ls = new LeftShift(kind, null, null, graph()); + LeftShift ls = new LeftShift(kind, null, null, into); return ls; } diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RightShift.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RightShift.java Wed Jun 08 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/RightShift.java Wed Jun 08 11:59:54 2011 +0200 @@ -47,7 +47,7 @@ @Override public Node copy(Graph into) { - RightShift rs = new RightShift(kind, null, null, graph()); + RightShift rs = new RightShift(kind, null, null, into); return rs; } diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/UnsignedRightShift.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/UnsignedRightShift.java Wed Jun 08 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/UnsignedRightShift.java Wed Jun 08 11:59:54 2011 +0200 @@ -47,7 +47,7 @@ @Override public Node copy(Graph into) { - UnsignedRightShift x = new UnsignedRightShift(kind, null, null, graph()); + UnsignedRightShift x = new UnsignedRightShift(kind, null, null, into); return x; } diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DuplicationPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/DuplicationPhase.java Wed Jun 08 11:59:54 2011 +0200 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.max.graal.compiler.phases; + +import java.util.*; + +import com.oracle.max.graal.compiler.graph.*; +import com.oracle.max.graal.graph.*; + +/** + * Duplicates every node in the graph to test the implementation of the {@link com.oracle.max.graal.graph.Node#copy()} method in node subclasses. + */ +public class DuplicationPhase extends Phase { + + @Override + protected void run(Graph graph) { + + // Create duplicate graph. + CompilerGraph duplicate = new CompilerGraph(); + Map replacements = new HashMap(); + replacements.put(graph.start(), duplicate.start()); + duplicate.addDuplicate(graph.getNodes(), replacements); + + // Delete nodes in original graph. + for (Node n : graph.getNodes()) { + if (n != null && n != graph.start()) { + n.forceDelete(); + } + } + + // Copy nodes from duplicate back to original graph. + replacements.clear(); + replacements.put(duplicate.start(), graph.start()); + graph.addDuplicate(duplicate.getNodes(), replacements); + } +} diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java Wed Jun 08 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Graph.java Wed Jun 08 11:59:54 2011 +0200 @@ -84,6 +84,7 @@ // create node duplicates for (Node node : nodes) { if (node != null && !replacements.containsKey(node)) { + assert node.graph != this; Node newNode = node.copy(this); assert newNode.getClass() == node.getClass(); newNodes.put(node, newNode); diff -r 7f584bf507ed -r 385a4d7c2a78 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 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/Node.java Wed Jun 08 11:59:54 2011 +0200 @@ -115,6 +115,18 @@ public boolean isDeleted() { return id == DeletedID; } + + public void forceDelete() { + for (Node n : usages) { + n.inputs.silentRemove(this); + } + for (Node n : predecessors) { + n.successors.silentRemove(this); + } + usages.clear(); + predecessors.clear(); + predecessorsIndex.clear(); + } public void delete() { assert !isDeleted(); diff -r 7f584bf507ed -r 385a4d7c2a78 graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java --- a/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java Wed Jun 08 11:35:18 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java Wed Jun 08 11:59:54 2011 +0200 @@ -44,15 +44,21 @@ private Node self() { return this.node; } + + Node silentSet(int index, Node node) { + Node result = nodes[index]; + nodes[index] = node; + return result; + } @Override public Node set(int index, Node node) { - assert node == Node.Null || node.graph == self().graph : "node is from different graph: (this=" + this + ") and (node=" + node + ")"; + assert node == Node.Null || node.graph == self().graph : "node is from different graph: (this=" + self() + ") and (node=" + node + ")"; assert node == Node.Null || node.id() != Node.DeletedID : "inserted node must not be deleted"; Node old = nodes[index]; if (old != node) { - nodes[index] = node; + silentSet(index, node); if (self().inputs == this) { if (old != null) { old.usages.remove(self()); @@ -107,6 +113,10 @@ } return false; } + + public int remove(Node n) { + return replace(n, null); + } public int replace(Node toReplace, Node replacement) { int result = 0; @@ -118,6 +128,21 @@ } return result; } + + int silentRemove(Node n) { + return silentReplace(n, null); + } + + int silentReplace(Node toReplace, Node replacement) { + int result = 0; + for (int i = 0; i < nodes.length; i++) { + if (nodes[i] == toReplace) { + silentSet(i, replacement); + result++; + } + } + return result; + } public void setAndClear(int index, Node clearedNode, int clearedIndex) { assert self().successors == this;