Search in sources :

Example 41 with ConstantNode

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

the class NegateNodeCanonicalizationTest method testByte.

@Test
public void testByte() {
    byte[] a = new byte[] { Byte.MIN_VALUE, Byte.MIN_VALUE + 1, -1, 0, 1, Byte.MAX_VALUE - 1, Byte.MAX_VALUE };
    for (byte i : a) {
        ConstantNode node = ConstantNode.forByte(i, graph);
        JavaConstant expected = JavaConstant.forInt(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 42 with ConstantNode

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

the class WordOperationPlugin method comparisonOp.

private ValueNode comparisonOp(GraphBuilderContext graph, Condition condition, ValueNode left, ValueNode right) {
    assert left.getStackKind() == wordKind && right.getStackKind() == wordKind;
    CanonicalizedCondition canonical = condition.canonicalize();
    ValueNode a = canonical.mustMirror() ? right : left;
    ValueNode b = canonical.mustMirror() ? left : right;
    CompareNode comparison;
    if (canonical.getCanonicalCondition() == CanonicalCondition.EQ) {
        comparison = new IntegerEqualsNode(a, b);
    } else if (canonical.getCanonicalCondition() == CanonicalCondition.BT) {
        comparison = new IntegerBelowNode(a, b);
    } else {
        assert canonical.getCanonicalCondition() == CanonicalCondition.LT;
        comparison = new IntegerLessThanNode(a, b);
    }
    ConstantNode trueValue = graph.add(forInt(1));
    ConstantNode falseValue = graph.add(forInt(0));
    if (canonical.mustNegate()) {
        ConstantNode temp = trueValue;
        trueValue = falseValue;
        falseValue = temp;
    }
    return graph.add(new ConditionalNode(graph.add(comparison), trueValue, falseValue));
}
Also used : CanonicalizedCondition(org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode)

Example 43 with ConstantNode

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

the class CInterfaceInvocationPlugin method replaceConstant.

private boolean replaceConstant(GraphBuilderContext b, ResolvedJavaMethod method, ConstantInfo constantInfo) {
    Object value = constantInfo.getValueInfo().getProperty();
    JavaKind kind = wordTypes.asKind(b.getInvokeReturnType());
    ConstantNode valueNode;
    switch(constantInfo.getKind()) {
        case INTEGER:
        case POINTER:
            if (method.getSignature().getReturnKind() == JavaKind.Boolean) {
                valueNode = ConstantNode.forBoolean((long) value != 0, b.getGraph());
            } else {
                valueNode = ConstantNode.forIntegerKind(kind, (long) value, b.getGraph());
            }
            break;
        case FLOAT:
            valueNode = ConstantNode.forFloatingKind(kind, (double) value, b.getGraph());
            break;
        case STRING:
        case BYTEARRAY:
            valueNode = ConstantNode.forConstant(SubstrateObjectConstant.forObject(value), b.getMetaAccess(), b.getGraph());
            break;
        default:
            throw shouldNotReachHere("Unexpected constant kind " + constantInfo);
    }
    b.push(pushKind(method), valueNode);
    return true;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 44 with ConstantNode

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

the class ConstantFoldLoadFieldPlugin method tryConstantFold.

private static boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, JavaConstant receiver) {
    ConstantNode result = ConstantFoldUtil.tryConstantFold(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), field, receiver, b.getOptions());
    if (result != null) {
        JavaConstant value = result.asJavaConstant();
        if (b.getMetaAccess() instanceof AnalysisMetaAccess && value.getJavaKind() == JavaKind.Object && value.isNonNull()) {
            SubstrateObjectConstant sValue = (SubstrateObjectConstant) value;
            SubstrateObjectConstant sReceiver = (SubstrateObjectConstant) receiver;
            Object root;
            if (receiver == null) {
                /* Found a root, map the constant value to the root field. */
                root = field;
            } else {
                /* Map the constant value to the root field of it's receiver. */
                root = sReceiver.getRoot();
                assert root != null : receiver.toValueString() + " : " + field + " : " + b.getGraph();
            }
            sValue.setRoot(root);
        }
        result = b.getGraph().unique(result);
        b.push(field.getJavaKind(), result);
        return true;
    }
    return false;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess)

Example 45 with ConstantNode

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

the class AheadOfTimeCompilationTest method testStringObjectCommon.

private void testStringObjectCommon(boolean compileAOT) {
    StructuredGraph result = compile("getStringObject", compileAOT);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    JavaConstant c = filter.first().asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(String.class, c), "test string");
    assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count());
    assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) JavaConstant(jdk.vm.ci.meta.JavaConstant)

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