Search in sources :

Example 1 with Canonicalizable

use of org.graalvm.compiler.graph.spi.Canonicalizable in project graal by oracle.

the class SimplifyingGraphDecoder method canonicalizeFixedNode.

/**
 * Canonicalizes the provided node, which was originally a {@link FixedNode} but can already be
 * canonicalized (and therefore be a non-fixed node).
 *
 * @param methodScope The current method.
 * @param node The node to be canonicalized.
 */
protected Node canonicalizeFixedNode(MethodScope methodScope, Node node) {
    if (node instanceof LoadFieldNode) {
        LoadFieldNode loadFieldNode = (LoadFieldNode) node;
        return loadFieldNode.canonical(canonicalizerTool);
    } else if (node instanceof FixedGuardNode) {
        FixedGuardNode guard = (FixedGuardNode) node;
        if (guard.getCondition() instanceof LogicConstantNode) {
            LogicConstantNode condition = (LogicConstantNode) guard.getCondition();
            if (condition.getValue() == guard.isNegated()) {
                DeoptimizeNode deopt = new DeoptimizeNode(guard.getAction(), guard.getReason(), guard.getSpeculation());
                if (guard.stateBefore() != null) {
                    deopt.setStateBefore(guard.stateBefore());
                }
                return deopt;
            } else {
                return null;
            }
        }
        return node;
    } else if (node instanceof IfNode) {
        IfNode ifNode = (IfNode) node;
        if (ifNode.condition() instanceof LogicNegationNode) {
            ifNode.eliminateNegation();
        }
        if (ifNode.condition() instanceof LogicConstantNode) {
            boolean condition = ((LogicConstantNode) ifNode.condition()).getValue();
            AbstractBeginNode survivingSuccessor = ifNode.getSuccessor(condition);
            AbstractBeginNode deadSuccessor = ifNode.getSuccessor(!condition);
            graph.removeSplit(ifNode, survivingSuccessor);
            assert deadSuccessor.next() == null : "must not be parsed yet";
            deadSuccessor.safeDelete();
        }
        return node;
    } else if (node instanceof LoadIndexedNode) {
        LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
        return loadIndexedNode.canonical(canonicalizerTool);
    } else if (node instanceof ArrayLengthNode) {
        ArrayLengthNode arrayLengthNode = (ArrayLengthNode) node;
        return arrayLengthNode.canonical(canonicalizerTool);
    } else if (node instanceof IntegerSwitchNode && ((IntegerSwitchNode) node).value().isConstant()) {
        IntegerSwitchNode switchNode = (IntegerSwitchNode) node;
        int value = switchNode.value().asJavaConstant().asInt();
        AbstractBeginNode survivingSuccessor = switchNode.successorAtKey(value);
        List<Node> allSuccessors = switchNode.successors().snapshot();
        graph.removeSplit(switchNode, survivingSuccessor);
        for (Node successor : allSuccessors) {
            if (successor != survivingSuccessor) {
                assert ((AbstractBeginNode) successor).next() == null : "must not be parsed yet";
                successor.safeDelete();
            }
        }
        return node;
    } else if (node instanceof Canonicalizable) {
        return ((Canonicalizable) node).canonical(canonicalizerTool);
    } else {
        return node;
    }
}
Also used : IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) Node(org.graalvm.compiler.graph.Node) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) Canonicalizable(org.graalvm.compiler.graph.spi.Canonicalizable) List(java.util.List) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode)

Example 2 with Canonicalizable

use of org.graalvm.compiler.graph.spi.Canonicalizable in project graal by oracle.

the class PartialEscapeClosure method processNodeWithScalarReplacedInputs.

/**
 * This tries to canonicalize the node based on improved (replaced) inputs.
 */
@SuppressWarnings("unchecked")
private boolean processNodeWithScalarReplacedInputs(ValueNode node, FixedNode insertBefore, BlockT state, GraphEffectList effects) {
    ValueNode canonicalizedValue = node;
    if (node instanceof Canonicalizable.Unary<?>) {
        Canonicalizable.Unary<ValueNode> canonicalizable = (Canonicalizable.Unary<ValueNode>) node;
        ObjectState valueObj = getObjectState(state, canonicalizable.getValue());
        ValueNode valueAlias = valueObj != null ? valueObj.getMaterializedValue() : getScalarAlias(canonicalizable.getValue());
        if (valueAlias != canonicalizable.getValue()) {
            canonicalizedValue = (ValueNode) canonicalizable.canonical(tool, valueAlias);
        }
    } else if (node instanceof Canonicalizable.Binary<?>) {
        Canonicalizable.Binary<ValueNode> canonicalizable = (Canonicalizable.Binary<ValueNode>) node;
        ObjectState xObj = getObjectState(state, canonicalizable.getX());
        ValueNode xAlias = xObj != null ? xObj.getMaterializedValue() : getScalarAlias(canonicalizable.getX());
        ObjectState yObj = getObjectState(state, canonicalizable.getY());
        ValueNode yAlias = yObj != null ? yObj.getMaterializedValue() : getScalarAlias(canonicalizable.getY());
        if (xAlias != canonicalizable.getX() || yAlias != canonicalizable.getY()) {
            canonicalizedValue = (ValueNode) canonicalizable.canonical(tool, xAlias, yAlias);
        }
    } else {
        return false;
    }
    if (canonicalizedValue != node && canonicalizedValue != null) {
        if (canonicalizedValue.isAlive()) {
            ValueNode alias = getAliasAndResolve(state, canonicalizedValue);
            if (alias instanceof VirtualObjectNode) {
                addVirtualAlias((VirtualObjectNode) alias, node);
                effects.deleteNode(node);
            } else {
                effects.replaceAtUsages(node, alias, insertBefore);
                addScalarAlias(node, alias);
            }
        } else {
            if (!prepareCanonicalNode(canonicalizedValue, state, effects)) {
                VirtualUtil.trace(node.getOptions(), debug, "replacement via canonicalization too complex: %s -> %s", node, canonicalizedValue);
                return false;
            }
            if (canonicalizedValue instanceof ControlSinkNode) {
                effects.replaceWithSink((FixedWithNextNode) node, (ControlSinkNode) canonicalizedValue);
                state.markAsDead();
            } else {
                effects.replaceAtUsages(node, canonicalizedValue, insertBefore);
                addScalarAlias(node, canonicalizedValue);
            }
        }
        VirtualUtil.trace(node.getOptions(), debug, "replaced via canonicalization: %s -> %s", node, canonicalizedValue);
        return true;
    }
    return false;
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualObjectState(org.graalvm.compiler.virtual.nodes.VirtualObjectState) Canonicalizable(org.graalvm.compiler.graph.spi.Canonicalizable) ValueNode(org.graalvm.compiler.nodes.ValueNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode)

Aggregations

Canonicalizable (org.graalvm.compiler.graph.spi.Canonicalizable)2 List (java.util.List)1 Node (org.graalvm.compiler.graph.Node)1 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 FloatingNode (org.graalvm.compiler.nodes.calc.FloatingNode)1 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)1 IntegerSwitchNode (org.graalvm.compiler.nodes.extended.IntegerSwitchNode)1 ArrayLengthNode (org.graalvm.compiler.nodes.java.ArrayLengthNode)1 LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)1 LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)1 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)1 VirtualObjectState (org.graalvm.compiler.virtual.nodes.VirtualObjectState)1