Search in sources :

Example 91 with ConstantNode

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

the class NodePosIteratorTest method testInputs.

@Test
public void testInputs() {
    TestNode n = new TestNode();
    ConstantNode i1 = ConstantNode.forInt(1);
    ConstantNode i2 = ConstantNode.forDouble(1.0d);
    ConstantNode i3 = ConstantNode.forInt(4);
    ConstantNode i4 = ConstantNode.forInt(14);
    n.itail = new NodeInputList<>(n, new ValueNode[] { i3, i4 });
    n.i1 = i1;
    n.i2 = i2;
    NodeIterable<Node> inputs = n.inputs();
    Iterator<Node> iterator = inputs.iterator();
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i1);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i2);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i3);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i4);
    Assert.assertFalse(iterator.hasNext());
    Assert.assertFalse(iterator.hasNext());
    Iterator<Position> positionIterator = n.inputPositions().iterator();
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals("ConstantNode:i1", positionIterator.next().toString());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals("FloatingNode:i2", positionIterator.next().toString());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals("NodeInputList:itail[0]", positionIterator.next().toString());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertTrue(positionIterator.hasNext());
    Assert.assertEquals("NodeInputList:itail[1]", positionIterator.next().toString());
    Assert.assertFalse(positionIterator.hasNext());
    Assert.assertFalse(positionIterator.hasNext());
    iterator = inputs.iterator();
    n.i1 = i4;
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i4);
    n.i2 = i1;
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i1);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i3);
    n.itail.initialize(1, i4);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i4);
    Assert.assertFalse(iterator.hasNext());
    iterator = inputs.iterator();
    n.i1 = null;
    n.i2 = i2;
    n.itail.initialize(0, null);
    n.itail.initialize(1, i4);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i2);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(iterator.next(), i4);
    Assert.assertFalse(iterator.hasNext());
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Position(org.graalvm.compiler.graph.Position) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Test(org.junit.Test)

Example 92 with ConstantNode

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

the class StableArrayReadFoldingTest method parseForCompile.

@Override
protected StructuredGraph parseForCompile(ResolvedJavaMethod method, CompilationIdentifier compilationId, OptionValues options) {
    StructuredGraph graph = super.parseForCompile(method, compilationId, options);
    // Mimic @Stable array constants.
    for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
        if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
            ConstantNode newConstantNode = graph.unique(ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess()));
            constantNode.replaceAndDelete(newConstantNode);
        }
    }
    return graph;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph)

Example 93 with ConstantNode

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

the class IfCanonicalizerTest method test.

private void test(String snippet) {
    StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
    DebugContext debug = graph.getDebug();
    ParameterNode param = graph.getNodes(ParameterNode.TYPE).iterator().next();
    ConstantNode constant = ConstantNode.forInt(0, graph);
    for (Node n : param.usages().snapshot()) {
        if (!(n instanceof FrameState)) {
            n.replaceFirstInput(param, constant);
        }
    }
    debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    for (FrameState fs : param.usages().filter(FrameState.class).snapshot()) {
        fs.replaceFirstInput(param, null);
        param.safeDelete();
    }
    StructuredGraph referenceGraph = parseEager(REFERENCE_SNIPPET, AllowAssumptions.YES);
    assertEquals(referenceGraph, graph);
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IfNode(org.graalvm.compiler.nodes.IfNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugContext(org.graalvm.compiler.debug.DebugContext) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 94 with ConstantNode

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

the class ClassCastBytecodeExceptionTest method registerInvocationPlugins.

@Override
protected void registerInvocationPlugins(InvocationPlugins invocationPlugins) {
    invocationPlugins.register(new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode obj, ValueNode classNode) {
            ResolvedJavaType type = b.getConstantReflection().asJavaType(classNode.asConstant());
            Constant hub = b.getConstantReflection().asObjectHub(type);
            Stamp hubStamp = b.getStampProvider().createHubStamp(StampFactory.object(TypeReference.createExactTrusted(type)));
            ConstantNode hubConst = b.add(ConstantNode.forConstant(hubStamp, hub, b.getMetaAccess()));
            return throwBytecodeException(b, ClassCastException.class, obj, hubConst);
        }
    }, Exceptions.class, "throwClassCast", Object.class, Class.class);
    super.registerInvocationPlugins(invocationPlugins);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Constant(jdk.vm.ci.meta.Constant) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 95 with ConstantNode

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

the class DebugInfoBuilder method toJavaValue.

protected JavaValue toJavaValue(ValueNode value) {
    try {
        if (value instanceof VirtualObjectNode) {
            VirtualObjectNode obj = (VirtualObjectNode) value;
            EscapeObjectState state = objectStates.get(obj);
            if (state == null && obj.entryCount() > 0) {
                // null states occur for objects with 0 fields
                throw new GraalError("no mapping found for virtual object %s", obj);
            }
            if (state instanceof MaterializedObjectState) {
                return toJavaValue(((MaterializedObjectState) state).materializedValue());
            } else {
                assert obj.entryCount() == 0 || state instanceof VirtualObjectState;
                VirtualObject vobject = virtualObjects.get(obj);
                if (vobject == null) {
                    vobject = VirtualObject.get(obj.type(), virtualObjects.size());
                    virtualObjects.put(obj, vobject);
                    pendingVirtualObjects.add(obj);
                }
                STATE_VIRTUAL_OBJECTS.increment(debug);
                return vobject;
            }
        } else {
            // Remove proxies from constants so the constant can be directly embedded.
            ValueNode unproxied = GraphUtil.unproxify(value);
            if (unproxied instanceof ConstantNode) {
                STATE_CONSTANTS.increment(debug);
                return unproxied.asJavaConstant();
            } else if (value != null) {
                STATE_VARIABLES.increment(debug);
                Value operand = nodeValueMap.operand(value);
                if (operand instanceof ConstantValue && ((ConstantValue) operand).isJavaConstant()) {
                    return ((ConstantValue) operand).getJavaConstant();
                } else {
                    assert operand instanceof Variable : operand + " for " + value;
                    return (JavaValue) operand;
                }
            } else {
                // return a dummy value because real value not needed
                STATE_ILLEGALS.increment(debug);
                return Value.ILLEGAL;
            }
        }
    } catch (GraalError e) {
        throw e.addContext("toValue: ", value);
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Variable(org.graalvm.compiler.lir.Variable) GraalError(org.graalvm.compiler.debug.GraalError) VirtualObjectState(org.graalvm.compiler.virtual.nodes.VirtualObjectState) VirtualObject(jdk.vm.ci.code.VirtualObject) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaValue(jdk.vm.ci.meta.JavaValue) ConstantValue(org.graalvm.compiler.lir.ConstantValue) Value(jdk.vm.ci.meta.Value) MaterializedObjectState(org.graalvm.compiler.virtual.nodes.MaterializedObjectState) ConstantValue(org.graalvm.compiler.lir.ConstantValue) EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState)

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