# HG changeset patch # User Thomas Wuerthinger # Date 1309268885 -7200 # Node ID 0dfaf5733c63dcb0dd3f7ddcb454b5ad4fcd6201 # Parent 607c6500c22e823703a2e74345ccab57bb3b6f4c Draft GVN. diff -r 607c6500c22e -r 0dfaf5733c63 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Tue Jun 28 15:28:30 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalOptions.java Tue Jun 28 15:48:05 2011 +0200 @@ -103,6 +103,7 @@ public static boolean TraceDeadCodeElimination = ____; public static boolean TraceMemoryMaps = ____; public static boolean TraceReadElimination = ____; + public static boolean TraceGVN = ____; public static int TraceBytecodeParserLevel = 0; public static boolean QuietBailout = ____; @@ -142,6 +143,7 @@ public static boolean CommentedAssembly = ____; public static boolean PrintLIRWithAssembly = ____; + public static boolean OptGVN = true; public static boolean OptCanonicalizer = true; public static boolean OptLoops = true; } diff -r 607c6500c22e -r 0dfaf5733c63 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 Tue Jun 28 15:28:30 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java Tue Jun 28 15:48:05 2011 +0200 @@ -99,6 +99,10 @@ new CanonicalizerPhase().apply(graph); new DeadCodeEliminationPhase().apply(graph); } + + if (GraalOptions.OptGVN) { + new GlobalValueNumberingPhase().apply(graph); + } // // new EscapeAnalysisPhase().apply(graph); @@ -109,6 +113,9 @@ if (GraalOptions.Lower) { new LoweringPhase(compilation.runtime).apply(graph); new MemoryPhase().apply(graph); + if (GraalOptions.OptGVN) { + new GlobalValueNumberingPhase().apply(graph); + } new ReadEliminationPhase().apply(graph); } diff -r 607c6500c22e -r 0dfaf5733c63 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ReadNode.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ReadNode.java Tue Jun 28 15:28:30 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ReadNode.java Tue Jun 28 15:48:05 2011 +0200 @@ -47,6 +47,11 @@ } @Override + public boolean valueEqual(Node i) { + return i instanceof ReadNode; + } + + @Override public Node copy(Graph into) { return new ReadNode(super.kind, null, null, into); } diff -r 607c6500c22e -r 0dfaf5733c63 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GlobalValueNumberingPhase.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/GlobalValueNumberingPhase.java Tue Jun 28 15:48:05 2011 +0200 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 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 com.oracle.max.graal.compiler.*; +import com.oracle.max.graal.compiler.debug.*; +import com.oracle.max.graal.compiler.ir.*; +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 GlobalValueNumberingPhase extends Phase { + + @Override + protected void run(Graph graph) { + NodeBitMap visited = graph.createNodeBitMap(); + for (Node n : graph.getNodes()) { + apply(n, visited); + } + } + + private void apply(Node n, NodeBitMap visited) { + if (n != null && !visited.isMarked(n)) { + visited.mark(n); + for (Node input : n.inputs()) { + apply(input, visited); + } + Node newNode = n.graph().ideal(n); + if (GraalOptions.TraceGVN && newNode != n) { + TTY.println("GVN applied and new node is " + newNode); + } + } + } +}