Search in sources :

Example 26 with ConstantNode

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

the class LoopTransformations method updateMainLoopLimit.

private static void updateMainLoopLimit(IfNode preLimit, InductionVariable preIv, LoopFragmentWhole mainLoop) {
    // Update the main loops limit test to be different than the post loop
    StructuredGraph graph = preLimit.graph();
    IfNode mainLimit = mainLoop.getDuplicatedNode(preLimit);
    LogicNode ifTest = mainLimit.condition();
    CompareNode compareNode = (CompareNode) ifTest;
    ValueNode prePhi = preIv.valueNode();
    ValueNode mainPhi = mainLoop.getDuplicatedNode(prePhi);
    ValueNode preStride = preIv.strideNode();
    ValueNode mainStride;
    if (preStride instanceof ConstantNode) {
        mainStride = preStride;
    } else {
        mainStride = mainLoop.getDuplicatedNode(preStride);
    }
    // Fetch the bounds to pose lowering the range by one
    ValueNode ub = null;
    if (compareNode.getX() == mainPhi) {
        ub = compareNode.getY();
    } else if (compareNode.getY() == mainPhi) {
        ub = compareNode.getX();
    } else {
        throw GraalError.shouldNotReachHere();
    }
    // Preloop always performs at least one iteration, so remove that from the main loop.
    ValueNode newLimit = sub(graph, ub, mainStride);
    // Re-wire the condition with the new limit
    compareNode.replaceFirstInput(ub, newLimit);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 27 with ConstantNode

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

the class FloatArraysEqualsTest method testStableArray.

public void testStableArray(String methodName) {
    ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
    Result expected = executeExpected(method, null);
    StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
    for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
        if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
            ConstantNode newConstantNode = ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess());
            newConstantNode = graph.unique(newConstantNode);
            constantNode.replaceAndDelete(newConstantNode);
        }
    }
    CompilationResult result = compile(method, graph);
    InstalledCode code = addMethod(graph.getDebug(), method, result);
    Result actual;
    try {
        actual = new Result(code.executeVarargs(), null);
    } catch (Exception e) {
        actual = new Result(null, e);
    }
    assertEquals(expected, actual);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InstalledCode(jdk.vm.ci.code.InstalledCode) CompilationResult(org.graalvm.compiler.code.CompilationResult) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CompilationResult(org.graalvm.compiler.code.CompilationResult)

Example 28 with ConstantNode

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

the class SystemArrayCopyTest method parse.

@Override
protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
    StructuredGraph graph = super.parse(builder, graphBuilderSuite);
    if (argsToBind != null) {
        ResolvedJavaMethod m = graph.method();
        Object receiver = isStatic(m.getModifiers()) ? null : this;
        Object[] args = argsWithReceiver(receiver, argsToBind);
        JavaType[] parameterTypes = m.toParameterTypes();
        assert parameterTypes.length == args.length;
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (args[index] != null) {
                JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[index].getJavaKind(), args[index]);
                ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
                param.replaceAtUsages(replacement);
            }
        }
    }
    return graph;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 29 with ConstantNode

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

the class AheadOfTimeCompilationTest method testPrimitiveClassObjectAOT.

@Test
public void testPrimitiveClassObjectAOT() {
    StructuredGraph result = compile("getPrimitiveClassObject", true);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    Stamp constantStamp = filter.first().stamp(NodeView.DEFAULT);
    Assert.assertTrue(constantStamp instanceof KlassPointerStamp);
    int expected = runtime().getVMConfig().classMirrorIsHandle ? 3 : 2;
    assertDeepEquals(expected, result.getNodes().filter(ReadNode.class).count());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Stamp(org.graalvm.compiler.core.common.type.Stamp) KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) Test(org.junit.Test)

Example 30 with ConstantNode

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

the class AheadOfTimeCompilationTest method testPrimitiveClassObject.

@Test
public void testPrimitiveClassObject() {
    StructuredGraph result = compile("getPrimitiveClassObject", false);
    NodeIterable<ConstantNode> filter = getConstantNodes(result);
    assertDeepEquals(1, filter.count());
    JavaConstant c = filter.first().asJavaConstant();
    Assert.assertEquals(getSnippetReflection().asObject(Class.class, c), Integer.TYPE);
    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) Test(org.junit.Test)

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