# HG changeset patch # User Thomas Wuerthinger # Date 1308247766 -7200 # Node ID ac6fb0c93ffb0b66c662173a8f3bc8b59e806157 # Parent 6264ecd38bc251505926ab1e28de8685d44bfb5e Towards lowering (example lowering for field access). diff -r 6264ecd38bc2 -r ac6fb0c93ffb 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 Thu Jun 16 18:31:16 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Thu Jun 16 20:09:26 2011 +0200 @@ -701,6 +701,10 @@ @Override public void visitFixedGuard(FixedGuard fixedGuard) { Node comp = fixedGuard.node(); + emitGuardComp(comp); + } + + public void emitGuardComp(Node comp) { if (comp instanceof IsNonNull) { IsNonNull x = (IsNonNull) comp; CiValue value = load(x.object()); @@ -708,7 +712,7 @@ lir.nullCheck(value, info); } else if (comp instanceof IsType) { IsType x = (IsType) comp; - CiValue value = load(x.object()); + load(x.object()); LIRDebugInfo info = stateFor(x); XirArgument clazz = toXirArgument(x.type().getEncoding(Representation.ObjectHub)); XirSnippet typeCheck = xir.genTypeCheck(site(x), toXirArgument(x.object()), clazz, x.type()); @@ -1420,6 +1424,14 @@ lir.jump(getLIRBlock(end.merge())); } + @Override + public void visitMemoryRead(MemoryRead memRead) { + if (memRead.guard() != null) { + emitGuardComp(memRead.guard()); + } + lir.move(new CiAddress(memRead.valueKind(), load(memRead.location()), memRead.displacement()), createResultVariable(memRead), memRead.valueKind()); + } + @Override public void visitLoopEnd(LoopEnd x) { diff -r 6264ecd38bc2 -r ac6fb0c93ffb graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoadField.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoadField.java Thu Jun 16 18:31:16 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/LoadField.java Thu Jun 16 20:09:26 2011 +0200 @@ -36,6 +36,7 @@ */ public final class LoadField extends AccessField { private static final LoadFieldCanonicalizerOp CANONICALIZER = new LoadFieldCanonicalizerOp(); + private static final LoadFieldLoweringOp LOWERING = new LoadFieldLoweringOp(); private static final int INPUT_COUNT = 0; private static final int SUCCESSOR_COUNT = 0; @@ -118,6 +119,8 @@ public T lookup(Class clazz) { if (clazz == CanonicalizerOp.class) { return (T) CANONICALIZER; + } else if (clazz == LoweringOp.class) { + return (T) LOWERING; } return super.lookup(clazz); } @@ -127,7 +130,17 @@ @Override public Node lower(Node n, LoweringTool tool) { LoadField field = (LoadField) n; - return null; //field.field().createLoad(tool); + if (field.isVolatile()) { + return null; + } + Graph graph = field.graph(); + int displacement = field.field().offset(); + assert field.kind != CiKind.Illegal; + MemoryRead memoryRead = new MemoryRead(field.field().kind(), displacement, graph); + memoryRead.setGuard(new IsNonNull(field.object(), graph)); + memoryRead.setNext(field.next()); + memoryRead.setLocation(field.object()); + return memoryRead; } } diff -r 6264ecd38bc2 -r ac6fb0c93ffb graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MemoryRead.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/MemoryRead.java Thu Jun 16 20:09:26 2011 +0200 @@ -0,0 +1,90 @@ +/* + * 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 MemoryRead extends Instruction { + 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 SUCCESSOR_COUNT = 0; + + private int displacement; + private CiKind valueKind; + + /** + * The instruction that produces the object tested against null. + */ + public Value location() { + return (Value) inputs().get(super.inputCount() + INPUT_NODE); + } + + public Value setLocation(Value n) { + return (Value) inputs().set(super.inputCount() + INPUT_NODE, n); + } + + /** + * The instruction that produces the object tested against null. + */ + public FloatingNode guard() { + return (FloatingNode) inputs().get(super.inputCount() + INPUT_GUARD); + } + + public FloatingNode setGuard(FloatingNode n) { + return (FloatingNode) inputs().set(super.inputCount() + INPUT_GUARD, n); + } + + public int displacement() { + return displacement; + } + + public CiKind valueKind() { + return valueKind; + } + + public MemoryRead(CiKind kind, int displacement, Graph graph) { + super(kind.stackKind(), INPUT_COUNT, SUCCESSOR_COUNT, graph); + this.displacement = displacement; + this.valueKind = kind; + } + + @Override + public void accept(ValueVisitor v) { + v.visitMemoryRead(this); + } + + @Override + public void print(LogStream out) { + out.print("mem read from ").print(location()); + } + + @Override + public Node copy(Graph into) { + return new MemoryRead(super.kind, displacement(), into); + } +} diff -r 6264ecd38bc2 -r ac6fb0c93ffb 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 Thu Jun 16 18:31:16 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java Thu Jun 16 20:09:26 2011 +0200 @@ -51,6 +51,7 @@ public abstract void visitLocal(Local i); public abstract void visitLogic(Logic i); public abstract void visitLookupSwitch(LookupSwitch i); + public abstract void visitMemoryRead(MemoryRead i); public abstract void visitMonitorAddress(MonitorAddress monitorAddress); public abstract void visitMonitorEnter(MonitorEnter i); public abstract void visitMonitorExit(MonitorExit i); diff -r 6264ecd38bc2 -r ac6fb0c93ffb graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Thu Jun 16 18:31:16 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java Thu Jun 16 20:09:26 2011 +0200 @@ -26,7 +26,6 @@ import java.util.*; import com.oracle.max.graal.compiler.*; -import com.oracle.max.graal.compiler.debug.*; import com.oracle.max.graal.compiler.graph.*; import com.oracle.max.graal.compiler.ir.*; import com.oracle.max.graal.compiler.value.*; diff -r 6264ecd38bc2 -r ac6fb0c93ffb graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java Thu Jun 16 18:31:16 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/Phase.java Thu Jun 16 20:09:26 2011 +0200 @@ -23,7 +23,6 @@ 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.observer.*; import com.oracle.max.graal.compiler.schedule.*; import com.oracle.max.graal.graph.Graph; diff -r 6264ecd38bc2 -r ac6fb0c93ffb 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 Thu Jun 16 18:31:16 2011 +0200 +++ b/graal/com.oracle.max.graal.graph/src/com/oracle/max/graal/graph/NodeArray.java Thu Jun 16 20:09:26 2011 +0200 @@ -147,9 +147,6 @@ } if (node != null) { node.predecessors.add(self()); - if (node.predecessors.size() > 1 && node.getClass().getName().contains("EndNode")) { - assert false; - } } } }