Search in sources :

Example 31 with NodeView

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

the class LoadMethodNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (hub instanceof LoadHubNode) {
        ValueNode object = ((LoadHubNode) hub).getValue();
        TypeReference type = StampTool.typeReferenceOrNull(object);
        if (type != null) {
            if (type.isExact()) {
                return resolveExactMethod(tool, type.getType());
            }
            Assumptions assumptions = graph().getAssumptions();
            AssumptionResult<ResolvedJavaMethod> resolvedMethod = type.getType().findUniqueConcreteMethod(method);
            if (resolvedMethod != null && resolvedMethod.canRecordTo(assumptions) && !type.getType().isInterface() && method.getDeclaringClass().isAssignableFrom(type.getType())) {
                NodeView view = NodeView.from(tool);
                resolvedMethod.recordTo(assumptions);
                return ConstantNode.forConstant(stamp(view), resolvedMethod.getResult().getEncoding(), tool.getMetaAccess());
            }
        }
    }
    if (hub.isConstant()) {
        return resolveExactMethod(tool, tool.getConstantReflection().asJavaType(hub.asConstant()));
    }
    return this;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) Assumptions(jdk.vm.ci.meta.Assumptions) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) NodeView(org.graalvm.compiler.nodes.NodeView) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 32 with NodeView

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

the class TypeSwitchNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    NodeView view = NodeView.from(tool);
    if (value() instanceof ConstantNode) {
        Constant constant = value().asConstant();
        int survivingEdge = keySuccessorIndex(keyCount());
        for (int i = 0; i < keyCount(); i++) {
            Constant typeHub = keyAt(i);
            Boolean equal = tool.getConstantReflection().constantEquals(constant, typeHub);
            if (equal == null) {
                /* We don't know if this key is a match or not, so we cannot simplify. */
                return;
            } else if (equal.booleanValue()) {
                survivingEdge = keySuccessorIndex(i);
            }
        }
        killOtherSuccessors(tool, survivingEdge);
    }
    if (value() instanceof LoadHubNode && ((LoadHubNode) value()).getValue().stamp(view) instanceof ObjectStamp) {
        ObjectStamp objectStamp = (ObjectStamp) ((LoadHubNode) value()).getValue().stamp(view);
        if (objectStamp.type() != null) {
            int validKeys = 0;
            for (int i = 0; i < keyCount(); i++) {
                if (objectStamp.type().isAssignableFrom(keys[i])) {
                    validKeys++;
                }
            }
            if (validKeys == 0) {
                tool.addToWorkList(defaultSuccessor());
                graph().removeSplitPropagate(this, defaultSuccessor());
            } else if (validKeys != keys.length) {
                ArrayList<AbstractBeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
                ResolvedJavaType[] newKeys = new ResolvedJavaType[validKeys];
                int[] newKeySuccessors = new int[validKeys + 1];
                double[] newKeyProbabilities = new double[validKeys + 1];
                double totalProbability = 0;
                int current = 0;
                for (int i = 0; i < keyCount() + 1; i++) {
                    if (i == keyCount() || objectStamp.type().isAssignableFrom(keys[i])) {
                        int index = newSuccessors.indexOf(keySuccessor(i));
                        if (index == -1) {
                            index = newSuccessors.size();
                            newSuccessors.add(keySuccessor(i));
                        }
                        newKeySuccessors[current] = index;
                        if (i < keyCount()) {
                            newKeys[current] = keys[i];
                        }
                        newKeyProbabilities[current] = keyProbability(i);
                        totalProbability += keyProbability(i);
                        current++;
                    }
                }
                if (totalProbability > 0) {
                    for (int i = 0; i < current; i++) {
                        newKeyProbabilities[i] /= totalProbability;
                    }
                } else {
                    for (int i = 0; i < current; i++) {
                        newKeyProbabilities[i] = 1.0 / current;
                    }
                }
                for (int i = 0; i < blockSuccessorCount(); i++) {
                    AbstractBeginNode successor = blockSuccessor(i);
                    if (!newSuccessors.contains(successor)) {
                        tool.deleteBranch(successor);
                    }
                    setBlockSuccessor(i, null);
                }
                AbstractBeginNode[] successorsArray = newSuccessors.toArray(new AbstractBeginNode[newSuccessors.size()]);
                TypeSwitchNode newSwitch = graph().add(new TypeSwitchNode(value(), successorsArray, newKeys, newKeyProbabilities, newKeySuccessors, tool.getConstantReflection()));
                ((FixedWithNextNode) predecessor()).setNext(newSwitch);
                GraphUtil.killWithUnusedFloatingInputs(this);
            }
        }
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Constant(jdk.vm.ci.meta.Constant) ArrayList(java.util.ArrayList) NodeView(org.graalvm.compiler.nodes.NodeView) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 33 with NodeView

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

the class FloatEqualsNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    ValueNode value = OP.canonical(tool.getConstantReflection(), tool.getMetaAccess(), tool.getOptions(), tool.smallestCompareWidth(), CanonicalCondition.EQ, unorderedIsTrue, forX, forY, view);
    if (value != null) {
        return value;
    }
    return this;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 34 with NodeView

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

the class IntegerBelowNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    ValueNode value = OP.canonical(tool.getConstantReflection(), tool.getMetaAccess(), tool.getOptions(), tool.smallestCompareWidth(), OP.getCondition(), false, forX, forY, view);
    if (value != null) {
        return value;
    }
    return this;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 35 with NodeView

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

the class IntegerEqualsNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    ValueNode value = OP.canonical(tool.getConstantReflection(), tool.getMetaAccess(), tool.getOptions(), tool.smallestCompareWidth(), CanonicalCondition.EQ, false, forX, forY, view);
    if (value != null) {
        return value;
    }
    return this;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Aggregations

NodeView (org.graalvm.compiler.nodes.NodeView)37 ValueNode (org.graalvm.compiler.nodes.ValueNode)28 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4 Constant (jdk.vm.ci.meta.Constant)3 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 AddNode (org.graalvm.compiler.nodes.calc.AddNode)2 MulNode (org.graalvm.compiler.nodes.calc.MulNode)2 ArrayList (java.util.ArrayList)1 Assumptions (jdk.vm.ci.meta.Assumptions)1 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Add (org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Add)1 Mul (org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Mul)1 Sub (org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Sub)1 FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 Stamp (org.graalvm.compiler.core.common.type.Stamp)1