# HG changeset patch # User Lukas Stadler # Date 1403708101 -7200 # Node ID 1434b835f0d32f354076cf01ca1edf613a79906b # Parent 7a0035cbf8087b21e0bfedc7f6c2f29d4df30f58 implement Canonicalizable.Binary in the FixedBinaryNode hierarchy diff -r 7a0035cbf808 -r 1434b835f0d3 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FixedBinaryNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FixedBinaryNode.java Wed Jun 25 16:55:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/FixedBinaryNode.java Wed Jun 25 16:55:01 2014 +0200 @@ -23,9 +23,10 @@ package com.oracle.graal.nodes.calc; import com.oracle.graal.compiler.common.type.*; +import com.oracle.graal.graph.spi.*; import com.oracle.graal.nodes.*; -public abstract class FixedBinaryNode extends DeoptimizingFixedWithNextNode { +public abstract class FixedBinaryNode extends DeoptimizingFixedWithNextNode implements Canonicalizable.Binary { @Input private ValueNode x; @Input private ValueNode y; diff -r 7a0035cbf808 -r 1434b835f0d3 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerDivNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerDivNode.java Wed Jun 25 16:55:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerDivNode.java Wed Jun 25 16:55:01 2014 +0200 @@ -31,7 +31,7 @@ import com.oracle.graal.nodes.type.*; @NodeInfo(shortName = "/") -public class IntegerDivNode extends FixedBinaryNode implements Canonicalizable, Lowerable, LIRLowerable { +public class IntegerDivNode extends FixedBinaryNode implements Lowerable, LIRLowerable { public IntegerDivNode(ValueNode x, ValueNode y) { super(x.stamp().unrestricted(), x, y); @@ -43,30 +43,30 @@ } @Override - public Node canonical(CanonicalizerTool tool) { - if (getX().isConstant() && getY().isConstant()) { - long y = getY().asConstant().asLong(); + public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { + if (forX.isConstant() && forY.isConstant()) { + long y = forY.asConstant().asLong(); if (y == 0) { return this; // this will trap, can not canonicalize } - return ConstantNode.forIntegerStamp(stamp(), getX().asConstant().asLong() / y, graph()); - } else if (getY().isConstant()) { - long c = getY().asConstant().asLong(); + return ConstantNode.forIntegerStamp(stamp(), forX.asConstant().asLong() / y); + } else if (forY.isConstant()) { + long c = forY.asConstant().asLong(); if (c == 1) { - return getX(); + return forX; } if (c == -1) { - return graph().unique(new NegateNode(getX())); + return new NegateNode(forX); } long abs = Math.abs(c); - if (CodeUtil.isPowerOf2(abs) && getX().stamp() instanceof IntegerStamp) { - ValueNode dividend = getX(); - IntegerStamp stampX = (IntegerStamp) getX().stamp(); + if (CodeUtil.isPowerOf2(abs) && forX.stamp() instanceof IntegerStamp) { + ValueNode dividend = forX; + IntegerStamp stampX = (IntegerStamp) forX.stamp(); int log2 = CodeUtil.log2(abs); // no rounding if dividend is positive or if its low bits are always 0 if (stampX.canBeNegative() || (stampX.upMask() & (abs - 1)) != 0) { int bits = PrimitiveStamp.getBits(stamp()); - RightShiftNode sign = new RightShiftNode(getX(), ConstantNode.forInt(bits - 1)); + RightShiftNode sign = new RightShiftNode(forX, ConstantNode.forInt(bits - 1)); UnsignedRightShiftNode round = new UnsignedRightShiftNode(sign, ConstantNode.forInt(bits - log2)); dividend = IntegerArithmeticNode.add(dividend, round); } @@ -79,13 +79,13 @@ } // Convert the expression ((a - a % b) / b) into (a / b). - if (getX() instanceof IntegerSubNode) { - IntegerSubNode integerSubNode = (IntegerSubNode) getX(); + if (forX instanceof IntegerSubNode) { + IntegerSubNode integerSubNode = (IntegerSubNode) forX; if (integerSubNode.getY() instanceof IntegerRemNode) { IntegerRemNode integerRemNode = (IntegerRemNode) integerSubNode.getY(); if (integerSubNode.stamp().isCompatible(this.stamp()) && integerRemNode.stamp().isCompatible(this.stamp()) && integerSubNode.getX() == integerRemNode.getX() && - this.getY() == integerRemNode.getY()) { - return graph().add(new IntegerDivNode(integerSubNode.getX(), this.getY())); + forY == integerRemNode.getY()) { + return new IntegerDivNode(integerSubNode.getX(), forY); } } } diff -r 7a0035cbf808 -r 1434b835f0d3 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerRemNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerRemNode.java Wed Jun 25 16:55:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerRemNode.java Wed Jun 25 16:55:01 2014 +0200 @@ -31,7 +31,7 @@ import com.oracle.graal.nodes.type.*; @NodeInfo(shortName = "%") -public class IntegerRemNode extends FixedBinaryNode implements Canonicalizable, Lowerable, LIRLowerable { +public class IntegerRemNode extends FixedBinaryNode implements Lowerable, LIRLowerable { public IntegerRemNode(ValueNode x, ValueNode y) { super(x.stamp().unrestricted(), x, y); @@ -43,19 +43,19 @@ } @Override - public Node canonical(CanonicalizerTool tool) { - if (getX().isConstant() && getY().isConstant()) { - long y = getY().asConstant().asLong(); + public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { + if (forX.isConstant() && forY.isConstant()) { + long y = forY.asConstant().asLong(); if (y == 0) { return this; // this will trap, can not canonicalize } - return ConstantNode.forIntegerStamp(stamp(), getX().asConstant().asLong() % y); - } else if (getY().isConstant()) { - long c = getY().asConstant().asLong(); + return ConstantNode.forIntegerStamp(stamp(), forX.asConstant().asLong() % y); + } else if (forY.isConstant()) { + long c = forY.asConstant().asLong(); if (c == 1 || c == -1) { return ConstantNode.forIntegerStamp(stamp(), 0); - } else if (c > 0 && CodeUtil.isPowerOf2(c) && getX().stamp() instanceof IntegerStamp && ((IntegerStamp) getX().stamp()).isPositive()) { - return new AndNode(getX(), ConstantNode.forIntegerStamp(stamp(), c - 1)); + } else if (c > 0 && CodeUtil.isPowerOf2(c) && forX.stamp() instanceof IntegerStamp && ((IntegerStamp) forX.stamp()).isPositive()) { + return new AndNode(forX, ConstantNode.forIntegerStamp(stamp(), c - 1)); } } return this; diff -r 7a0035cbf808 -r 1434b835f0d3 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedDivNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedDivNode.java Wed Jun 25 16:55:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedDivNode.java Wed Jun 25 16:55:01 2014 +0200 @@ -30,27 +30,27 @@ import com.oracle.graal.nodes.spi.*; @NodeInfo(shortName = "|/|") -public class UnsignedDivNode extends FixedBinaryNode implements Canonicalizable, Lowerable, LIRLowerable { +public class UnsignedDivNode extends FixedBinaryNode implements Lowerable, LIRLowerable { public UnsignedDivNode(ValueNode x, ValueNode y) { super(x.stamp().unrestricted(), x, y); } @Override - public Node canonical(CanonicalizerTool tool) { - if (getX().isConstant() && getY().isConstant()) { - long yConst = getY().asConstant().asLong(); + public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { + if (forX.isConstant() && forY.isConstant()) { + long yConst = forY.asConstant().asLong(); if (yConst == 0) { return this; // this will trap, cannot canonicalize } - return ConstantNode.forIntegerStamp(stamp(), UnsignedMath.divide(getX().asConstant().asLong(), yConst), graph()); - } else if (getY().isConstant()) { - long c = getY().asConstant().asLong(); + return ConstantNode.forIntegerStamp(stamp(), UnsignedMath.divide(forX.asConstant().asLong(), yConst)); + } else if (forY.isConstant()) { + long c = forY.asConstant().asLong(); if (c == 1) { - return getX(); + return forX; } if (CodeUtil.isPowerOf2(c)) { - return graph().unique(new UnsignedRightShiftNode(getX(), ConstantNode.forInt(CodeUtil.log2(c), graph()))); + return new UnsignedRightShiftNode(forX, ConstantNode.forInt(CodeUtil.log2(c))); } } return this; diff -r 7a0035cbf808 -r 1434b835f0d3 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedRemNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedRemNode.java Wed Jun 25 16:55:01 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/UnsignedRemNode.java Wed Jun 25 16:55:01 2014 +0200 @@ -30,26 +30,26 @@ import com.oracle.graal.nodes.spi.*; @NodeInfo(shortName = "|%|") -public class UnsignedRemNode extends FixedBinaryNode implements Canonicalizable, Lowerable, LIRLowerable { +public class UnsignedRemNode extends FixedBinaryNode implements Lowerable, LIRLowerable { public UnsignedRemNode(ValueNode x, ValueNode y) { super(x.stamp().unrestricted(), x, y); } @Override - public Node canonical(CanonicalizerTool tool) { - if (getX().isConstant() && getY().isConstant()) { - long yConst = getY().asConstant().asLong(); + public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { + if (forX.isConstant() && forY.isConstant()) { + long yConst = forY.asConstant().asLong(); if (yConst == 0) { return this; // this will trap, cannot canonicalize } - return ConstantNode.forIntegerStamp(stamp(), UnsignedMath.remainder(getX().asConstant().asLong(), yConst), graph()); - } else if (getY().isConstant()) { - long c = getY().asConstant().asLong(); + return ConstantNode.forIntegerStamp(stamp(), UnsignedMath.remainder(forX.asConstant().asLong(), yConst)); + } else if (forY.isConstant()) { + long c = forY.asConstant().asLong(); if (c == 1) { return ConstantNode.forIntegerStamp(stamp(), 0); } else if (CodeUtil.isPowerOf2(c)) { - return new AndNode(getX(), ConstantNode.forIntegerStamp(stamp(), c - 1)); + return new AndNode(forX, ConstantNode.forIntegerStamp(stamp(), c - 1)); } } return this;