Search in sources :

Example 6 with AddNode

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

the class LoopBeginNode method getSelfIncrements.

/**
 * Returns an array with one entry for each input of the phi, which is either
 * {@link #NO_INCREMENT} or the increment, i.e., the value by which the phi is incremented in
 * the corresponding branch.
 */
private static int[] getSelfIncrements(PhiNode phi) {
    int[] selfIncrement = new int[phi.valueCount()];
    for (int i = 0; i < phi.valueCount(); i++) {
        ValueNode input = phi.valueAt(i);
        long increment = NO_INCREMENT;
        if (input != null && input instanceof AddNode && input.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
            AddNode add = (AddNode) input;
            if (add.getX() == phi && add.getY().isConstant()) {
                increment = add.getY().asJavaConstant().asLong();
            } else if (add.getY() == phi && add.getX().isConstant()) {
                increment = add.getX().asJavaConstant().asLong();
            }
        } else if (input == phi) {
            increment = 0;
        }
        if (increment < Integer.MIN_VALUE || increment > Integer.MAX_VALUE || increment == NO_INCREMENT) {
            increment = NO_INCREMENT;
        }
        selfIncrement[i] = (int) increment;
    }
    return selfIncrement;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 7 with AddNode

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

the class LongNodeChainTest method longAddChain.

private void longAddChain(boolean reverse) {
    HighTierContext context = getDefaultHighTierContext();
    OptionValues options = getInitialOptions();
    StructuredGraph graph = new StructuredGraph.Builder(options, DebugContext.create(options, DebugHandlersFactory.LOADER)).build();
    ValueNode constant = graph.unique(ConstantNode.forPrimitive(JavaConstant.INT_1));
    ValueNode value = null;
    if (reverse) {
        // Make sure the constant's stamp is not used to infer the add node's stamp.
        OpaqueNode opaque = graph.unique(new OpaqueNode(constant));
        constant = opaque;
        AddNode addNode = graph.unique(new AddNode(constant, constant));
        value = addNode;
        for (int i = 1; i < N; ++i) {
            AddNode newAddNode = graph.addWithoutUnique(new AddNode(constant, constant));
            addNode.setY(newAddNode);
            addNode = newAddNode;
        }
        opaque.replaceAndDelete(opaque.getValue());
    } else {
        value = constant;
        for (int i = 0; i < N; ++i) {
            value = graph.unique(new AddNode(constant, value));
        }
    }
    ReturnNode returnNode = graph.add(new ReturnNode(value));
    graph.start().setNext(returnNode);
    for (SchedulingStrategy s : Strategies) {
        new SchedulePhase(s).apply(graph);
    }
    new CanonicalizerPhase().apply(graph, context);
    JavaConstant asConstant = (JavaConstant) returnNode.result().asConstant();
    Assert.assertEquals(N + 1, asConstant.asInt());
}
Also used : SchedulePhase(org.graalvm.compiler.phases.schedule.SchedulePhase) OptionValues(org.graalvm.compiler.options.OptionValues) JavaConstant(jdk.vm.ci.meta.JavaConstant) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) SchedulingStrategy(org.graalvm.compiler.phases.schedule.SchedulePhase.SchedulingStrategy) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 8 with AddNode

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

the class CInterfaceInvocationPlugin method makeAddress.

private static ValueNode makeAddress(StructuredGraph graph, ValueNode[] args, AccessorInfo accessorInfo, ValueNode base, int displacement, int indexScaling) {
    ValueNode offset = ConstantNode.forIntegerKind(FrameAccess.getWordKind(), displacement, graph);
    if (accessorInfo.isIndexed()) {
        ValueNode index = args[accessorInfo.indexParameterNumber(true)];
        assert index.getStackKind().isPrimitive();
        ValueNode wordIndex = adaptPrimitiveType(graph, index, index.getStackKind(), FrameAccess.getWordKind(), false);
        ValueNode scaledIndex = graph.unique(new MulNode(wordIndex, ConstantNode.forIntegerKind(FrameAccess.getWordKind(), indexScaling, graph)));
        offset = graph.unique(new AddNode(scaledIndex, offset));
    }
    assert base.getStackKind() == FrameAccess.getWordKind();
    return graph.unique(new AddNode(base, offset));
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 9 with AddNode

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

the class AMD64HotSpotAddressLowering method optimizeAdd.

/**
 * Given that Add(a, cst) is always positive, performs the following: ZeroExtend(Add(a, cst)) ->
 * Add(SignExtend(a), SignExtend(cst)).
 */
private static void optimizeAdd(ZeroExtendNode zeroExtendNode, ConstantNode constant, ValueNode other, LoopEx loop) {
    StructuredGraph graph = zeroExtendNode.graph();
    AddNode addNode = graph.unique(new AddNode(signExtend(other, loop), ConstantNode.forLong(constant.asJavaConstant().asInt(), graph)));
    zeroExtendNode.replaceAtUsages(addNode);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 10 with AddNode

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

the class AMD64HotSpotAddressLowering method tryOptimize.

private static void tryOptimize(OffsetAddressNode offsetAddress, LoopEx loop) {
    EconomicMap<Node, InductionVariable> ivs = loop.getInductionVariables();
    InductionVariable currentIV = ivs.get(offsetAddress.getOffset());
    while (currentIV != null) {
        if (!(currentIV instanceof DerivedInductionVariable)) {
            break;
        }
        ValueNode currentValue = currentIV.valueNode();
        if (currentValue.isDeleted()) {
            break;
        }
        if (currentValue instanceof ZeroExtendNode) {
            ZeroExtendNode zeroExtendNode = (ZeroExtendNode) currentValue;
            if (applicableToImplicitZeroExtend(zeroExtendNode)) {
                ValueNode input = zeroExtendNode.getValue();
                if (input instanceof AddNode) {
                    AddNode add = (AddNode) input;
                    if (add.getX().isConstant()) {
                        optimizeAdd(zeroExtendNode, (ConstantNode) add.getX(), add.getY(), loop);
                    } else if (add.getY().isConstant()) {
                        optimizeAdd(zeroExtendNode, (ConstantNode) add.getY(), add.getX(), loop);
                    }
                }
            }
        }
        currentIV = ((DerivedInductionVariable) currentIV).getBase();
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) 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) ValueNode(org.graalvm.compiler.nodes.ValueNode) DerivedInductionVariable(org.graalvm.compiler.loop.DerivedInductionVariable) BasicInductionVariable(org.graalvm.compiler.loop.BasicInductionVariable) InductionVariable(org.graalvm.compiler.loop.InductionVariable) DerivedInductionVariable(org.graalvm.compiler.loop.DerivedInductionVariable) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) 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