# HG changeset patch # User Thomas Wuerthinger # Date 1308918907 -7200 # Node ID 16043c211a98e33f48ef6d80b3825cb0e7bfd0a4 # Parent 6202a6bb6726188994a51a2efa3472d228951c31 Towards splitting the lowering and the memory graph creation phases. diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java --- 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()); } diff -r 6202a6bb6726 -r 16043c211a98 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 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); diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/AbstractMemoryMergeNode.java --- 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.*; diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryMergeNode.java --- 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.*; diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryWrite.java --- 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); - } -} diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java --- 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); diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/WriteNode.java --- /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); + } +} diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/LoweringPhase.java --- 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 locationToWrite; - private HashMap> locationToReads; - - public MemoryMap(Block b, MemoryMap memoryMap) { - this(b); - } - - public MemoryMap(Block b) { - block = b; - locationToWrite = new HashMap(); - locationToReads = new HashMap>(); - 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 writeEntry : locationToWrite.entrySet()) { - memMerge.mergedNodes().add(writeEntry.getValue()); - } - - TTY.println("entrySet size" + locationToReads.entrySet()); - for (Entry> 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()); - } - 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 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 create a memory merge nevertheless. - if (n instanceof AbstractMemoryMergeNode) { - loweringTool.createMemoryMerge(n); - } } } } diff -r 6202a6bb6726 -r 16043c211a98 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java --- 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());