use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class NegateNodeCanonicalizationTest method testByte.
@Test
public void testByte() {
byte[] a = new byte[] { Byte.MIN_VALUE, Byte.MIN_VALUE + 1, -1, 0, 1, Byte.MAX_VALUE - 1, Byte.MAX_VALUE };
for (byte i : a) {
ConstantNode node = ConstantNode.forByte(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 WordOperationPlugin method comparisonOp.
private ValueNode comparisonOp(GraphBuilderContext graph, Condition condition, ValueNode left, ValueNode right) {
assert left.getStackKind() == wordKind && right.getStackKind() == wordKind;
CanonicalizedCondition canonical = condition.canonicalize();
ValueNode a = canonical.mustMirror() ? right : left;
ValueNode b = canonical.mustMirror() ? left : right;
CompareNode comparison;
if (canonical.getCanonicalCondition() == CanonicalCondition.EQ) {
comparison = new IntegerEqualsNode(a, b);
} else if (canonical.getCanonicalCondition() == CanonicalCondition.BT) {
comparison = new IntegerBelowNode(a, b);
} else {
assert canonical.getCanonicalCondition() == CanonicalCondition.LT;
comparison = new IntegerLessThanNode(a, b);
}
ConstantNode trueValue = graph.add(forInt(1));
ConstantNode falseValue = graph.add(forInt(0));
if (canonical.mustNegate()) {
ConstantNode temp = trueValue;
trueValue = falseValue;
falseValue = temp;
}
return graph.add(new ConditionalNode(graph.add(comparison), trueValue, falseValue));
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class CInterfaceInvocationPlugin method replaceConstant.
private boolean replaceConstant(GraphBuilderContext b, ResolvedJavaMethod method, ConstantInfo constantInfo) {
Object value = constantInfo.getValueInfo().getProperty();
JavaKind kind = wordTypes.asKind(b.getInvokeReturnType());
ConstantNode valueNode;
switch(constantInfo.getKind()) {
case INTEGER:
case POINTER:
if (method.getSignature().getReturnKind() == JavaKind.Boolean) {
valueNode = ConstantNode.forBoolean((long) value != 0, b.getGraph());
} else {
valueNode = ConstantNode.forIntegerKind(kind, (long) value, b.getGraph());
}
break;
case FLOAT:
valueNode = ConstantNode.forFloatingKind(kind, (double) value, b.getGraph());
break;
case STRING:
case BYTEARRAY:
valueNode = ConstantNode.forConstant(SubstrateObjectConstant.forObject(value), b.getMetaAccess(), b.getGraph());
break;
default:
throw shouldNotReachHere("Unexpected constant kind " + constantInfo);
}
b.push(pushKind(method), valueNode);
return true;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class ConstantFoldLoadFieldPlugin method tryConstantFold.
private static boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, JavaConstant receiver) {
ConstantNode result = ConstantFoldUtil.tryConstantFold(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), field, receiver, b.getOptions());
if (result != null) {
JavaConstant value = result.asJavaConstant();
if (b.getMetaAccess() instanceof AnalysisMetaAccess && value.getJavaKind() == JavaKind.Object && value.isNonNull()) {
SubstrateObjectConstant sValue = (SubstrateObjectConstant) value;
SubstrateObjectConstant sReceiver = (SubstrateObjectConstant) receiver;
Object root;
if (receiver == null) {
/* Found a root, map the constant value to the root field. */
root = field;
} else {
/* Map the constant value to the root field of it's receiver. */
root = sReceiver.getRoot();
assert root != null : receiver.toValueString() + " : " + field + " : " + b.getGraph();
}
sValue.setRoot(root);
}
result = b.getGraph().unique(result);
b.push(field.getJavaKind(), result);
return true;
}
return false;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class AheadOfTimeCompilationTest method testStringObjectCommon.
private void testStringObjectCommon(boolean compileAOT) {
StructuredGraph result = compile("getStringObject", compileAOT);
NodeIterable<ConstantNode> filter = getConstantNodes(result);
assertDeepEquals(1, filter.count());
JavaConstant c = filter.first().asJavaConstant();
Assert.assertEquals(getSnippetReflection().asObject(String.class, c), "test string");
assertDeepEquals(0, result.getNodes().filter(FloatingReadNode.class).count());
assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count());
}
Aggregations