Search in sources :

Example 1 with NodeIterable

use of org.graalvm.compiler.graph.iterators.NodeIterable in project graal by oracle.

the class ConditionAnchoringTest method test.

public void test(String name, int ids) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    assertThat(unsafeNodes, hasCount(1));
    // lower unsafe load
    PhaseContext context = new PhaseContext(getProviders());
    LoweringPhase lowering = new LoweringPhase(new CanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
    lowering.apply(graph, context);
    unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
    assertThat(unsafeNodes, isEmpty());
    assertThat(conditionAnchors, hasCount(1));
    // 2 * ids id reads, 1 'field' access
    assertThat(reads, hasCount(2 * ids + 1));
    // float reads and canonicalize to give a chance to conditions to GVN
    FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
    floatingReadPhase.apply(graph);
    CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase();
    canonicalizerPhase.apply(graph, context);
    NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
    // 1 id read, 1 'field' access
    assertThat(floatingReads, hasCount(ids + 1));
    new ConditionalEliminationPhase(false).apply(graph, context);
    floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
    conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    assertThat(floatingReads, hasCount(1));
    assertThat(conditionAnchors, isEmpty());
    FloatingReadNode readNode = floatingReads.first();
    assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
    assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
Also used : RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Unsafe(sun.misc.Unsafe) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) TruffleGraphBuilderPlugins(org.graalvm.compiler.truffle.compiler.substitutions.TruffleGraphBuilderPlugins) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) NodeIterableIsEmpty.isEmpty(org.graalvm.compiler.graph.test.matchers.NodeIterableIsEmpty.isEmpty) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assert.assertThat(org.junit.Assert.assertThat) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) JavaKind(jdk.vm.ci.meta.JavaKind) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) IfNode(org.graalvm.compiler.nodes.IfNode) Test(org.junit.Test) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) NodeIterableCount.hasCount(org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) StandardLoweringStage(org.graalvm.compiler.nodes.spi.LoweringTool.StandardLoweringStage) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) IfNode(org.graalvm.compiler.nodes.IfNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode)

Example 2 with NodeIterable

use of org.graalvm.compiler.graph.iterators.NodeIterable in project graal by oracle.

the class UnsafeAutomaticSubstitutionProcessor method extractValueStoreField.

/**
 * If the value produced by valueNode is stored into a static final field then that field is
 * returned. If the field is either not static or not final the method returns null and the
 * reason is recorded in the unsuccessfulReasons parameter.
 */
private static ResolvedJavaField extractValueStoreField(ValueNode valueNode, List<String> unsuccessfulReasons) {
    ResolvedJavaField offsetField = null;
    NodeIterable<Node> valueNodeUsages = valueNode.usages();
    NodeIterable<StoreFieldNode> valueNodeStoreFieldUsages = valueNodeUsages.filter(StoreFieldNode.class);
    NodeIterable<SignExtendNode> valueNodeSignExtendUsages = valueNodeUsages.filter(SignExtendNode.class);
    if (valueNodeStoreFieldUsages.count() == 1) {
        offsetField = valueNodeStoreFieldUsages.first().field();
    } else if (valueNodeSignExtendUsages.count() == 1) {
        SignExtendNode signExtendNode = valueNodeSignExtendUsages.first();
        NodeIterable<StoreFieldNode> signExtendFieldStoreUsages = signExtendNode.usages().filter(StoreFieldNode.class);
        if (signExtendFieldStoreUsages.count() == 1) {
            offsetField = signExtendFieldStoreUsages.first().field();
        }
    }
    if (offsetField != null) {
        if (offsetField.isStatic() && offsetField.isFinal()) {
            return offsetField;
        } else {
            if (!offsetField.isStatic()) {
                unsuccessfulReasons.add("The offset field " + offsetField.format("%H.%n") + " is not static.");
            }
            if (!offsetField.isFinal()) {
                unsuccessfulReasons.add("The offset field " + offsetField.format("%H.%n") + " is not final.");
            }
        }
    } else {
        String producer;
        String operation;
        if (valueNode instanceof Invoke) {
            Invoke invokeNode = (Invoke) valueNode;
            producer = "call to " + invokeNode.callTarget().targetMethod().format("%H.%n(%p)");
            operation = "call";
        } else if (valueNode instanceof SubNode) {
            producer = "subtraction operation " + valueNode;
            operation = "subtraction";
        } else {
            throw VMError.shouldNotReachHere();
        }
        String message = "Could not determine the field where the value produced by the " + producer + " is stored. The " + operation + " is not directly followed by a field store or by a sign extend node followed directly by a field store. ";
        unsuccessfulReasons.add(message);
    }
    return null;
}
Also used : StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) SubNode(org.graalvm.compiler.nodes.calc.SubNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) SubNode(org.graalvm.compiler.nodes.calc.SubNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 3 with NodeIterable

use of org.graalvm.compiler.graph.iterators.NodeIterable in project graal by oracle.

the class LoopFragment method toHirExits.

public static NodeIterable<AbstractBeginNode> toHirExits(final Iterable<Block> blocks) {
    return new NodeIterable<AbstractBeginNode>() {

        @Override
        public Iterator<AbstractBeginNode> iterator() {
            final Iterator<Block> it = blocks.iterator();
            return new Iterator<AbstractBeginNode>() {

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }

                /**
                 * Return the true LoopExitNode for this loop or the BeginNode for the block.
                 */
                @Override
                public AbstractBeginNode next() {
                    Block next = it.next();
                    LoopExitNode exit = next.getLoopExit();
                    if (exit != null) {
                        return exit;
                    }
                    return next.getBeginNode();
                }

                @Override
                public boolean hasNext() {
                    return it.hasNext();
                }
            };
        }
    };
}
Also used : NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Iterator(java.util.Iterator) Block(org.graalvm.compiler.nodes.cfg.Block) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

NodeIterable (org.graalvm.compiler.graph.iterators.NodeIterable)3 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 Iterator (java.util.Iterator)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)1 Node (org.graalvm.compiler.graph.Node)1 NodeIterableCount.hasCount (org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount)1 NodeIterableIsEmpty.isEmpty (org.graalvm.compiler.graph.test.matchers.NodeIterableIsEmpty.isEmpty)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 BeginNode (org.graalvm.compiler.nodes.BeginNode)1 ConditionAnchorNode (org.graalvm.compiler.nodes.ConditionAnchorNode)1 IfNode (org.graalvm.compiler.nodes.IfNode)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 AllowAssumptions (org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions)1 SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)1 SubNode (org.graalvm.compiler.nodes.calc.SubNode)1