# HG changeset patch # User Roland Schatz # Date 1366619407 -7200 # Node ID 9adb07d6f07f0947bd2cb6503cda285059d2c517 # Parent 589e140a7f1c86c83f066c53260f7d39775562bf AddLocationNode diff -r 589e140a7f1c -r 9adb07d6f07f graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/AddLocationNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/AddLocationNode.java Mon Apr 22 10:30:07 2013 +0200 @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2013, 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.graal.nodes.extended; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.*; + +/** + * Location node that is the sum of two other location nodes. Can represent locations in the form of + * [(base + x) + y] where base is a node and x and y are location nodes. + */ +@NodeInfo(nameTemplate = "AddLoc {p#locationIdentity/s}") +public final class AddLocationNode extends LocationNode implements Canonicalizable { + + @Input private ValueNode x; + @Input private ValueNode y; + + public LocationNode getX() { + return (LocationNode) x; + } + + public LocationNode getY() { + return (LocationNode) y; + } + + public static AddLocationNode create(LocationNode x, LocationNode y, Graph graph) { + assert x.getValueKind().equals(y.getValueKind()) && x.locationIdentity() == y.locationIdentity(); + return graph.unique(new AddLocationNode(x, y)); + } + + private AddLocationNode(LocationNode x, LocationNode y) { + super(x.locationIdentity(), x.getValueKind()); + this.x = x; + this.y = y; + } + + @Override + protected LocationNode addDisplacement(long displacement) { + LocationNode added = getX().addDisplacement(displacement); + return graph().unique(new AddLocationNode(added, getY())); + } + + @Override + public ValueNode canonical(CanonicalizerTool tool) { + if (x instanceof ConstantLocationNode) { + return getY().addDisplacement(((ConstantLocationNode) x).displacement()); + } + if (y instanceof ConstantLocationNode) { + return getX().addDisplacement(((ConstantLocationNode) y).displacement()); + } + + if (x instanceof IndexedLocationNode && y instanceof IndexedLocationNode) { + IndexedLocationNode xIdx = (IndexedLocationNode) x; + IndexedLocationNode yIdx = (IndexedLocationNode) y; + if (xIdx.indexScaling() == yIdx.indexScaling()) { + long displacement = xIdx.displacement() + yIdx.displacement(); + ValueNode index = IntegerArithmeticNode.add(xIdx.index(), yIdx.index()); + return IndexedLocationNode.create(locationIdentity(), getValueKind(), displacement, index, graph(), xIdx.indexScaling()); + } + } + + return this; + } + + @Override + public Value generateLea(LIRGeneratorTool gen, Value base) { + Value xAddr = getX().generateLea(gen, base); + return getY().generateLea(gen, xAddr); + } + + @Override + public Value generateLoad(LIRGeneratorTool gen, Value base, DeoptimizingNode deopting) { + Value xAddr = getX().generateLea(gen, base); + return getY().generateLoad(gen, xAddr, deopting); + } + + @Override + public void generateStore(LIRGeneratorTool gen, Value base, Value value, DeoptimizingNode deopting) { + Value xAddr = getX().generateLea(gen, base); + getY().generateStore(gen, xAddr, value, deopting); + } +} diff -r 589e140a7f1c -r 9adb07d6f07f graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ConstantLocationNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ConstantLocationNode.java Mon Apr 22 10:30:07 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ConstantLocationNode.java Mon Apr 22 10:30:07 2013 +0200 @@ -50,6 +50,11 @@ } @Override + protected ConstantLocationNode addDisplacement(long x) { + return create(locationIdentity(), getValueKind(), displacement + x, graph()); + } + + @Override public Value generateLea(LIRGeneratorTool gen, Value base) { return gen.emitLea(base, displacement(), Value.ILLEGAL, 0); } diff -r 589e140a7f1c -r 9adb07d6f07f graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java Mon Apr 22 10:30:07 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IndexedLocationNode.java Mon Apr 22 10:30:07 2013 +0200 @@ -46,6 +46,10 @@ return index; } + public long displacement() { + return displacement; + } + /** * @return Constant that is used to scale the index. */ @@ -65,6 +69,11 @@ } @Override + protected LocationNode addDisplacement(long x) { + return create(locationIdentity(), getValueKind(), displacement + x, index, graph(), indexScaling); + } + + @Override public ValueNode canonical(CanonicalizerTool tool) { Constant constantIndex = index.asConstant(); if (constantIndex != null) { diff -r 589e140a7f1c -r 9adb07d6f07f graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LocationNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LocationNode.java Mon Apr 22 10:30:07 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/LocationNode.java Mon Apr 22 10:30:07 2013 +0200 @@ -86,6 +86,8 @@ return locationIdentity; } + protected abstract LocationNode addDisplacement(long displacement); + @Override public void generate(LIRGeneratorTool generator) { // nothing to do...