Search in sources :

Example 81 with ValueNode

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

the class OrNode 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;
    }
    return canonical(this, getOp(forX, forY), stamp(view), forX, forY, view);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 82 with ValueNode

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

the class AddNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    ValueNode ret = super.canonical(tool, forX, forY);
    if (ret != this) {
        return ret;
    }
    if (forX.isConstant() && !forY.isConstant()) {
        // we try to swap and canonicalize
        ValueNode improvement = canonical(tool, forY, forX);
        if (improvement != this) {
            return improvement;
        }
        // if this fails we only swap
        return new AddNode(forY, forX);
    }
    BinaryOp<Add> op = getOp(forX, forY);
    NodeView view = NodeView.from(tool);
    return canonical(this, op, forX, forY, view);
}
Also used : Add(org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Add) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 83 with ValueNode

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

the class AddNode method canonical.

private static ValueNode canonical(AddNode addNode, BinaryOp<Add> op, ValueNode forX, ValueNode forY, NodeView view) {
    AddNode self = addNode;
    boolean associative = op.isAssociative();
    if (associative) {
        if (forX instanceof SubNode) {
            SubNode sub = (SubNode) forX;
            if (sub.getY() == forY) {
                // (a - b) + b
                return sub.getX();
            }
        }
        if (forY instanceof SubNode) {
            SubNode sub = (SubNode) forY;
            if (sub.getY() == forX) {
                // b + (a - b)
                return sub.getX();
            }
        }
    }
    if (forY.isConstant()) {
        Constant c = forY.asConstant();
        if (op.isNeutral(c)) {
            return forX;
        }
        if (associative && self != null) {
            // canonicalize expressions like "(a + 1) + 2"
            ValueNode reassociated = reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
            if (reassociated != self) {
                return reassociated;
            }
        }
    }
    if (forX instanceof NegateNode) {
        return BinaryArithmeticNode.sub(forY, ((NegateNode) forX).getValue(), view);
    } else if (forY instanceof NegateNode) {
        return BinaryArithmeticNode.sub(forX, ((NegateNode) forY).getValue(), view);
    }
    if (self == null) {
        self = (AddNode) new AddNode(forX, forY).maybeCommuteInputs();
    }
    return self;
}
Also used : Constant(jdk.vm.ci.meta.Constant) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 84 with ValueNode

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

the class AndNode method canonical.

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

Example 85 with ValueNode

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

the class BinaryArithmeticNode method maybeCommuteInputs.

/**
 * Ensure a canonical ordering of inputs for commutative nodes to improve GVN results. Order the
 * inputs by increasing {@link Node#id} and call {@link Graph#findDuplicate(Node)} on the node
 * if it's currently in a graph. It's assumed that if there was a constant on the left it's been
 * moved to the right by other code and that ordering is left alone.
 *
 * @return the original node or another node with the same input ordering
 */
@SuppressWarnings("deprecation")
public BinaryNode maybeCommuteInputs() {
    assert this instanceof BinaryCommutative;
    if (!y.isConstant() && (x.isConstant() || x.getId() > y.getId())) {
        ValueNode tmp = x;
        x = y;
        y = tmp;
        if (graph() != null) {
            // See if this node already exists
            BinaryNode duplicate = graph().findDuplicate(this);
            if (duplicate != null) {
                return duplicate;
            }
        }
    }
    return this;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode)

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