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