Search in sources :

Example 96 with ConstantNode

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

the class CompiledMethodTest method test1.

/**
 * Usages of the constant {@code " "} are replaced with the constant {@code "-"} and it is
 * verified that executing the compiled code produces a result that the preserves the node
 * replacement unless deoptimization occurs (e.g., due to -Xcomp causing profiles to be
 * missing).
 */
@Test
public void test1() {
    final ResolvedJavaMethod javaMethod = getResolvedJavaMethod("testMethod");
    final StructuredGraph graph = parseEager(javaMethod, AllowAssumptions.NO);
    new CanonicalizerPhase().apply(graph, new PhaseContext(getProviders()));
    new DeadCodeEliminationPhase().apply(graph);
    for (ConstantNode node : ConstantNode.getConstantNodes(graph)) {
        if (node.getStackKind() == JavaKind.Object && " ".equals(getSnippetReflection().asObject(String.class, node.asJavaConstant()))) {
            node.replace(graph, ConstantNode.forConstant(getSnippetReflection().forObject("-"), getMetaAccess(), graph));
        }
    }
    InstalledCode compiledMethod = getCode(javaMethod, graph);
    try {
        Object result = compiledMethod.executeVarargs("1", "2", "3");
        if (!"1-2-3".equals(result)) {
            // Deoptimization probably occurred
            Assert.assertEquals("interpreter", result);
        }
    } catch (InvalidInstalledCodeException t) {
        Assert.fail("method invalidated");
    }
}
Also used : PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvalidInstalledCodeException(jdk.vm.ci.code.InvalidInstalledCodeException) InstalledCode(jdk.vm.ci.code.InstalledCode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 97 with ConstantNode

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

the class AddNode method create.

public static ValueNode create(ValueNode x, ValueNode y, NodeView view) {
    BinaryOp<Add> op = ArithmeticOpTable.forStamp(x.stamp(view)).getAdd();
    Stamp stamp = op.foldStamp(x.stamp(view), y.stamp(view));
    ConstantNode tryConstantFold = tryConstantFold(op, x, y, stamp, view);
    if (tryConstantFold != null) {
        return tryConstantFold;
    }
    if (x.isConstant() && !y.isConstant()) {
        return canonical(null, op, y, x, view);
    } else {
        return canonical(null, op, x, y, view);
    }
}
Also used : Add(org.graalvm.compiler.core.common.type.ArithmeticOpTable.BinaryOp.Add) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp)

Example 98 with ConstantNode

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

the class CanonicalStringGraphPrinter method writeCanonicalGraphExpressionString.

protected static void writeCanonicalGraphExpressionString(ValueNode node, boolean checkConstants, boolean removeIdentities, PrintWriter writer) {
    writer.print(node.getClass().getSimpleName());
    writer.print("(");
    Fields properties = node.getNodeClass().getData();
    for (int i = 0; i < properties.getCount(); i++) {
        String dataStr = String.valueOf(properties.get(node, i));
        if (removeIdentities) {
            dataStr = removeIdentities(dataStr);
        }
        writer.print(dataStr);
        if (i + 1 < properties.getCount() || node.inputPositions().iterator().hasNext()) {
            writer.print(", ");
        }
    }
    Iterator<Position> iterator = node.inputPositions().iterator();
    while (iterator.hasNext()) {
        Position position = iterator.next();
        Node input = position.get(node);
        if (checkConstants && input instanceof ConstantNode) {
            ConstantNode constantNode = (ConstantNode) input;
            String valueString = constantNode.getValue().toValueString();
            if (removeIdentities) {
                valueString = removeIdentities(valueString);
            }
            writer.print(valueString);
        } else if (input instanceof ValueNode && !(input instanceof PhiNode) && !(input instanceof FixedNode)) {
            writeCanonicalGraphExpressionString((ValueNode) input, checkConstants, removeIdentities, writer);
        } else if (input == null) {
            writer.print("null");
        } else {
            writer.print(input.getClass().getSimpleName());
        }
        if (iterator.hasNext()) {
            writer.print(", ");
        }
    }
    writer.print(")");
}
Also used : Fields(org.graalvm.compiler.core.common.Fields) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) Position(org.graalvm.compiler.graph.Position) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 99 with ConstantNode

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

the class TypeGuardInlineInfo method createGuard.

@SuppressWarnings("try")
private void createGuard(StructuredGraph graph, Providers providers) {
    try (DebugCloseable context = invoke.asNode().withNodeSourcePosition()) {
        ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
        LoadHubNode receiverHub = graph.unique(new LoadHubNode(providers.getStampProvider(), nonNullReceiver));
        ConstantNode typeHub = ConstantNode.forConstant(receiverHub.stamp(NodeView.DEFAULT), providers.getConstantReflection().asObjectHub(type), providers.getMetaAccess(), graph);
        LogicNode typeCheck = CompareNode.createCompareNode(graph, CanonicalCondition.EQ, receiverHub, typeHub, providers.getConstantReflection(), NodeView.DEFAULT);
        FixedGuardNode guard = graph.add(new FixedGuardNode(typeCheck, DeoptimizationReason.TypeCheckedInliningViolated, DeoptimizationAction.InvalidateReprofile));
        assert invoke.predecessor() != null;
        ValueNode anchoredReceiver = InliningUtil.createAnchoredReceiver(graph, guard, type, nonNullReceiver, true);
        invoke.callTarget().replaceFirstInput(nonNullReceiver, anchoredReceiver);
        graph.addBeforeFixed(invoke.asNode(), guard);
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 100 with ConstantNode

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

the class InlineableGraph method replaceParamsWithMoreInformativeArguments.

/**
 * This method detects:
 * <ul>
 * <li>constants among the arguments to the <code>invoke</code></li>
 * <li>arguments with more precise type than that declared by the corresponding parameter</li>
 * </ul>
 *
 * <p>
 * The corresponding parameters are updated to reflect the above information. Before doing so,
 * their usages are added to <code>parameterUsages</code> for later incremental
 * canonicalization.
 * </p>
 *
 * @return null if no incremental canonicalization is need, a list of nodes for such
 *         canonicalization otherwise.
 */
private ArrayList<Node> replaceParamsWithMoreInformativeArguments(final Invoke invoke, final HighTierContext context) {
    NodeInputList<ValueNode> args = invoke.callTarget().arguments();
    ArrayList<Node> parameterUsages = null;
    List<ParameterNode> params = graph.getNodes(ParameterNode.TYPE).snapshot();
    assert params.size() <= args.size();
    /*
         * param-nodes that aren't used (eg, as a result of canonicalization) don't occur in
         * `params`. Thus, in general, the sizes of `params` and `args` don't always match. Still,
         * it's always possible to pair a param-node with its corresponding arg-node using
         * param.index() as index into `args`.
         */
    for (ParameterNode param : params) {
        if (param.usages().isNotEmpty()) {
            ValueNode arg = args.get(param.index());
            if (arg.isConstant()) {
                ConstantNode constant = (ConstantNode) arg;
                parameterUsages = trackParameterUsages(param, parameterUsages);
                // collect param usages before replacing the param
                param.replaceAtUsagesAndDelete(graph.unique(ConstantNode.forConstant(arg.stamp(NodeView.DEFAULT), constant.getValue(), constant.getStableDimension(), constant.isDefaultStable(), context.getMetaAccess())));
            // param-node gone, leaving a gap in the sequence given by param.index()
            } else {
                Stamp impro = improvedStamp(arg, param);
                if (impro != null) {
                    param.setStamp(impro);
                    parameterUsages = trackParameterUsages(param, parameterUsages);
                } else {
                    assert !isArgMoreInformativeThanParam(arg, param);
                }
            }
        }
    }
    assert (parameterUsages == null) || (!parameterUsages.isEmpty());
    return parameterUsages;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

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