Search in sources :

Example 11 with AddNode

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

the class AddNodeTest method checkTemplateAndName.

@Test
public void checkTemplateAndName() {
    AddNode add = new AddNode(ConstantNode.forInt(30), ConstantNode.forInt(12));
    NodeClass<? extends Node> addClass = add.getNodeClass();
    assertEquals("+", addClass.shortName());
    assertEquals("Using short name as template", "+", addClass.getNameTemplate());
}
Also used : AddNode(org.graalvm.compiler.nodes.calc.AddNode) Test(org.junit.Test)

Example 12 with AddNode

use of org.graalvm.compiler.nodes.calc.AddNode 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 13 with AddNode

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

the class NodeBenchmark method createAndDeleteAdd.

@Benchmark
public void createAndDeleteAdd(StringEquals s, Blackhole bh) {
    AddNode addNode = new AddNode(ConstantNode.forInt(40), ConstantNode.forInt(2));
    s.graph.addOrUniqueWithInputs(addNode);
    GraphUtil.killWithUnusedFloatingInputs(addNode);
    bh.consume(addNode);
}
Also used : AddNode(org.graalvm.compiler.nodes.calc.AddNode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 14 with AddNode

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

the class AMD64AddressLoweringTest method convertTwoLevelsOfNegatedShiftedBaseAndNegatedIndexToDisplacement.

@Test
public void convertTwoLevelsOfNegatedShiftedBaseAndNegatedIndexToDisplacement() {
    ValueNode base = graph.addOrUniqueWithInputs(new NegateNode(new LeftShiftNode(new NegateNode(new LeftShiftNode(const64(500), const32(1))), const32(1))));
    ValueNode index = graph.addOrUniqueWithInputs(new NegateNode(new AddNode(new NegateNode(const64(13)), const64(3))));
    AddressNode result = lowering.lower(base, index);
    assertAddress(result, null, null, Scale.Times4, 2010);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 15 with AddNode

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

the class AMD64AddressNode method canonicalizeIndex.

public void canonicalizeIndex(SimplifierTool tool) {
    if (index instanceof AddNode && ((IntegerStamp) index.stamp(NodeView.DEFAULT)).getBits() == 64) {
        AddNode add = (AddNode) index;
        ValueNode valX = add.getX();
        if (valX instanceof PhiNode) {
            PhiNode phi = (PhiNode) valX;
            if (phi.merge() instanceof LoopBeginNode) {
                LoopBeginNode loopNode = (LoopBeginNode) phi.merge();
                if (!loopNode.isSimpleLoop()) {
                    ValueNode valY = add.getY();
                    if (valY instanceof ConstantNode) {
                        int addBy = valY.asJavaConstant().asInt();
                        displacement = displacement + scale.value * addBy;
                        replaceFirstInput(index, phi);
                        tool.addToWorkList(index);
                    }
                }
            }
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Aggregations

AddNode (org.graalvm.compiler.nodes.calc.AddNode)27 ValueNode (org.graalvm.compiler.nodes.ValueNode)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)6 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)5 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)4 Node (org.graalvm.compiler.graph.Node)4 PhiNode (org.graalvm.compiler.nodes.PhiNode)4 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)4 Test (org.junit.Test)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)3 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 Block (org.graalvm.compiler.nodes.cfg.Block)3 SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)3 AMD64AddressNode (org.graalvm.compiler.core.amd64.AMD64AddressNode)2 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 FrameState (org.graalvm.compiler.nodes.FrameState)2 NodeView (org.graalvm.compiler.nodes.NodeView)2