# HG changeset patch # User Thomas Wuerthinger # Date 1308919586 -7200 # Node ID e237c1980f4b5dbd93de7935ad0ae90425b30f65 # Parent 16043c211a98e33f48ef6d80b3825cb0e7bfd0a4 Simplifications on ReadNode WriteNode. diff -r 16043c211a98 -r e237c1980f4b 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:35:07 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Fri Jun 24 14:46:26 2011 +0200 @@ -1446,13 +1446,13 @@ @Override public void visitMemoryRead(ReadNode memRead) { - lir.move(memRead.location().createAddress(this, memRead.object()), createResultVariable(memRead), memRead.valueKind()); + lir.move(memRead.location().createAddress(this, memRead.object()), createResultVariable(memRead), memRead.location().getValueKind()); } @Override public void visitMemoryWrite(WriteNode memWrite) { - lir.move(load(memWrite.value()), memWrite.location().createAddress(this, memWrite.object()), memWrite.valueKind()); + lir.move(load(memWrite.value()), memWrite.location().createAddress(this, memWrite.object()), memWrite.location().getValueKind()); } diff -r 16043c211a98 -r e237c1980f4b graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/AccessNode.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/AccessNode.java Fri Jun 24 14:35:07 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/AccessNode.java Fri Jun 24 14:46:26 2011 +0200 @@ -28,15 +28,13 @@ public abstract class AccessNode extends StateSplit { - private static final int INPUT_COUNT = 3; + private static final int INPUT_COUNT = 2; private static final int INPUT_NODE = 0; private static final int INPUT_GUARD = 1; - private static final int INPUT_MEMORY_STATE = 2; private static final int SUCCESSOR_COUNT = 0; private LocationNode location; - private CiKind valueKind; @Override protected int inputCount() { @@ -59,26 +57,13 @@ inputs().set(super.inputCount() + INPUT_GUARD, n); } - public GuardNode memoryState() { - return (GuardNode) inputs().get(super.inputCount() + INPUT_MEMORY_STATE); - } - - public void setMemoryState(GuardNode n) { - inputs().set(super.inputCount() + INPUT_MEMORY_STATE, n); - } - public LocationNode location() { return location; } - public CiKind valueKind() { - return valueKind; - } - public AccessNode(CiKind kind, Value object, LocationNode location, int inputCount, int successorCount, Graph graph) { - super(kind.stackKind(), INPUT_COUNT + inputCount, SUCCESSOR_COUNT + successorCount, graph); + super(kind, INPUT_COUNT + inputCount, SUCCESSOR_COUNT + successorCount, graph); this.location = location; - this.valueKind = kind; setObject(object); } diff -r 16043c211a98 -r e237c1980f4b graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LocationNode.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LocationNode.java Fri Jun 24 14:35:07 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LocationNode.java Fri Jun 24 14:46:26 2011 +0200 @@ -56,6 +56,10 @@ out.print("mem location disp is ").print(displacement); } + public CiKind getValueKind() { + return valueKind; + } + @Override public Node copy(Graph into) { return new LocationNode(identity, valueKind, displacement, into); diff -r 16043c211a98 -r e237c1980f4b graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/MemoryPhase.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/MemoryPhase.java Fri Jun 24 14:46:26 2011 +0200 @@ -0,0 +1,165 @@ +/* + * 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 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.*; + +public class MemoryPhase extends Phase { + + 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()); + } + + for (Entry> readEntry : locationToReads.entrySet()) { + 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()); + } + } + + @Override + protected void run(final Graph 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); + } + } + + 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()]); + } + } + + // Lower the instructions of this block. + for (final Node n : b.getInstructions()) { + // This memory merge node is not lowered => create a memory merge nevertheless. + if (n instanceof AbstractMemoryMergeNode) { + map.createMemoryMerge((AbstractMemoryMergeNode) n); + } else if (n instanceof ReadNode) { + ReadNode readNode = (ReadNode) n; + + } else if (n instanceof WriteNode) { + WriteNode writeNode = (WriteNode) n; + + } + } + + memoryMaps[b.blockID()] = map; + } +} diff -r 16043c211a98 -r e237c1980f4b 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:35:07 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java Fri Jun 24 14:46:26 2011 +0200 @@ -251,7 +251,7 @@ Graph graph = field.graph(); int displacement = ((HotSpotField) field.field()).offset(); assert field.kind != CiKind.Illegal; - ReadNode memoryRead = new ReadNode(field.field().kind(), field.object(), new LocationNode(field.field(), field.field().kind(), displacement, graph), graph); + ReadNode memoryRead = new ReadNode(field.field().kind().stackKind(), field.object(), new LocationNode(field.field(), field.field().kind(), displacement, graph), graph); memoryRead.setGuard((GuardNode) tool.createGuard(new IsNonNull(field.object(), graph))); memoryRead.setNext(field.next()); field.replace(memoryRead); @@ -262,7 +262,7 @@ } Graph graph = field.graph(); int displacement = ((HotSpotField) field.field()).offset(); - WriteNode memoryWrite = new WriteNode(field.field().kind(), field.object(), field.value(), new LocationNode(field.field(), field.field().kind(), displacement, graph), graph); + WriteNode memoryWrite = new WriteNode(CiKind.Illegal, 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());