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);
}
}
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;
}
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);
}
}
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));
}
Aggregations