Search in sources :

Example 1 with LogicConstantNode

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

the class NormalizeCompareNode method tryConstantFold.

protected static ValueNode tryConstantFold(ValueNode x, ValueNode y, boolean isUnorderedLess, JavaKind kind, ConstantReflectionProvider constantReflection) {
    LogicNode result = CompareNode.tryConstantFold(CanonicalCondition.EQ, x, y, null, false);
    if (result instanceof LogicConstantNode) {
        LogicConstantNode logicConstantNode = (LogicConstantNode) result;
        LogicNode resultLT = CompareNode.tryConstantFold(CanonicalCondition.LT, x, y, constantReflection, isUnorderedLess);
        if (resultLT instanceof LogicConstantNode) {
            LogicConstantNode logicConstantNodeLT = (LogicConstantNode) resultLT;
            if (logicConstantNodeLT.getValue()) {
                return ConstantNode.forIntegerKind(kind, -1);
            } else if (logicConstantNode.getValue()) {
                return ConstantNode.forIntegerKind(kind, 0);
            } else {
                return ConstantNode.forIntegerKind(kind, 1);
            }
        }
    }
    return null;
}
Also used : LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 2 with LogicConstantNode

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

the class GraphChangeMonitoringPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, C context) {
    /*
         * Phase may add nodes but not end up using them so ignore additions. Nodes going dead and
         * having their inputs change are the main interesting differences.
         */
    HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NodeEvent.NODE_ADDED);
    StructuredGraph graphCopy = (StructuredGraph) graph.copy(graph.getDebug());
    DebugContext debug = graph.getDebug();
    try (NodeEventScope s = graphCopy.trackNodeEvents(listener)) {
        try (DebugContext.Scope s2 = debug.sandbox("WithoutMonitoring", null)) {
            super.run(graphCopy, context);
        } catch (Throwable t) {
            debug.handle(t);
        }
    }
    EconomicSet<Node> filteredNodes = EconomicSet.create(Equivalence.IDENTITY);
    for (Node n : listener.getNodes()) {
        if (n instanceof LogicConstantNode) {
        // Ignore LogicConstantNode since those are sometimes created and deleted as part of
        // running a phase.
        } else {
            filteredNodes.add(n);
        }
    }
    if (!filteredNodes.isEmpty()) {
        /* rerun it on the real graph in a new Debug scope so Dump and Log can find it. */
        listener = new HashSetNodeEventListener();
        try (NodeEventScope s = graph.trackNodeEvents(listener)) {
            try (DebugContext.Scope s2 = debug.scope("WithGraphChangeMonitoring")) {
                if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
                    debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** Before phase %s", getName());
                }
                super.run(graph, context);
                if (debug.isDumpEnabled(DebugContext.DETAILED_LEVEL)) {
                    debug.dump(DebugContext.DETAILED_LEVEL, graph, "*** After phase %s %s", getName(), filteredNodes);
                }
                debug.log("*** %s %s %s\n", message, graph, filteredNodes);
            }
        }
    } else {
        // Go ahead and run it normally even though it should have no effect
        super.run(graph, context);
    }
}
Also used : HashSetNodeEventListener(org.graalvm.compiler.phases.common.util.HashSetNodeEventListener) NodeEventScope(org.graalvm.compiler.graph.Graph.NodeEventScope) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) Node(org.graalvm.compiler.graph.Node) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) DebugContext(org.graalvm.compiler.debug.DebugContext)

Example 3 with LogicConstantNode

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

the class EffectsClosure method processBlock.

@Override
protected BlockT processBlock(Block block, BlockT state) {
    if (!state.isDead()) {
        GraphEffectList effects = blockEffects.get(block);
        /*
             * If we enter an if branch that is known to be unreachable, we mark it as dead and
             * cease to do any more analysis on it. At merges, these dead branches will be ignored.
             */
        if (block.getBeginNode().predecessor() instanceof IfNode) {
            IfNode ifNode = (IfNode) block.getBeginNode().predecessor();
            LogicNode condition = ifNode.condition();
            Node alias = getScalarAlias(condition);
            if (alias instanceof LogicConstantNode) {
                LogicConstantNode constant = (LogicConstantNode) alias;
                boolean isTrueSuccessor = block.getBeginNode() == ifNode.trueSuccessor();
                if (constant.getValue() != isTrueSuccessor) {
                    state.markAsDead();
                    effects.killIfBranch(ifNode, constant.getValue());
                    return state;
                }
            }
        }
        OptionValues options = block.getBeginNode().getOptions();
        VirtualUtil.trace(options, debug, "\nBlock: %s, preds: %s, succ: %s (", block, block.getPredecessors(), block.getSuccessors());
        // a lastFixedNode is needed in case we want to insert fixed nodes
        FixedWithNextNode lastFixedNode = null;
        Iterable<? extends Node> nodes = schedule != null ? schedule.getBlockToNodesMap().get(block) : block.getNodes();
        for (Node node : nodes) {
            // reset the aliases (may be non-null due to iterative loop processing)
            aliases.set(node, null);
            if (node instanceof LoopExitNode) {
                LoopExitNode loopExit = (LoopExitNode) node;
                for (ProxyNode proxy : loopExit.proxies()) {
                    aliases.set(proxy, null);
                    changed |= processNode(proxy, state, effects, lastFixedNode) && isSignificantNode(node);
                }
                processLoopExit(loopExit, loopEntryStates.get(loopExit.loopBegin()), state, blockEffects.get(block));
            }
            changed |= processNode(node, state, effects, lastFixedNode) && isSignificantNode(node);
            if (node instanceof FixedWithNextNode) {
                lastFixedNode = (FixedWithNextNode) node;
            }
            if (state.isDead()) {
                break;
            }
        }
        VirtualUtil.trace(options, debug, ")\n    end state: %s\n", state);
    }
    return state;
}
Also used : ProxyNode(org.graalvm.compiler.nodes.ProxyNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) OptionValues(org.graalvm.compiler.options.OptionValues) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) IfNode(org.graalvm.compiler.nodes.IfNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 4 with LogicConstantNode

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

the class BytecodeParser method genIf.

protected void genIf(LogicNode conditionInput, BciBlock trueBlockInput, BciBlock falseBlockInput, double probabilityInput) {
    BciBlock trueBlock = trueBlockInput;
    BciBlock falseBlock = falseBlockInput;
    LogicNode condition = conditionInput;
    double probability = probabilityInput;
    FrameState stateBefore = null;
    ProfilingPlugin profilingPlugin = this.graphBuilderConfig.getPlugins().getProfilingPlugin();
    if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
        stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
    }
    // Remove a logic negation node.
    if (condition instanceof LogicNegationNode) {
        LogicNegationNode logicNegationNode = (LogicNegationNode) condition;
        BciBlock tmpBlock = trueBlock;
        trueBlock = falseBlock;
        falseBlock = tmpBlock;
        probability = 1 - probability;
        condition = logicNegationNode.getValue();
    }
    if (condition instanceof LogicConstantNode) {
        genConstantTargetIf(trueBlock, falseBlock, condition);
    } else {
        if (condition.graph() == null) {
            condition = genUnique(condition);
        }
        if (isNeverExecutedCode(probability)) {
            append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, true));
            if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
                profilingPlugin.profileGoto(this, method, bci(), falseBlock.startBci, stateBefore);
            }
            appendGoto(falseBlock);
            return;
        } else if (isNeverExecutedCode(1 - probability)) {
            append(new FixedGuardNode(condition, UnreachedCode, InvalidateReprofile, false));
            if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
                profilingPlugin.profileGoto(this, method, bci(), trueBlock.startBci, stateBefore);
            }
            appendGoto(trueBlock);
            return;
        }
        if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
            profilingPlugin.profileIf(this, method, bci(), condition, trueBlock.startBci, falseBlock.startBci, stateBefore);
        }
        int oldBci = stream.currentBCI();
        int trueBlockInt = checkPositiveIntConstantPushed(trueBlock);
        if (trueBlockInt != -1) {
            int falseBlockInt = checkPositiveIntConstantPushed(falseBlock);
            if (falseBlockInt != -1) {
                if (tryGenConditionalForIf(trueBlock, falseBlock, condition, oldBci, trueBlockInt, falseBlockInt)) {
                    return;
                }
            }
        }
        this.controlFlowSplit = true;
        FixedNode trueSuccessor = createTarget(trueBlock, frameState, false, false);
        FixedNode falseSuccessor = createTarget(falseBlock, frameState, false, true);
        ValueNode ifNode = genIfNode(condition, trueSuccessor, falseSuccessor, probability);
        postProcessIfNode(ifNode);
        append(ifNode);
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicNegationNode(org.graalvm.compiler.nodes.LogicNegationNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) FrameState(org.graalvm.compiler.nodes.FrameState) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ProfilingPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)

Example 5 with LogicConstantNode

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

the class BytecodeParser method genConstantTargetIf.

private void genConstantTargetIf(BciBlock trueBlock, BciBlock falseBlock, LogicNode condition) {
    LogicConstantNode constantLogicNode = (LogicConstantNode) condition;
    boolean value = constantLogicNode.getValue();
    BciBlock nextBlock = falseBlock;
    if (value) {
        nextBlock = trueBlock;
    }
    int startBci = nextBlock.startBci;
    int targetAtStart = stream.readUByte(startBci);
    if (targetAtStart == Bytecodes.GOTO && nextBlock.getPredecessorCount() == 1) {
        // This is an empty block. Skip it.
        BciBlock successorBlock = nextBlock.successors.get(0);
        ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
        if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
            FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
            profilingPlugin.profileGoto(this, method, bci(), successorBlock.startBci, stateBefore);
        }
        appendGoto(successorBlock);
        assert nextBlock.numNormalSuccessors() == 1;
    } else {
        ProfilingPlugin profilingPlugin = graphBuilderConfig.getPlugins().getProfilingPlugin();
        if (profilingPlugin != null && profilingPlugin.shouldProfile(this, method)) {
            FrameState stateBefore = frameState.create(bci(), getNonIntrinsicAncestor(), false, null, null);
            profilingPlugin.profileGoto(this, method, bci(), nextBlock.startBci, stateBefore);
        }
        appendGoto(nextBlock);
    }
}
Also used : LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) FrameState(org.graalvm.compiler.nodes.FrameState) BciBlock(org.graalvm.compiler.java.BciBlockMapping.BciBlock) RuntimeConstraint(jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint) ProfilingPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)

Aggregations

LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)3 RuntimeConstraint (jdk.vm.ci.meta.DeoptimizationReason.RuntimeConstraint)2 Node (org.graalvm.compiler.graph.Node)2 BciBlock (org.graalvm.compiler.java.BciBlockMapping.BciBlock)2 FrameState (org.graalvm.compiler.nodes.FrameState)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 ProfilingPlugin (org.graalvm.compiler.nodes.graphbuilderconf.ProfilingPlugin)2 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 PlatformKind (jdk.vm.ci.meta.PlatformKind)1 Value (jdk.vm.ci.meta.Value)1 LIRKind (org.graalvm.compiler.core.common.LIRKind)1 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)1 DebugContext (org.graalvm.compiler.debug.DebugContext)1 NodeEventScope (org.graalvm.compiler.graph.Graph.NodeEventScope)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 IfNode (org.graalvm.compiler.nodes.IfNode)1