changeset 3070:16043c211a98

Towards splitting the lowering and the memory graph creation phases.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Fri, 24 Jun 2011 14:35:07 +0200
parents 6202a6bb6726
children e237c1980f4b
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/AbstractMemoryMergeNode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryMergeNode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryWrite.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/WriteNode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java
diffstat 9 files changed, 74 insertions(+), 219 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Fri Jun 24 14:21:12 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Fri Jun 24 14:35:07 2011 +0200
@@ -1451,7 +1451,7 @@
 
 
     @Override
-    public void visitMemoryWrite(MemoryWrite memWrite) {
+    public void visitMemoryWrite(WriteNode memWrite) {
         lir.move(load(memWrite.value()), memWrite.location().createAddress(this, memWrite.object()), memWrite.valueKind());
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Fri Jun 24 14:21:12 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/IR.java	Fri Jun 24 14:35:07 2011 +0200
@@ -108,6 +108,7 @@
 
         if (GraalOptions.Lower) {
             new LoweringPhase(compilation.runtime).apply(graph);
+            new MemoryPhase().apply(graph);
         }
 
         IdentifyBlocksPhase schedule = new IdentifyBlocksPhase(true);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/AbstractMemoryMergeNode.java	Fri Jun 24 14:21:12 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/AbstractMemoryMergeNode.java	Fri Jun 24 14:35:07 2011 +0200
@@ -24,7 +24,6 @@
 
 import java.util.*;
 
-import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.graph.*;
 import com.sun.cri.ci.*;
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryMergeNode.java	Fri Jun 24 14:21:12 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryMergeNode.java	Fri Jun 24 14:35:07 2011 +0200
@@ -22,8 +22,6 @@
  */
 package com.oracle.max.graal.compiler.ir;
 
-import java.util.*;
-
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.graph.*;
 import com.sun.cri.ci.*;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryWrite.java	Fri Jun 24 14:21:12 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
- * 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.ir;
-
-import com.oracle.max.graal.compiler.debug.*;
-import com.oracle.max.graal.graph.*;
-import com.sun.cri.ci.*;
-import com.sun.cri.ri.*;
-
-
-public final class MemoryWrite extends AccessNode {
-    private static final int INPUT_COUNT = 1;
-    private static final int INPUT_VALUE = 0;
-    private static final int SUCCESSOR_COUNT = 0;
-
-    @Override
-    protected int inputCount() {
-        return super.inputCount() + INPUT_COUNT;
-    }
-
-    public Value value() {
-        return (Value) inputs().get(super.inputCount() + INPUT_VALUE);
-    }
-
-    public void setValue(Value v) {
-        inputs().set(super.inputCount() + INPUT_VALUE, v);
-    }
-
-    public MemoryWrite(CiKind kind, Value object, Value value, LocationNode location, Graph graph) {
-        super(kind, object, location, INPUT_COUNT, SUCCESSOR_COUNT, graph);
-        setValue(value);
-    }
-
-    @Override
-    public void accept(ValueVisitor v) {
-        v.visitMemoryWrite(this);
-    }
-
-    @Override
-    public void print(LogStream out) {
-        out.print("mem write to ").print(object()).print(" with value").print(value());
-    }
-
-    @Override
-    public Node copy(Graph into) {
-        return new MemoryWrite(super.kind, null, null, null, into);
-    }
-}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java	Fri Jun 24 14:21:12 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java	Fri Jun 24 14:35:07 2011 +0200
@@ -52,7 +52,7 @@
     public abstract void visitLogic(Logic i);
     public abstract void visitLookupSwitch(LookupSwitch i);
     public abstract void visitMemoryRead(ReadNode i);
-    public abstract void visitMemoryWrite(MemoryWrite i);
+    public abstract void visitMemoryWrite(WriteNode i);
     public abstract void visitMonitorAddress(MonitorAddress monitorAddress);
     public abstract void visitMonitorEnter(MonitorEnter i);
     public abstract void visitMonitorExit(MonitorExit i);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/WriteNode.java	Fri Jun 24 14:35:07 2011 +0200
@@ -0,0 +1,67 @@
+/*
+ * 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.ir;
+
+import com.oracle.max.graal.compiler.debug.*;
+import com.oracle.max.graal.graph.*;
+import com.sun.cri.ci.*;
+
+
+public final class WriteNode extends AccessNode {
+    private static final int INPUT_COUNT = 1;
+    private static final int INPUT_VALUE = 0;
+    private static final int SUCCESSOR_COUNT = 0;
+
+    @Override
+    protected int inputCount() {
+        return super.inputCount() + INPUT_COUNT;
+    }
+
+    public Value value() {
+        return (Value) inputs().get(super.inputCount() + INPUT_VALUE);
+    }
+
+    public void setValue(Value v) {
+        inputs().set(super.inputCount() + INPUT_VALUE, v);
+    }
+
+    public WriteNode(CiKind kind, Value object, Value value, LocationNode location, Graph graph) {
+        super(kind, object, location, INPUT_COUNT, SUCCESSOR_COUNT, graph);
+        setValue(value);
+    }
+
+    @Override
+    public void accept(ValueVisitor v) {
+        v.visitMemoryWrite(this);
+    }
+
+    @Override
+    public void print(LogStream out) {
+        out.print("mem write to ").print(object()).print(" with value").print(value());
+    }
+
+    @Override
+    public Node copy(Graph into) {
+        return new WriteNode(super.kind, null, null, null, into);
+    }
+}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java	Fri Jun 24 14:21:12 2011 +0200
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java	Fri Jun 24 14:35:07 2011 +0200
@@ -23,10 +23,7 @@
 package com.oracle.max.graal.compiler.phases;
 
 import java.util.*;
-import java.util.Map.Entry;
 
-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.compiler.schedule.*;
 import com.oracle.max.graal.graph.*;
@@ -43,134 +40,23 @@
     };
 
     private final RiRuntime runtime;
-    private Graph currentGraph;
 
     public LoweringPhase(RiRuntime runtime) {
         this.runtime = runtime;
     }
 
-    public static class MemoryMap {
-
-        private final Block block;
-        private HashMap<Object, Node> locationToWrite;
-        private HashMap<Object, List<Node>> locationToReads;
-
-        public MemoryMap(Block b, MemoryMap memoryMap) {
-            this(b);
-        }
-
-        public MemoryMap(Block b) {
-            block = b;
-            locationToWrite = new HashMap<Object, Node>();
-            locationToReads = new HashMap<Object, List<Node>>();
-            if (GraalOptions.TraceMemoryMaps) {
-                TTY.println("Creating new memory map for block B" + b.blockID());
-            }
-        }
-
-        public void mergeWith(MemoryMap memoryMap) {
-            if (GraalOptions.TraceMemoryMaps) {
-                TTY.println("Merging with memory map of block B" + memoryMap.block.blockID());
-            }
-        }
-
-        public void createMemoryMerge(AbstractMemoryMergeNode memMerge) {
-            if (GraalOptions.TraceMemoryMaps) {
-                TTY.println("Creating memory merge at node " + memMerge.id());
-            }
-
-            for (Entry<Object, Node> writeEntry : locationToWrite.entrySet()) {
-                memMerge.mergedNodes().add(writeEntry.getValue());
-            }
-
-            TTY.println("entrySet size" + locationToReads.entrySet());
-            for (Entry<Object, List<Node>> readEntry : locationToReads.entrySet()) {
-                TTY.println(readEntry.getValue().toString());
-                memMerge.mergedNodes().addAll(readEntry.getValue());
-            }
-
-            locationToReads.clear();
-            locationToWrite.clear();
-        }
-
-        public void registerWrite(Object location, Node node) {
-            if (GraalOptions.TraceMemoryMaps) {
-                TTY.println("Register write to " + location + " at node " + node.id());
-            }
-
-            if (locationToWrite.containsKey(location)) {
-                Node prevWrite = locationToWrite.get(location);
-                node.inputs().add(prevWrite);
-            }
-
-            if (locationToReads.containsKey(location)) {
-                for (Node prevRead : locationToReads.get(location)) {
-                    node.inputs().add(prevRead);
-                }
-            }
-            locationToWrite.put(location, node);
-            locationToReads.remove(location);
-        }
-
-        public void registerRead(Object location, Node node) {
-            if (GraalOptions.TraceMemoryMaps) {
-                TTY.println("Register read to " + location + " at node " + node.id());
-            }
-
-            if (locationToWrite.containsKey(location)) {
-                Node prevWrite = locationToWrite.get(location);
-                node.inputs().add(prevWrite);
-            }
-
-            if (!locationToReads.containsKey(location)) {
-                locationToReads.put(location, new ArrayList<Node>());
-            }
-            locationToReads.get(location).add(node);
-            TTY.println("entrySet size" + locationToReads.entrySet());
-        }
-
-        public Node getMemoryState(Object location) {
-            return null;
-        }
-    }
-
     @Override
     protected void run(final Graph graph) {
-        this.currentGraph = graph;
         final IdentifyBlocksPhase s = new IdentifyBlocksPhase(false);
         s.apply(graph);
 
         List<Block> blocks = s.getBlocks();
-        MemoryMap[] memoryMaps = new MemoryMap[blocks.size()];
         for (final Block b : blocks) {
-            process(b, memoryMaps);
+            process(b);
         }
     }
 
-    private void process(final Block b, MemoryMap[] memoryMaps) {
-        // Visit every block at most once.
-        if (memoryMaps[b.blockID()] != null) {
-            return;
-        }
-
-        // Process predecessors before this block.
-        for (Block pred : b.getPredecessors()) {
-            process(pred, memoryMaps);
-        }
-
-        // Create initial memory map for the block.
-        MemoryMap map = null;
-        if (b.getPredecessors().size() == 0) {
-            map = new MemoryMap(b);
-        } else {
-            map = new MemoryMap(b, memoryMaps[b.getPredecessors().get(0).blockID()]);
-            for (int i=1; i<b.getPredecessors().size(); ++i) {
-                map.mergeWith(memoryMaps[b.getPredecessors().get(0).blockID()]);
-            }
-        }
-        final MemoryMap finalMap = map;
-        memoryMaps[b.blockID()] = finalMap;
-
+    private void process(final Block b) {
         final CiLoweringTool loweringTool = new CiLoweringTool() {
 
             @Override
@@ -192,34 +78,11 @@
                         return guard;
                     }
                 }
-                GuardNode newGuard = new GuardNode(currentGraph);
+                GuardNode newGuard = new GuardNode(anchor.graph());
                 newGuard.setAnchor(anchor);
                 newGuard.setNode((BooleanNode) condition);
                 return newGuard;
             }
-
-            @Override
-            public void createMemoryMerge(Node node) {
-                assert node instanceof AbstractMemoryMergeNode;
-                AbstractMemoryMergeNode memMerge = (AbstractMemoryMergeNode) node;
-                assert memMerge.mergedNodes().size() == 0;
-                finalMap.createMemoryMerge(memMerge);
-            }
-
-            @Override
-            public void registerRead(Object location, Node node) {
-                finalMap.registerRead(location, node);
-            }
-
-            @Override
-            public void registerWrite(Object location, Node node) {
-                finalMap.registerWrite(location, node);
-            }
-
-            @Override
-            public Node getMemoryState(Object location) {
-                return finalMap.getMemoryState(location);
-            }
         };
 
         // Lower the instructions of this block.
@@ -228,11 +91,6 @@
                 LoweringOp op = n.lookup(LoweringOp.class);
                 if (op != null) {
                     op.lower(n, loweringTool);
-                } else {
-                    // This memory merge node is not lowered => create a memory merge nevertheless.
-                    if (n instanceof AbstractMemoryMergeNode) {
-                        loweringTool.createMemoryMerge(n);
-                    }
                 }
             }
         }
--- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java	Fri Jun 24 14:21:12 2011 +0200
+++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java	Fri Jun 24 14:35:07 2011 +0200
@@ -262,7 +262,7 @@
             }
             Graph graph = field.graph();
             int displacement = ((HotSpotField) field.field()).offset();
-            MemoryWrite memoryWrite = new MemoryWrite(field.field().kind(), field.object(), field.value(), new LocationNode(field.field(), field.field().kind(), displacement, graph), graph);
+            WriteNode memoryWrite = new WriteNode(field.field().kind(), field.object(), field.value(), new LocationNode(field.field(), field.field().kind(), displacement, graph), graph);
             memoryWrite.setGuard((GuardNode) tool.createGuard(new IsNonNull(field.object(), graph)));
             memoryWrite.setStateAfter(field.stateAfter());
             memoryWrite.setNext(field.next());