Search in sources :

Example 11 with ConstantNode

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

the class SnippetTemplate method bind.

/**
 * Gets the instantiation-time bindings to this template's parameters.
 *
 * @return the map that will be used to bind arguments to parameters when inlining this template
 */
private EconomicMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider metaAccess, Arguments args) {
    EconomicMap<Node, Node> replacements = EconomicMap.create(Equivalence.IDENTITY);
    assert args.info.getParameterCount() == parameters.length : "number of args (" + args.info.getParameterCount() + ") != number of parameters (" + parameters.length + ")";
    for (int i = 0; i < parameters.length; i++) {
        Object parameter = parameters[i];
        assert parameter != null : this + " has no parameter named " + args.info.getParameterName(i);
        Object argument = args.values[i];
        if (parameter instanceof ParameterNode) {
            if (argument instanceof ValueNode) {
                replacements.put((ParameterNode) parameter, (ValueNode) argument);
            } else {
                JavaKind kind = ((ParameterNode) parameter).getStackKind();
                assert argument != null || kind == JavaKind.Object : this + " cannot accept null for non-object parameter named " + args.info.getParameterName(i);
                JavaConstant constant = forBoxed(argument, kind);
                replacements.put((ParameterNode) parameter, ConstantNode.forConstant(constant, metaAccess, replaceeGraph));
            }
        } else if (parameter instanceof ParameterNode[]) {
            ParameterNode[] params = (ParameterNode[]) parameter;
            Varargs varargs = (Varargs) argument;
            int length = params.length;
            List<?> list = null;
            Object array = null;
            if (varargs.value instanceof List) {
                list = (List<?>) varargs.value;
                assert list.size() == length : length + " != " + list.size();
            } else {
                array = varargs.value;
                assert array != null && array.getClass().isArray();
                assert Array.getLength(array) == length : length + " != " + Array.getLength(array);
            }
            for (int j = 0; j < length; j++) {
                ParameterNode param = params[j];
                assert param != null;
                Object value = list != null ? list.get(j) : Array.get(array, j);
                if (value instanceof ValueNode) {
                    replacements.put(param, (ValueNode) value);
                } else {
                    JavaConstant constant = forBoxed(value, param.getStackKind());
                    ConstantNode element = ConstantNode.forConstant(constant, metaAccess, replaceeGraph);
                    replacements.put(param, element);
                }
            }
        } else {
            assert parameter.equals(CONSTANT_PARAMETER) || parameter.equals(UNUSED_PARAMETER) : "unexpected entry for parameter: " + args.info.getParameterName(i) + " -> " + parameter;
        }
    }
    return replacements;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ArrayList(java.util.ArrayList) List(java.util.List) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 12 with ConstantNode

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

the class ArrayEqualsNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (tool.allUsagesAvailable() && hasNoUsages()) {
        return null;
    }
    ValueNode a1 = GraphUtil.unproxify(array1);
    ValueNode a2 = GraphUtil.unproxify(array2);
    if (a1 == a2) {
        return ConstantNode.forBoolean(true);
    }
    if (a1.isConstant() && a2.isConstant() && length.isConstant()) {
        ConstantNode c1 = (ConstantNode) a1;
        ConstantNode c2 = (ConstantNode) a2;
        if (c1.getStableDimension() >= 1 && c2.getStableDimension() >= 1) {
            boolean ret = arrayEquals(tool.getConstantReflection(), c1.asJavaConstant(), c2.asJavaConstant(), length.asJavaConstant().asInt());
            return ConstantNode.forBoolean(ret);
        }
    }
    return this;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 13 with ConstantNode

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

the class RemNode method create.

public static ValueNode create(ValueNode forX, ValueNode forY, NodeView view) {
    BinaryOp<Rem> op = ArithmeticOpTable.forStamp(forX.stamp(view)).getRem();
    Stamp stamp = op.foldStamp(forX.stamp(view), forY.stamp(view));
    ConstantNode tryConstantFold = tryConstantFold(op, forX, forY, stamp, view);
    if (tryConstantFold != null) {
        return tryConstantFold;
    }
    return new RemNode(forX, forY);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) Rem(org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Rem)

Example 14 with ConstantNode

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

the class MulNode method create.

public static ValueNode create(ValueNode x, ValueNode y, NodeView view) {
    BinaryOp<Mul> op = ArithmeticOpTable.forStamp(x.stamp(view)).getMul();
    Stamp stamp = op.foldStamp(x.stamp(view), y.stamp(view));
    ConstantNode tryConstantFold = tryConstantFold(op, x, y, stamp, view);
    if (tryConstantFold != null) {
        return tryConstantFold;
    }
    return canonical(null, op, stamp, x, y, view);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Mul(org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Mul)

Example 15 with ConstantNode

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

the class OrNode method create.

public static ValueNode create(ValueNode x, ValueNode y, NodeView view) {
    BinaryOp<Or> op = ArithmeticOpTable.forStamp(x.stamp(view)).getOr();
    Stamp stamp = op.foldStamp(x.stamp(view), y.stamp(view));
    ConstantNode tryConstantFold = tryConstantFold(op, x, y, stamp, view);
    if (tryConstantFold != null) {
        return tryConstantFold;
    }
    return canonical(null, op, stamp, x, y, view);
}
Also used : Or(org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Or) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) PrimitiveStamp(org.graalvm.compiler.core.common.type.PrimitiveStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp)

Aggregations

ConstantNode (org.graalvm.compiler.nodes.ConstantNode)100 ValueNode (org.graalvm.compiler.nodes.ValueNode)46 JavaConstant (jdk.vm.ci.meta.JavaConstant)32 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)28 Stamp (org.graalvm.compiler.core.common.type.Stamp)23 Test (org.junit.Test)15 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)14 Node (org.graalvm.compiler.graph.Node)14 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 PhiNode (org.graalvm.compiler.nodes.PhiNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)10 ArrayList (java.util.ArrayList)9 JavaKind (jdk.vm.ci.meta.JavaKind)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 Constant (jdk.vm.ci.meta.Constant)8 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)8 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)7