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