Search in sources :

Example 71 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class AMD64AddressLowering method improveNegation.

private boolean improveNegation(StructuredGraph graph, DebugContext debug, AMD64AddressNode ret, boolean originalBaseNegated, boolean originalIndexNegated) {
    boolean baseNegated = originalBaseNegated;
    boolean indexNegated = originalIndexNegated;
    ValueNode originalBase = ret.getBase();
    ValueNode originalIndex = ret.getIndex();
    if (ret.getBase() instanceof NegateNode) {
        NegateNode negate = (NegateNode) ret.getBase();
        ret.setBase(negate.getValue());
        baseNegated = !baseNegated;
    }
    if (ret.getIndex() instanceof NegateNode) {
        NegateNode negate = (NegateNode) ret.getIndex();
        ret.setIndex(negate.getValue());
        indexNegated = !indexNegated;
    }
    if (baseNegated != originalBaseNegated || indexNegated != originalIndexNegated) {
        ValueNode base = ret.getBase();
        ValueNode index = ret.getIndex();
        boolean improved = improve(graph, debug, ret, baseNegated, indexNegated);
        if (baseNegated != originalBaseNegated) {
            if (base == ret.getBase()) {
                ret.setBase(originalBase);
            } else if (ret.getBase() != null) {
                ret.setBase(graph.maybeAddOrUnique(NegateNode.create(ret.getBase(), NodeView.DEFAULT)));
            }
        }
        if (indexNegated != originalIndexNegated) {
            if (index == ret.getIndex()) {
                ret.setIndex(originalIndex);
            } else if (ret.getIndex() != null) {
                ret.setIndex(graph.maybeAddOrUnique(NegateNode.create(ret.getIndex(), NodeView.DEFAULT)));
            }
        }
        return improved;
    } else {
        assert ret.getBase() == originalBase && ret.getIndex() == originalIndex;
    }
    return false;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode)

Example 72 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class ShiftNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    ValueNode valueNode = canonical(getOp(forX), stamp(NodeView.DEFAULT), forX, forY, view);
    if (valueNode != null) {
        return valueNode;
    }
    return this;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 73 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class SignExtendNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
    NodeView view = NodeView.from(tool);
    ValueNode ret = super.canonical(tool, forValue);
    if (ret != this) {
        return ret;
    }
    return canonical(this, forValue, getInputBits(), getResultBits(), view);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 74 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class SubNode method canonical.

private static ValueNode canonical(SubNode subNode, BinaryOp<Sub> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
    SubNode self = subNode;
    if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
        Constant zero = op.getZero(forX.stamp(view));
        if (zero != null) {
            return ConstantNode.forPrimitive(stamp, zero);
        }
    }
    boolean associative = op.isAssociative();
    if (associative) {
        if (forX instanceof AddNode) {
            AddNode x = (AddNode) forX;
            if (x.getY() == forY) {
                // (a + b) - b
                return x.getX();
            }
            if (x.getX() == forY) {
                // (a + b) - a
                return x.getY();
            }
        } else if (forX instanceof SubNode) {
            SubNode x = (SubNode) forX;
            if (x.getX() == forY) {
                // (a - b) - a
                return NegateNode.create(x.getY(), view);
            }
        }
        if (forY instanceof AddNode) {
            AddNode y = (AddNode) forY;
            if (y.getX() == forX) {
                // a - (a + b)
                return NegateNode.create(y.getY(), view);
            }
            if (y.getY() == forX) {
                // b - (a + b)
                return NegateNode.create(y.getX(), view);
            }
        } else if (forY instanceof SubNode) {
            SubNode y = (SubNode) forY;
            if (y.getX() == forX) {
                // a - (a - b)
                return y.getY();
            }
        }
    }
    if (forY.isConstant()) {
        Constant c = forY.asConstant();
        if (op.isNeutral(c)) {
            return forX;
        }
        if (associative && self != null) {
            ValueNode reassociated = reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
            if (reassociated != self) {
                return reassociated;
            }
        }
        if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
            long i = ((PrimitiveConstant) c).asLong();
            if (i < 0 || ((IntegerStamp) StampFactory.forKind(forY.getStackKind())).contains(-i)) {
                // commutative, so prefer add when it fits.
                return BinaryArithmeticNode.add(forX, ConstantNode.forIntegerStamp(stamp, -i), view);
            }
        }
    } else if (forX.isConstant()) {
        Constant c = forX.asConstant();
        if (ArithmeticOpTable.forStamp(stamp).getAdd().isNeutral(c)) {
            /*
                 * Note that for floating point numbers, + and - have different neutral elements. We
                 * have to test for the neutral element of +, because we are doing this
                 * transformation: 0 - x == (-x) + 0 == -x.
                 */
            return NegateNode.create(forY, view);
        }
        if (associative && self != null) {
            return reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
        }
    }
    if (forY instanceof NegateNode) {
        return BinaryArithmeticNode.add(forX, ((NegateNode) forY).getValue(), view);
    }
    return self != null ? self : new SubNode(forX, forY);
}
Also used : Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 75 with ValueNode

use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.

the class SubNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    ValueNode ret = super.canonical(tool, forX, forY);
    if (ret != this) {
        return ret;
    }
    BinaryOp<Sub> op = getOp(forX, forY);
    return canonical(this, op, stamp, forX, forY, view);
}
Also used : Sub(org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Sub) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)482 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)104 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)77 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)76 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)69 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)67 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)60 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)52 Node (org.graalvm.compiler.graph.Node)50 JavaKind (jdk.vm.ci.meta.JavaKind)48 Stamp (org.graalvm.compiler.core.common.type.Stamp)48 LogicNode (org.graalvm.compiler.nodes.LogicNode)48 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)38 FixedNode (org.graalvm.compiler.nodes.FixedNode)37 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)37 NodeView (org.graalvm.compiler.nodes.NodeView)36 PhiNode (org.graalvm.compiler.nodes.PhiNode)36 Test (org.junit.Test)36