Search in sources :

Example 1 with GuardNode

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

the class DeadCodeEliminationPhase method run.

@Override
public void run(StructuredGraph graph) {
    if (optional && Options.ReduceDCE.getValue(graph.getOptions())) {
        return;
    }
    NodeFlood flood = graph.createNodeFlood();
    int totalNodeCount = graph.getNodeCount();
    flood.add(graph.start());
    iterateSuccessorsAndInputs(flood);
    boolean changed = false;
    for (GuardNode guard : graph.getNodes(GuardNode.TYPE)) {
        if (flood.isMarked(guard.getAnchor().asNode())) {
            flood.add(guard);
            changed = true;
        }
    }
    if (changed) {
        iterateSuccessorsAndInputs(flood);
    }
    int totalMarkedCount = flood.getTotalMarkedCount();
    if (totalNodeCount == totalMarkedCount) {
        // All nodes are live => nothing more to do.
        return;
    } else {
        // Some nodes are not marked alive and therefore dead => proceed.
        assert totalNodeCount > totalMarkedCount;
    }
    deleteNodes(flood, graph);
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) NodeFlood(org.graalvm.compiler.graph.NodeFlood)

Example 2 with GuardNode

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

the class MethodHandleNode method maybeCastArgument.

/**
 * Inserts a node to cast the argument at index to the given type if the given type is more
 * concrete than the argument type.
 *
 * @param adder
 * @param index of the argument to be cast
 * @param type the type the argument should be cast to
 */
private static void maybeCastArgument(GraphAdder adder, ValueNode[] arguments, int index, JavaType type) {
    ValueNode argument = arguments[index];
    if (type instanceof ResolvedJavaType && !((ResolvedJavaType) type).isJavaLangObject()) {
        Assumptions assumptions = adder.getAssumptions();
        TypeReference targetType = TypeReference.create(assumptions, (ResolvedJavaType) type);
        /*
             * When an argument is a Word type, we can have a mismatch of primitive/object types
             * here. Not inserting a PiNode is a safe fallback, and Word types need no additional
             * type information anyway.
             */
        if (targetType != null && !targetType.getType().isPrimitive() && !argument.getStackKind().isPrimitive()) {
            ResolvedJavaType argumentType = StampTool.typeOrNull(argument.stamp(NodeView.DEFAULT));
            if (argumentType == null || (argumentType.isAssignableFrom(targetType.getType()) && !argumentType.equals(targetType.getType()))) {
                LogicNode inst = InstanceOfNode.createAllowNull(targetType, argument, null, null);
                assert !inst.isAlive();
                if (!inst.isTautology()) {
                    inst = adder.add(inst);
                    AnchoringNode guardAnchor = adder.getGuardAnchor();
                    DeoptimizationReason reason = DeoptimizationReason.ClassCastException;
                    DeoptimizationAction action = DeoptimizationAction.InvalidateRecompile;
                    JavaConstant speculation = JavaConstant.NULL_POINTER;
                    GuardingNode guard;
                    if (guardAnchor == null) {
                        FixedGuardNode fixedGuard = adder.add(new FixedGuardNode(inst, reason, action, speculation, false));
                        guard = fixedGuard;
                    } else {
                        GuardNode newGuard = adder.add(new GuardNode(inst, guardAnchor, reason, action, false, speculation));
                        adder.add(new ValueAnchorNode(newGuard));
                        guard = newGuard;
                    }
                    ValueNode valueNode = adder.add(PiNode.create(argument, StampFactory.object(targetType), guard.asNode()));
                    arguments[index] = valueNode;
                }
            }
        }
    }
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) AnchoringNode(org.graalvm.compiler.nodes.extended.AnchoringNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Assumptions(jdk.vm.ci.meta.Assumptions) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 3 with GuardNode

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

the class CountedLoopInfo method createOverFlowGuard.

@SuppressWarnings("try")
public GuardingNode createOverFlowGuard() {
    GuardingNode overflowGuard = getOverFlowGuard();
    if (overflowGuard != null) {
        return overflowGuard;
    }
    try (DebugCloseable position = loop.loopBegin().withNodeSourcePosition()) {
        IntegerStamp stamp = (IntegerStamp) iv.valueNode().stamp(NodeView.DEFAULT);
        StructuredGraph graph = iv.valueNode().graph();
        // we use a negated guard with a < condition to achieve a >=
        CompareNode cond;
        ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
        if (iv.direction() == Direction.Up) {
            ValueNode v1 = sub(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.maxValue(stamp.getBits()), graph), sub(graph, iv.strideNode(), one));
            if (oneOff) {
                v1 = sub(graph, v1, one);
            }
            cond = graph.unique(new IntegerLessThanNode(v1, end));
        } else {
            assert iv.direction() == Direction.Down;
            ValueNode v1 = add(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.minValue(stamp.getBits()), graph), sub(graph, one, iv.strideNode()));
            if (oneOff) {
                v1 = add(graph, v1, one);
            }
            cond = graph.unique(new IntegerLessThanNode(end, v1));
        }
        assert graph.getGuardsStage().allowsFloatingGuards();
        overflowGuard = graph.unique(new GuardNode(cond, AbstractBeginNode.prevBegin(loop.entryPoint()), DeoptimizationReason.LoopLimitCheck, DeoptimizationAction.InvalidateRecompile, true, // TODO gd: use speculation
        JavaConstant.NULL_POINTER));
        loop.loopBegin().setOverflowGuard(overflowGuard);
        return overflowGuard;
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 4 with GuardNode

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

the class LoopFragment method markFloating.

private static void markFloating(Deque<WorkListEntry> workList, Node start, NodeBitMap loopNodes, NodeBitMap nonLoopNodes) {
    if (isLoopNode(start, loopNodes, nonLoopNodes).isKnown()) {
        return;
    }
    pushWorkList(workList, start, loopNodes);
    while (!workList.isEmpty()) {
        WorkListEntry currentEntry = workList.peek();
        if (currentEntry.usages.hasNext()) {
            Node current = currentEntry.usages.next();
            TriState result = isLoopNode(current, loopNodes, nonLoopNodes);
            if (result.isKnown()) {
                if (result.toBoolean()) {
                    currentEntry.isLoopNode = true;
                }
            } else {
                pushWorkList(workList, current, loopNodes);
            }
        } else {
            workList.pop();
            boolean isLoopNode = currentEntry.isLoopNode;
            Node current = currentEntry.n;
            if (!isLoopNode && current instanceof GuardNode) {
                /*
                     * (gd) this is only OK if we are not going to make loop transforms based on
                     * this
                     */
                assert !((GuardNode) current).graph().hasValueProxies();
                isLoopNode = true;
            }
            if (isLoopNode) {
                loopNodes.mark(current);
                for (WorkListEntry e : workList) {
                    e.isLoopNode = true;
                }
            } else {
                nonLoopNodes.mark(current);
            }
        }
    }
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) GuardProxyNode(org.graalvm.compiler.nodes.GuardProxyNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) TriState(jdk.vm.ci.meta.TriState)

Example 5 with GuardNode

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

the class GuardPrioritiesTest method unknownTest.

@Test
public void unknownTest() {
    assumeTrue("GuardPriorities must be turned one", GraalOptions.GuardPriorities.getValue(getInitialOptions()));
    StructuredGraph graph = prepareGraph("unknownCondition");
    new SchedulePhase(SchedulePhase.SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER).apply(graph);
    for (GuardNode g1 : graph.getNodes(GuardNode.TYPE)) {
        for (GuardNode g2 : graph.getNodes(GuardNode.TYPE)) {
            if (g1.getSpeculation().isNull() ^ g2.getSpeculation().isNull()) {
                GuardNode withSpeculation = g1.getSpeculation().isNull() ? g2 : g1;
                GuardNode withoutSpeculation = g1.getSpeculation().isNull() ? g1 : g2;
                if (withoutSpeculation.isNegated() && withoutSpeculation.getCondition() instanceof IsNullNode) {
                    IsNullNode isNullNode = (IsNullNode) withoutSpeculation.getCondition();
                    if (isNullNode.getValue() instanceof ParameterNode && ((ParameterNode) isNullNode.getValue()).index() == 1) {
                        // this is the null check before the speculative guard, it's the only
                        // one that should be above
                        assertOrderedAfterLastSchedule(graph, withoutSpeculation, withSpeculation);
                        continue;
                    }
                }
                assertOrderedAfterLastSchedule(graph, withSpeculation, withoutSpeculation);
            }
        }
    }
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) Test(org.junit.Test)

Aggregations

GuardNode (org.graalvm.compiler.nodes.GuardNode)9 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 Node (org.graalvm.compiler.graph.Node)3 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)3 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 FixedNode (org.graalvm.compiler.nodes.FixedNode)3 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)3 PhiNode (org.graalvm.compiler.nodes.PhiNode)3 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)3 Test (org.junit.Test)3 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)2 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)2 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)2 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)2 PiNode (org.graalvm.compiler.nodes.PiNode)2