Search in sources :

Example 6 with NodeView

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

the class ReadNode method canonicalizeRead.

public static ValueNode canonicalizeRead(ValueNode read, AddressNode address, LocationIdentity locationIdentity, CanonicalizerTool tool) {
    NodeView view = NodeView.from(tool);
    MetaAccessProvider metaAccess = tool.getMetaAccess();
    if (tool.canonicalizeReads() && address instanceof OffsetAddressNode) {
        OffsetAddressNode objAddress = (OffsetAddressNode) address;
        ValueNode object = objAddress.getBase();
        if (metaAccess != null && object.isConstant() && !object.isNullConstant() && objAddress.getOffset().isConstant()) {
            long displacement = objAddress.getOffset().asJavaConstant().asLong();
            int stableDimension = ((ConstantNode) object).getStableDimension();
            if (locationIdentity.isImmutable() || stableDimension > 0) {
                Constant constant = read.stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), object.asConstant(), displacement);
                boolean isDefaultStable = locationIdentity.isImmutable() || ((ConstantNode) object).isDefaultStable();
                if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
                    return ConstantNode.forConstant(read.stamp(view), constant, Math.max(stableDimension - 1, 0), isDefaultStable, metaAccess);
                }
            }
        }
        if (locationIdentity.equals(ARRAY_LENGTH_LOCATION)) {
            ValueNode length = GraphUtil.arrayLength(object);
            if (length != null) {
                return length;
            }
        }
        if (locationIdentity instanceof CanonicalizableLocation) {
            CanonicalizableLocation canonicalize = (CanonicalizableLocation) locationIdentity;
            ValueNode result = canonicalize.canonicalizeRead(read, address, object, tool);
            assert result != null && result.stamp(view).isCompatible(read.stamp(view));
            return result;
        }
    }
    return read;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) Constant(jdk.vm.ci.meta.Constant) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView) CanonicalizableLocation(org.graalvm.compiler.nodes.CanonicalizableLocation) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 7 with NodeView

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

the class OffsetAddressNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (base instanceof OffsetAddressNode) {
        NodeView view = NodeView.from(tool);
        // Rewrite (&base[offset1])[offset2] to base[offset1 + offset2].
        OffsetAddressNode b = (OffsetAddressNode) base;
        return new OffsetAddressNode(b.getBase(), BinaryArithmeticNode.add(b.getOffset(), this.getOffset(), view));
    } else if (base instanceof AddNode) {
        AddNode add = (AddNode) base;
        if (add.getY().isConstant()) {
            return new OffsetAddressNode(add.getX(), new AddNode(add.getY(), getOffset()));
        }
    }
    return this;
}
Also used : NodeView(org.graalvm.compiler.nodes.NodeView) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 8 with NodeView

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

the class BinaryMathIntrinsicNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    ValueNode c = tryConstantFold(forX, forY, getOperation());
    if (c != null) {
        return c;
    }
    if (forY.isConstant()) {
        double yValue = forY.asJavaConstant().asDouble();
        // If the second argument is positive or negative zero, then the result is 1.0.
        if (yValue == 0.0D) {
            return ConstantNode.forDouble(1);
        }
        // If the second argument is 1.0, then the result is the same as the first argument.
        if (yValue == 1.0D) {
            return x;
        }
        // If the second argument is NaN, then the result is NaN.
        if (Double.isNaN(yValue)) {
            return ConstantNode.forDouble(Double.NaN);
        }
        // x**-1 = 1/x
        if (yValue == -1.0D) {
            return new FloatDivNode(ConstantNode.forDouble(1), x);
        }
        // x**2 = x*x
        if (yValue == 2.0D) {
            return new MulNode(x, x);
        }
        // x**0.5 = sqrt(x)
        if (yValue == 0.5D && x.stamp(view) instanceof FloatStamp && ((FloatStamp) x.stamp(view)).lowerBound() >= 0.0D) {
            return SqrtNode.create(x, view);
        }
    }
    return this;
}
Also used : FloatDivNode(org.graalvm.compiler.nodes.calc.FloatDivNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 9 with NodeView

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

the class IntegerAddExactSplitNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    NodeView view = NodeView.from(tool);
    if (!IntegerStamp.addCanOverflow((IntegerStamp) x.stamp(view), (IntegerStamp) y.stamp(view))) {
        tool.deleteBranch(overflowSuccessor);
        tool.addToWorkList(next);
        AddNode replacement = graph().unique(new AddNode(x, y));
        graph().replaceSplitWithFloating(this, replacement, next);
        tool.addToWorkList(replacement);
    }
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) NodeView(org.graalvm.compiler.nodes.NodeView) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 10 with NodeView

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

the class IntegerMulExactSplitNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    NodeView view = NodeView.from(tool);
    if (!IntegerStamp.multiplicationCanOverflow((IntegerStamp) x.stamp(view), (IntegerStamp) y.stamp(view))) {
        tool.deleteBranch(overflowSuccessor);
        tool.addToWorkList(next);
        MulNode replacement = graph().unique(new MulNode(x, y));
        graph().replaceSplitWithFloating(this, replacement, next);
        tool.addToWorkList(replacement);
    }
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) MulNode(org.graalvm.compiler.nodes.calc.MulNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Aggregations

NodeView (org.graalvm.compiler.nodes.NodeView)37 ValueNode (org.graalvm.compiler.nodes.ValueNode)28 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4 Constant (jdk.vm.ci.meta.Constant)3 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 AddNode (org.graalvm.compiler.nodes.calc.AddNode)2 MulNode (org.graalvm.compiler.nodes.calc.MulNode)2 ArrayList (java.util.ArrayList)1 Assumptions (jdk.vm.ci.meta.Assumptions)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Add (org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Add)1 Mul (org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Mul)1 Sub (org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Sub)1 FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1