Search in sources :

Example 21 with ConstantNode

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

the class CompileQueue method handleSpecialization.

private static void handleSpecialization(final HostedMethod method, MethodCallTargetNode targetNode, HostedMethod invokeTarget, HostedMethod invokeImplementation) {
    if (method.getAnnotation(Specialize.class) != null && !method.compilationInfo.isDeoptTarget() && invokeTarget.getAnnotation(DeoptTest.class) != null) {
        /*
             * Collect the constant arguments to a method which should be specialized.
             */
        if (invokeImplementation.compilationInfo.specializedArguments != null) {
            VMError.shouldNotReachHere("Specialized method " + invokeImplementation.format("%H.%n(%p)") + " can only be called from one place");
        }
        invokeImplementation.compilationInfo.specializedArguments = new ConstantNode[targetNode.arguments().size()];
        int idx = 0;
        for (ValueNode argument : targetNode.arguments()) {
            if (!(argument instanceof ConstantNode)) {
                VMError.shouldNotReachHere("Argument " + idx + " of specialized method " + invokeImplementation.format("%H.%n(%p)") + " is not constant");
            }
            invokeImplementation.compilationInfo.specializedArguments[idx++] = (ConstantNode) argument;
        }
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Specialize(com.oracle.svm.core.annotate.Specialize) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint)

Example 22 with ConstantNode

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

the class CompileQueue method ensureCompiled.

protected void ensureCompiled(HostedMethod method, CompileReason reason) {
    CompileTask task = new CompileTask(method, reason);
    CompileTask oldTask = compilations.putIfAbsent(method, task);
    if (oldTask != null) {
        // Method is already scheduled for compilation.
        if (oldTask.allReasons != null) {
            oldTask.allReasons.add(reason);
        }
        return;
    }
    if (method.compilationInfo.specializedArguments != null) {
        // Do the specialization: replace the argument locals with the constant arguments.
        StructuredGraph graph = method.compilationInfo.graph;
        int idx = 0;
        for (ConstantNode argument : method.compilationInfo.specializedArguments) {
            ParameterNode local = graph.getParameter(idx++);
            if (local != null) {
                local.replaceAndDelete(ConstantNode.forConstant(argument.asJavaConstant(), runtimeConfig.getProviders().getMetaAccess(), graph));
            }
        }
    }
    executor.execute(task);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint)

Example 23 with ConstantNode

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

the class NodeLIRBuilder method createPhiOut.

private Value[] createPhiOut(AbstractMergeNode merge, AbstractEndNode pred) {
    List<Value> values = new ArrayList<>();
    for (PhiNode phi : merge.valuePhis()) {
        ValueNode node = phi.valueAt(pred);
        Value value = operand(node);
        assert value != null;
        if (isRegister(value)) {
            /*
                 * Fixed register intervals are not allowed at block boundaries so we introduce a
                 * new Variable.
                 */
            value = gen.emitMove(value);
        } else if (!allowObjectConstantToStackMove() && node instanceof ConstantNode && !LIRKind.isValue(value)) {
            /*
                 * Some constants are not allowed as inputs for PHIs in certain backends. Explicitly
                 * create a copy of this value to force it into a register. The new variable is only
                 * used in the PHI.
                 */
            Variable result = gen.newVariable(value.getValueKind());
            gen.emitMove(result, value);
            value = result;
        }
        values.add(value);
    }
    return values.toArray(new Value[values.size()]);
}
Also used : LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Variable(org.graalvm.compiler.lir.Variable) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) ArrayList(java.util.ArrayList) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 24 with ConstantNode

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

the class CountedLoopInfo method maxTripCountNode.

/**
 * Returns a node that computes the maximum trip count of this loop. That is the trip count of
 * this loop assuming it is not exited by an other exit than the {@linkplain #getLimitTest()
 * count check}.
 *
 * This count is exact if {@link #isExactTripCount()} returns true.
 *
 * THIS VALUE SHOULD BE TREATED AS UNSIGNED.
 *
 * @param assumePositive if true the check that the loop is entered at all will be omitted.
 */
public ValueNode maxTripCountNode(boolean assumePositive) {
    StructuredGraph graph = iv.valueNode().graph();
    Stamp stamp = iv.valueNode().stamp(NodeView.DEFAULT);
    ValueNode max;
    ValueNode min;
    ValueNode range;
    ValueNode absStride;
    if (iv.direction() == Direction.Up) {
        absStride = iv.strideNode();
        range = sub(graph, end, iv.initNode());
        max = end;
        min = iv.initNode();
    } else {
        assert iv.direction() == Direction.Down;
        absStride = graph.maybeAddOrUnique(NegateNode.create(iv.strideNode(), NodeView.DEFAULT));
        range = sub(graph, iv.initNode(), end);
        max = iv.initNode();
        min = end;
    }
    ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
    if (oneOff) {
        range = add(graph, range, one);
    }
    // round-away-from-zero divison: (range + stride -/+ 1) / stride
    ValueNode denominator = add(graph, range, sub(graph, absStride, one));
    ValueNode div = unsignedDivBefore(graph, loop.entryPoint(), denominator, absStride);
    if (assumePositive) {
        return div;
    }
    ConstantNode zero = ConstantNode.forIntegerStamp(stamp, 0, graph);
    return graph.unique(new ConditionalNode(graph.unique(new IntegerLessThanNode(max, min)), zero, div));
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode)

Example 25 with ConstantNode

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

the class CountedLoopInfo method createOverFlowGuard.

@SuppressWarnings("try")
public GuardingNode createOverFlowGuard() {
    GuardingNode overflowGuard = getOverFlowGuard();
    if (overflowGuard != null) {
        return overflowGuard;
    }
    try (DebugCloseable position = loop.loopBegin().withNodeSourcePosition()) {
        IntegerStamp stamp = (IntegerStamp) iv.valueNode().stamp(NodeView.DEFAULT);
        StructuredGraph graph = iv.valueNode().graph();
        // we use a negated guard with a < condition to achieve a >=
        CompareNode cond;
        ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
        if (iv.direction() == Direction.Up) {
            ValueNode v1 = sub(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.maxValue(stamp.getBits()), graph), sub(graph, iv.strideNode(), one));
            if (oneOff) {
                v1 = sub(graph, v1, one);
            }
            cond = graph.unique(new IntegerLessThanNode(v1, end));
        } else {
            assert iv.direction() == Direction.Down;
            ValueNode v1 = add(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.minValue(stamp.getBits()), graph), sub(graph, one, iv.strideNode()));
            if (oneOff) {
                v1 = add(graph, v1, one);
            }
            cond = graph.unique(new IntegerLessThanNode(end, v1));
        }
        assert graph.getGuardsStage().allowsFloatingGuards();
        overflowGuard = graph.unique(new GuardNode(cond, AbstractBeginNode.prevBegin(loop.entryPoint()), DeoptimizationReason.LoopLimitCheck, DeoptimizationAction.InvalidateRecompile, true, // TODO gd: use speculation
        JavaConstant.NULL_POINTER));
        loop.loopBegin().setOverflowGuard(overflowGuard);
        return overflowGuard;
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Aggregations

ConstantNode (org.graalvm.compiler.nodes.ConstantNode)100 ValueNode (org.graalvm.compiler.nodes.ValueNode)46 JavaConstant (jdk.vm.ci.meta.JavaConstant)32 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)28 Stamp (org.graalvm.compiler.core.common.type.Stamp)23 Test (org.junit.Test)15 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)14 Node (org.graalvm.compiler.graph.Node)14 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 PhiNode (org.graalvm.compiler.nodes.PhiNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)10 ArrayList (java.util.ArrayList)9 JavaKind (jdk.vm.ci.meta.JavaKind)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 Constant (jdk.vm.ci.meta.Constant)8 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)8 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)7