Search in sources :

Example 1 with ValueNode

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

the class AMD64HotSpotAddressLowering method signExtend.

/**
 * Create a sign extend for {@code input}, or zero extend if {@code input} can be proven
 * positive.
 */
private static ValueNode signExtend(ValueNode input, LoopEx loop) {
    StructuredGraph graph = input.graph();
    if (input instanceof PhiNode) {
        EconomicMap<Node, InductionVariable> ivs = loop.getInductionVariables();
        InductionVariable inductionVariable = ivs.get(input);
        if (inductionVariable != null && inductionVariable instanceof BasicInductionVariable) {
            CountedLoopInfo countedLoopInfo = loop.counted();
            IntegerStamp initStamp = (IntegerStamp) inductionVariable.initNode().stamp(NodeView.DEFAULT);
            if (initStamp.isPositive()) {
                if (inductionVariable.isConstantExtremum()) {
                    long init = inductionVariable.constantInit();
                    long stride = inductionVariable.constantStride();
                    long extremum = inductionVariable.constantExtremum();
                    if (init >= 0 && extremum >= 0) {
                        long shortestTrip = (extremum - init) / stride + 1;
                        if (countedLoopInfo.constantMaxTripCount().equals(shortestTrip)) {
                            return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
                        }
                    }
                }
                if (countedLoopInfo.getCounter() == inductionVariable && inductionVariable.direction() == InductionVariable.Direction.Up && countedLoopInfo.getOverFlowGuard() != null) {
                    return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
                }
            }
        }
    }
    return input.graph().maybeAddOrUnique(SignExtendNode.create(input, ADDRESS_BITS, NodeView.DEFAULT));
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) PhiNode(org.graalvm.compiler.nodes.PhiNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GraalHotSpotVMConfigNode(org.graalvm.compiler.hotspot.nodes.GraalHotSpotVMConfigNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) CompressionNode(org.graalvm.compiler.nodes.CompressionNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) CountedLoopInfo(org.graalvm.compiler.loop.CountedLoopInfo) BasicInductionVariable(org.graalvm.compiler.loop.BasicInductionVariable) InductionVariable(org.graalvm.compiler.loop.InductionVariable) DerivedInductionVariable(org.graalvm.compiler.loop.DerivedInductionVariable) BasicInductionVariable(org.graalvm.compiler.loop.BasicInductionVariable) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode)

Example 2 with ValueNode

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

the class BranchProbabilityNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    if (!hasUsages()) {
        return;
    }
    if (probability.isConstant()) {
        double probabilityValue = probability.asJavaConstant().asDouble();
        if (probabilityValue < 0.0) {
            throw new GraalError("A negative probability of " + probabilityValue + " is not allowed!");
        } else if (probabilityValue > 1.0) {
            throw new GraalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!");
        } else if (Double.isNaN(probabilityValue)) {
            /*
                 * We allow NaN if the node is in unreachable code that will eventually fall away,
                 * or else an error will be thrown during lowering since we keep the node around.
                 */
            return;
        }
        boolean usageFound = false;
        for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) {
            assert node.condition() == CanonicalCondition.EQ;
            ValueNode other = node.getX();
            if (node.getX() == this) {
                other = node.getY();
            }
            if (other.isConstant()) {
                double probabilityToSet = probabilityValue;
                if (other.asJavaConstant().asInt() == 0) {
                    probabilityToSet = 1.0 - probabilityToSet;
                }
                for (IfNode ifNodeUsages : node.usages().filter(IfNode.class)) {
                    usageFound = true;
                    ifNodeUsages.setTrueSuccessorProbability(probabilityToSet);
                }
                if (!usageFound) {
                    usageFound = node.usages().filter(NodePredicates.isA(FixedGuardNode.class).or(ConditionalNode.class)).isNotEmpty();
                }
            }
        }
        if (usageFound) {
            ValueNode currentCondition = condition;
            replaceAndDelete(currentCondition);
            if (tool != null) {
                tool.addToWorkList(currentCondition.usages());
            }
        } else {
            if (!isSubstitutionGraph()) {
                throw new GraalError("Wrong usage of branch probability injection!");
            }
        }
    }
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) GraalError(org.graalvm.compiler.debug.GraalError) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 3 with ValueNode

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

the class GetClassNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool) {
    NodeView view = NodeView.from(tool);
    ValueNode folded = tryFold(tool.getMetaAccess(), tool.getConstantReflection(), view, getObject());
    return folded == null ? this : folded;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 4 with ValueNode

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

the class GetClassNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias = tool.getAlias(getObject());
    if (alias instanceof VirtualObjectNode) {
        VirtualObjectNode virtual = (VirtualObjectNode) alias;
        Constant javaClass = tool.getConstantReflectionProvider().asJavaClass(virtual.type());
        tool.replaceWithValue(ConstantNode.forConstant(stamp(NodeView.DEFAULT), javaClass, tool.getMetaAccessProvider(), graph()));
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) Constant(jdk.vm.ci.meta.Constant) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 5 with ValueNode

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

the class InstanceOfNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias = tool.getAlias(getValue());
    TriState fold = tryFold(alias.stamp(NodeView.DEFAULT));
    if (fold != TriState.UNKNOWN) {
        tool.replaceWithValue(LogicConstantNode.forBoolean(fold.isTrue(), graph()));
    }
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) TriState(jdk.vm.ci.meta.TriState)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)482 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)104 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)77 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)76 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)69 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)67 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)60 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)52 Node (org.graalvm.compiler.graph.Node)50 JavaKind (jdk.vm.ci.meta.JavaKind)48 Stamp (org.graalvm.compiler.core.common.type.Stamp)48 LogicNode (org.graalvm.compiler.nodes.LogicNode)48 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)38 FixedNode (org.graalvm.compiler.nodes.FixedNode)37 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)37 NodeView (org.graalvm.compiler.nodes.NodeView)36 PhiNode (org.graalvm.compiler.nodes.PhiNode)36 Test (org.junit.Test)36