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