Search in sources :

Example 1 with Canonicalizable

use of org.graalvm.compiler.nodes.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.nodes.virtual.VirtualObjectState) EscapeObjectState(org.graalvm.compiler.nodes.virtual.EscapeObjectState) Canonicalizable(org.graalvm.compiler.nodes.spi.Canonicalizable) ValueNode(org.graalvm.compiler.nodes.ValueNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode)

Aggregations

ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 Canonicalizable (org.graalvm.compiler.nodes.spi.Canonicalizable)1 EscapeObjectState (org.graalvm.compiler.nodes.virtual.EscapeObjectState)1 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)1 VirtualObjectState (org.graalvm.compiler.nodes.virtual.VirtualObjectState)1