Search in sources :

Example 1 with MulNode

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

the class FinalizeProfileNodesPhase method assignRandomSources.

private static void assignRandomSources(StructuredGraph graph) {
    ValueNode seed = graph.unique(new RandomSeedNode());
    ControlFlowGraph cfg = ControlFlowGraph.compute(graph, false, true, false, false);
    Map<LoopBeginNode, ValueNode> loopRandomValueCache = new HashMap<>();
    for (ProfileNode node : getProfileNodes(graph)) {
        ValueNode random;
        Block block = cfg.blockFor(node);
        Loop<Block> loop = block.getLoop();
        // pseudo-random number generator into the loop
        if (loop != null) {
            LoopBeginNode loopBegin = (LoopBeginNode) loop.getHeader().getBeginNode();
            random = loopRandomValueCache.get(loopBegin);
            if (random == null) {
                PhiNode phi = graph.addWithoutUnique(new ValuePhiNode(seed.stamp(NodeView.DEFAULT), loopBegin));
                phi.addInput(seed);
                // X_{n+1} = a*X_n + c, using glibc-like constants
                ValueNode a = ConstantNode.forInt(1103515245, graph);
                ValueNode c = ConstantNode.forInt(12345, graph);
                ValueNode next = graph.addOrUniqueWithInputs(new AddNode(c, new MulNode(phi, a)));
                for (int i = 0; i < loopBegin.getLoopEndCount(); i++) {
                    phi.addInput(next);
                }
                random = phi;
                loopRandomValueCache.put(loopBegin, random);
            }
        } else {
            // Graal doesn't compile methods with irreducible loops. So all profile nodes that
            // are not in a loop are guaranteed to be executed at most once. We feed the seed
            // value to such nodes directly.
            random = seed;
        }
        node.setRandom(random);
    }
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) HashMap(java.util.HashMap) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ProfileNode(org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) Block(org.graalvm.compiler.nodes.cfg.Block) RandomSeedNode(org.graalvm.compiler.hotspot.nodes.profiling.RandomSeedNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 2 with MulNode

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

the class BinaryMathIntrinsicNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    ValueNode c = tryConstantFold(forX, forY, getOperation());
    if (c != null) {
        return c;
    }
    if (forY.isConstant()) {
        double yValue = forY.asJavaConstant().asDouble();
        // If the second argument is positive or negative zero, then the result is 1.0.
        if (yValue == 0.0D) {
            return ConstantNode.forDouble(1);
        }
        // If the second argument is 1.0, then the result is the same as the first argument.
        if (yValue == 1.0D) {
            return x;
        }
        // If the second argument is NaN, then the result is NaN.
        if (Double.isNaN(yValue)) {
            return ConstantNode.forDouble(Double.NaN);
        }
        // x**-1 = 1/x
        if (yValue == -1.0D) {
            return new FloatDivNode(ConstantNode.forDouble(1), x);
        }
        // x**2 = x*x
        if (yValue == 2.0D) {
            return new MulNode(x, x);
        }
        // x**0.5 = sqrt(x)
        if (yValue == 0.5D && x.stamp(view) instanceof FloatStamp && ((FloatStamp) x.stamp(view)).lowerBound() >= 0.0D) {
            return SqrtNode.create(x, view);
        }
    }
    return this;
}
Also used : FloatDivNode(org.graalvm.compiler.nodes.calc.FloatDivNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 3 with MulNode

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

the class IntegerMulExactSplitNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    NodeView view = NodeView.from(tool);
    if (!IntegerStamp.multiplicationCanOverflow((IntegerStamp) x.stamp(view), (IntegerStamp) y.stamp(view))) {
        tool.deleteBranch(overflowSuccessor);
        tool.addToWorkList(next);
        MulNode replacement = graph().unique(new MulNode(x, y));
        graph().replaceSplitWithFloating(this, replacement, next);
        tool.addToWorkList(replacement);
    }
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) MulNode(org.graalvm.compiler.nodes.calc.MulNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 4 with MulNode

use of org.graalvm.compiler.nodes.calc.MulNode 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)

Aggregations

MulNode (org.graalvm.compiler.nodes.calc.MulNode)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)3 NodeView (org.graalvm.compiler.nodes.NodeView)2 AddNode (org.graalvm.compiler.nodes.calc.AddNode)2 HashMap (java.util.HashMap)1 FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 ProfileNode (org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode)1 RandomSeedNode (org.graalvm.compiler.hotspot.nodes.profiling.RandomSeedNode)1 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)1 FloatDivNode (org.graalvm.compiler.nodes.calc.FloatDivNode)1 Block (org.graalvm.compiler.nodes.cfg.Block)1 ControlFlowGraph (org.graalvm.compiler.nodes.cfg.ControlFlowGraph)1