Search in sources :

Example 56 with ConstantNode

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

the class NegateNodeCanonicalizationTest method testShort.

@Test
public void testShort() {
    short[] a = new short[] { Short.MIN_VALUE, Short.MIN_VALUE + 1, -1, 0, 1, Short.MAX_VALUE - 1, Short.MAX_VALUE };
    for (short i : a) {
        ConstantNode node = ConstantNode.forShort(i, graph);
        JavaConstant expected = JavaConstant.forInt(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 57 with ConstantNode

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

the class NegateNodeCanonicalizationTest method testDouble.

@Test
public void testDouble() {
    double[] a = new double[] { Double.MIN_VALUE, Double.MIN_VALUE + 1, -1, 0, 1, Double.MAX_VALUE - 1, Double.MAX_VALUE };
    for (double i : a) {
        ConstantNode node = ConstantNode.forDouble(i, graph);
        JavaConstant expected = JavaConstant.forDouble(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 58 with ConstantNode

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

the class LoopFragmentInside method insertWithinAfter.

/**
 * Duplicate the body within the loop after the current copy copy of the body.
 *
 * @param loop
 * @param updateLimit true if the iteration limit should be adjusted.
 */
public void insertWithinAfter(LoopEx loop, boolean updateLimit) {
    assert isDuplicate() && original().loop() == loop;
    patchNodes(dataFixWithinAfter);
    /*
         * Collect any new back edges values before updating them since they might reference each
         * other.
         */
    LoopBeginNode mainLoopBegin = loop.loopBegin();
    ArrayList<ValueNode> backedgeValues = new ArrayList<>();
    for (PhiNode mainPhiNode : mainLoopBegin.phis()) {
        ValueNode duplicatedNode = getDuplicatedNode(mainPhiNode.valueAt(1));
        if (duplicatedNode == null) {
            if (mainLoopBegin.isPhiAtMerge(mainPhiNode.valueAt(1))) {
                duplicatedNode = ((PhiNode) (mainPhiNode.valueAt(1))).valueAt(1);
            } else {
                assert mainPhiNode.valueAt(1).isConstant() : mainPhiNode.valueAt(1);
            }
        }
        backedgeValues.add(duplicatedNode);
    }
    int index = 0;
    for (PhiNode mainPhiNode : mainLoopBegin.phis()) {
        ValueNode duplicatedNode = backedgeValues.get(index++);
        if (duplicatedNode != null) {
            mainPhiNode.setValueAt(1, duplicatedNode);
        }
    }
    placeNewSegmentAndCleanup(loop);
    // Remove any safepoints from the original copy leaving only the duplicated one
    assert loop.whole().nodes().filter(SafepointNode.class).count() == nodes().filter(SafepointNode.class).count();
    for (SafepointNode safepoint : loop.whole().nodes().filter(SafepointNode.class)) {
        graph().removeFixed(safepoint);
    }
    int unrollFactor = mainLoopBegin.getUnrollFactor();
    StructuredGraph graph = mainLoopBegin.graph();
    if (updateLimit) {
        // Now use the previous unrollFactor to update the exit condition to power of two
        InductionVariable iv = loop.counted().getCounter();
        CompareNode compareNode = (CompareNode) loop.counted().getLimitTest().condition();
        ValueNode compareBound;
        if (compareNode.getX() == iv.valueNode()) {
            compareBound = compareNode.getY();
        } else if (compareNode.getY() == iv.valueNode()) {
            compareBound = compareNode.getX();
        } else {
            throw GraalError.shouldNotReachHere();
        }
        long originalStride = unrollFactor == 1 ? iv.constantStride() : iv.constantStride() / unrollFactor;
        if (iv.direction() == InductionVariable.Direction.Up) {
            ConstantNode aboveVal = graph.unique(ConstantNode.forIntegerStamp(iv.initNode().stamp(NodeView.DEFAULT), unrollFactor * originalStride));
            ValueNode newLimit = graph.addWithoutUnique(new SubNode(compareBound, aboveVal));
            compareNode.replaceFirstInput(compareBound, newLimit);
        } else if (iv.direction() == InductionVariable.Direction.Down) {
            ConstantNode aboveVal = graph.unique(ConstantNode.forIntegerStamp(iv.initNode().stamp(NodeView.DEFAULT), unrollFactor * -originalStride));
            ValueNode newLimit = graph.addWithoutUnique(new AddNode(compareBound, aboveVal));
            compareNode.replaceFirstInput(compareBound, newLimit);
        }
    }
    mainLoopBegin.setUnrollFactor(unrollFactor * 2);
    mainLoopBegin.setLoopFrequency(mainLoopBegin.loopFrequency() / 2);
    graph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph, "LoopPartialUnroll %s", loop);
    mainLoopBegin.getDebug().dump(DebugContext.VERBOSE_LEVEL, mainLoopBegin.graph(), "After insertWithinAfter %s", mainLoopBegin);
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) ArrayList(java.util.ArrayList) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) SubNode(org.graalvm.compiler.nodes.calc.SubNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 59 with ConstantNode

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

the class NodeBenchmark method createAndDeleteConstant.

@Benchmark
public void createAndDeleteConstant(StringEquals s, Blackhole bh) {
    ConstantNode constantNode = ConstantNode.forInt(42);
    s.graph.addOrUnique(constantNode);
    GraphUtil.killWithUnusedFloatingInputs(constantNode);
    bh.consume(constantNode);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 60 with ConstantNode

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

the class ArrayEqualsNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode alias1 = tool.getAlias(array1);
    ValueNode alias2 = tool.getAlias(array2);
    if (alias1 == alias2) {
        // the same virtual objects will always have the same contents
        tool.replaceWithValue(ConstantNode.forBoolean(true, graph()));
    } else if (alias1 instanceof VirtualObjectNode && alias2 instanceof VirtualObjectNode) {
        VirtualObjectNode virtual1 = (VirtualObjectNode) alias1;
        VirtualObjectNode virtual2 = (VirtualObjectNode) alias2;
        if (virtual1.entryCount() == virtual2.entryCount()) {
            int entryCount = virtual1.entryCount();
            boolean allEqual = true;
            for (int i = 0; i < entryCount; i++) {
                ValueNode entry1 = tool.getEntry(virtual1, i);
                ValueNode entry2 = tool.getEntry(virtual2, i);
                if (entry1 != entry2) {
                    if (entry1 instanceof ConstantNode && entry2 instanceof ConstantNode) {
                        // equal in Arrays.equals([F[F) or Arrays.equals([D[D).
                        if (entry1.getStackKind() == JavaKind.Float && entry2.getStackKind() == JavaKind.Float) {
                            float value1 = ((JavaConstant) ((ConstantNode) entry1).asConstant()).asFloat();
                            float value2 = ((JavaConstant) ((ConstantNode) entry2).asConstant()).asFloat();
                            if (Float.floatToIntBits(value1) != Float.floatToIntBits(value2)) {
                                allEqual = false;
                            }
                        } else if (entry1.getStackKind() == JavaKind.Double && entry2.getStackKind() == JavaKind.Double) {
                            double value1 = ((JavaConstant) ((ConstantNode) entry1).asConstant()).asDouble();
                            double value2 = ((JavaConstant) ((ConstantNode) entry2).asConstant()).asDouble();
                            if (Double.doubleToLongBits(value1) != Double.doubleToLongBits(value2)) {
                                allEqual = false;
                            }
                        } else {
                            allEqual = false;
                        }
                    } else {
                        // the contents might be different
                        allEqual = false;
                    }
                }
                if (entry1.stamp(NodeView.DEFAULT).alwaysDistinct(entry2.stamp(NodeView.DEFAULT))) {
                    // the contents are different
                    tool.replaceWithValue(ConstantNode.forBoolean(false, graph()));
                    return;
                }
            }
            if (allEqual) {
                tool.replaceWithValue(ConstantNode.forBoolean(true, graph()));
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

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