use of org.graalvm.compiler.nodes.calc.SignExtendNode in project graal by oracle.
the class ObjectAccessTest method assertRead.
private static void assertRead(StructuredGraph graph, JavaKind kind, boolean indexConvert, LocationIdentity locationIdentity) {
JavaReadNode read = (JavaReadNode) graph.start().next();
Assert.assertEquals(kind.getStackKind(), read.stamp(NodeView.DEFAULT).getStackKind());
OffsetAddressNode address = (OffsetAddressNode) read.getAddress();
Assert.assertEquals(graph.getParameter(0), address.getBase());
Assert.assertEquals(locationIdentity, read.getLocationIdentity());
if (indexConvert) {
SignExtendNode convert = (SignExtendNode) address.getOffset();
Assert.assertEquals(convert.getInputBits(), 32);
Assert.assertEquals(convert.getResultBits(), 64);
Assert.assertEquals(graph.getParameter(1), convert.getValue());
} else {
Assert.assertEquals(graph.getParameter(1), address.getOffset());
}
ReturnNode ret = (ReturnNode) read.next();
Assert.assertEquals(read, ret.result());
}
use of org.graalvm.compiler.nodes.calc.SignExtendNode in project graal by oracle.
the class ObjectAccessTest method assertWrite.
private static void assertWrite(StructuredGraph graph, boolean indexConvert, LocationIdentity locationIdentity) {
JavaWriteNode write = (JavaWriteNode) graph.start().next();
Assert.assertEquals(graph.getParameter(2), write.value());
OffsetAddressNode address = (OffsetAddressNode) write.getAddress();
Assert.assertEquals(graph.getParameter(0), address.getBase());
Assert.assertEquals(BytecodeFrame.AFTER_BCI, write.stateAfter().bci);
Assert.assertEquals(locationIdentity, write.getLocationIdentity());
if (indexConvert) {
SignExtendNode convert = (SignExtendNode) address.getOffset();
Assert.assertEquals(convert.getInputBits(), 32);
Assert.assertEquals(convert.getResultBits(), 64);
Assert.assertEquals(graph.getParameter(1), convert.getValue());
} else {
Assert.assertEquals(graph.getParameter(1), address.getOffset());
}
ReturnNode ret = (ReturnNode) write.next();
Assert.assertEquals(null, ret.result());
}
use of org.graalvm.compiler.nodes.calc.SignExtendNode in project graal by oracle.
the class PointerTest method assertRead.
private void assertRead(StructuredGraph graph, JavaKind kind, boolean indexConvert, LocationIdentity locationIdentity) {
WordCastNode cast = (WordCastNode) graph.start().next();
JavaReadNode read = (JavaReadNode) cast.next();
Assert.assertEquals(kind.getStackKind(), read.stamp(NodeView.DEFAULT).getStackKind());
OffsetAddressNode address = (OffsetAddressNode) read.getAddress();
Assert.assertEquals(cast, address.getBase());
Assert.assertEquals(graph.getParameter(0), cast.getInput());
Assert.assertEquals(target.wordJavaKind, cast.stamp(NodeView.DEFAULT).getStackKind());
Assert.assertEquals(locationIdentity, read.getLocationIdentity());
if (indexConvert) {
SignExtendNode convert = (SignExtendNode) address.getOffset();
Assert.assertEquals(convert.getInputBits(), 32);
Assert.assertEquals(convert.getResultBits(), 64);
Assert.assertEquals(graph.getParameter(1), convert.getValue());
} else {
Assert.assertEquals(graph.getParameter(1), address.getOffset());
}
ReturnNode ret = (ReturnNode) read.next();
Assert.assertEquals(read, ret.result());
}
use of org.graalvm.compiler.nodes.calc.SignExtendNode in project graal by oracle.
the class AArch64ReadNode method replace.
/**
* replace a ReadNode with an AArch64-specific variant which knows how to merge a downstream
* zero or sign extend into the read operation.
*
* @param readNode
*/
public static void replace(ReadNode readNode) {
assert readNode.getUsageCount() == 1;
assert readNode.getUsageAt(0) instanceof ZeroExtendNode || readNode.getUsageAt(0) instanceof SignExtendNode;
ValueNode usage = (ValueNode) readNode.getUsageAt(0);
boolean isSigned = usage instanceof SignExtendNode;
IntegerStamp accessStamp = ((IntegerStamp) readNode.getAccessStamp());
AddressNode address = readNode.getAddress();
LocationIdentity location = readNode.getLocationIdentity();
Stamp stamp = usage.stamp(NodeView.DEFAULT);
GuardingNode guard = readNode.getGuard();
BarrierType barrierType = readNode.getBarrierType();
boolean nullCheck = readNode.getNullCheck();
FrameState stateBefore = readNode.stateBefore();
AArch64ReadNode clone = new AArch64ReadNode(address, location, stamp, guard, barrierType, nullCheck, stateBefore, accessStamp, isSigned);
StructuredGraph graph = readNode.graph();
graph.add(clone);
// splice out the extend node
usage.replaceAtUsagesAndDelete(readNode);
// swap the clone for the read
graph.replaceFixedWithFixed(readNode, clone);
}
use of org.graalvm.compiler.nodes.calc.SignExtendNode in project graal by oracle.
the class JNIJavaCallWrapperMethod method loadAndUnboxArguments.
private List<Pair<ValueNode, ResolvedJavaType>> loadAndUnboxArguments(JNIGraphKit kit, HostedProviders providers, ResolvedJavaMethod invokeMethod, Signature invokeSignature) {
MetaAccessProvider metaAccess = providers.getMetaAccess();
List<Pair<ValueNode, ResolvedJavaType>> args = new ArrayList<>();
int javaIndex = 0;
javaIndex += metaAccess.lookupJavaType(JNIEnvironment.class).getJavaKind().getSlotCount();
if (!invokeMethod.isStatic()) {
JavaKind kind = metaAccess.lookupJavaType(JNIObjectHandle.class).getJavaKind();
ValueNode handle = kit.loadLocal(javaIndex, kind);
ValueNode unboxed = kit.unboxHandle(handle);
ValueNode receiver;
ResolvedJavaType receiverClass = invokeMethod.getDeclaringClass();
if (invokeMethod.isConstructor()) {
/*
* Our target method is a constructor and we might be called via `NewObject`, in
* which case we need to allocate the object before calling the constructor. We can
* detect when this is the case because unlike with `Call<Type>Method`, we are
* passed the object hub of our target class in place of the receiver object.
*/
Constant hub = providers.getConstantReflection().asObjectHub(receiverClass);
ConstantNode hubNode = kit.createConstant(hub, JavaKind.Object);
kit.startIf(kit.unique(new ObjectEqualsNode(unboxed, hubNode)), BranchProbabilityNode.FAST_PATH_PROBABILITY);
kit.thenPart();
ValueNode created = kit.append(new NewInstanceNode(receiverClass, true));
AbstractMergeNode merge = kit.endIf();
receiver = kit.unique(new ValuePhiNode(StampFactory.object(), merge, new ValueNode[] { created, unboxed }));
} else {
receiver = unboxed;
}
args.add(Pair.create(receiver, receiverClass));
}
javaIndex += metaAccess.lookupJavaType(JNIObjectHandle.class).getJavaKind().getSlotCount();
if (nonVirtual) {
javaIndex += metaAccess.lookupJavaType(JNIObjectHandle.class).getJavaKind().getSlotCount();
}
javaIndex += metaAccess.lookupJavaType(JNIMethodId.class).getJavaKind().getSlotCount();
int count = invokeSignature.getParameterCount(false);
if (callVariant == CallVariant.VARARGS) {
for (int i = 0; i < count; i++) {
ResolvedJavaType type = (ResolvedJavaType) invokeSignature.getParameterType(i, null);
JavaKind kind = type.getJavaKind();
JavaKind loadKind = kind;
if (loadKind == JavaKind.Float) {
// C varargs promote float to double
loadKind = JavaKind.Double;
}
ValueNode value = kit.loadLocal(javaIndex, loadKind);
if (kind == JavaKind.Float) {
value = kit.unique(new FloatConvertNode(FloatConvert.D2F, value));
} else if (kind.isObject()) {
value = kit.unboxHandle(value);
}
args.add(Pair.create(value, type));
javaIndex += loadKind.getSlotCount();
}
} else if (callVariant == CallVariant.ARRAY) {
ResolvedJavaType elementType = metaAccess.lookupJavaType(JNIValue.class);
int elementSize = SizeOf.get(JNIValue.class);
ValueNode array = kit.loadLocal(javaIndex, elementType.getJavaKind());
for (int i = 0; i < count; i++) {
ResolvedJavaType type = (ResolvedJavaType) invokeSignature.getParameterType(i, null);
JavaKind readKind = type.getJavaKind();
StructFieldInfo fieldInfo = getJNIValueOffsetOf(elementType, readKind);
int offset = i * elementSize + fieldInfo.getOffsetInfo().getProperty();
ConstantNode offsetConstant = kit.createConstant(JavaConstant.forInt(offset), providers.getWordTypes().getWordKind());
OffsetAddressNode address = kit.unique(new OffsetAddressNode(array, offsetConstant));
LocationIdentity locationIdentity = fieldInfo.getLocationIdentity();
if (locationIdentity == null) {
locationIdentity = LocationIdentity.any();
}
Stamp readStamp = getNarrowStamp(providers, readKind);
ValueNode value = kit.append(new CInterfaceReadNode(address, locationIdentity, readStamp, BarrierType.NONE, "args[" + i + "]"));
JavaKind stackKind = readKind.getStackKind();
if (readKind != stackKind) {
assert stackKind.getBitCount() > readKind.getBitCount() : "read kind must be narrower than stack kind";
if (readKind.isUnsigned()) {
// needed or another op may illegally sign-extend
value = kit.unique(new ZeroExtendNode(value, stackKind.getBitCount()));
} else {
value = kit.unique(new SignExtendNode(value, stackKind.getBitCount()));
}
} else if (readKind.isObject()) {
value = kit.unboxHandle(value);
}
args.add(Pair.create(value, type));
}
} else if (callVariant == CallVariant.VA_LIST) {
ValueNode valist = kit.loadLocal(javaIndex, metaAccess.lookupJavaType(WordBase.class).getJavaKind());
for (int i = 0; i < count; i++) {
ResolvedJavaType type = (ResolvedJavaType) invokeSignature.getParameterType(i, null);
JavaKind loadKind = type.getJavaKind();
if (loadKind.isObject()) {
loadKind = providers.getWordTypes().getWordKind();
}
ValueNode value = kit.append(new VaListNextArgNode(loadKind, valist));
if (type.getJavaKind().isObject()) {
value = kit.unboxHandle(value);
}
args.add(Pair.create(value, type));
}
} else {
throw VMError.unsupportedFeature("Call variant: " + callVariant);
}
return args;
}
Aggregations