use of org.graalvm.compiler.nodes.InvokeNode in project graal by oracle.
the class MacroNode method createInvoke.
protected InvokeNode createInvoke() {
MethodCallTargetNode callTarget = graph().add(new MethodCallTargetNode(invokeKind, targetMethod, arguments.toArray(new ValueNode[arguments.size()]), returnStamp, null));
InvokeNode invoke = graph().add(new InvokeNode(callTarget, bci));
if (stateAfter() != null) {
invoke.setStateAfter(stateAfter().duplicate());
if (getStackKind() != JavaKind.Void) {
invoke.stateAfter().replaceFirstInput(this, invoke);
}
}
return invoke;
}
use of org.graalvm.compiler.nodes.InvokeNode in project graal by oracle.
the class MacroNode method replaceWithInvoke.
@SuppressWarnings("try")
public InvokeNode replaceWithInvoke() {
try (DebugCloseable context = withNodeSourcePosition()) {
InvokeNode invoke = createInvoke();
graph().replaceFixedWithFixed(this, invoke);
return invoke;
}
}
use of org.graalvm.compiler.nodes.InvokeNode in project graal by oracle.
the class MethodHandleNode method getTargetInvokeNode.
/**
* Helper function to get the {@link InvokeNode} for the targetMethod of a
* java.lang.invoke.MemberName.
*
* @param adder
* @param target the target, already loaded from the member name node
*
* @return invoke node for the member name target
*/
private static InvokeNode getTargetInvokeNode(GraphAdder adder, IntrinsicMethod intrinsicMethod, int bci, StampPair returnStamp, ValueNode[] originalArguments, ResolvedJavaMethod target, ResolvedJavaMethod original) {
if (target == null) {
return null;
}
// In lambda forms we erase signature types to avoid resolving issues
// involving class loaders. When we optimize a method handle invoke
// to a direct call we must cast the receiver and arguments to its
// actual types.
Signature signature = target.getSignature();
final boolean isStatic = target.isStatic();
final int receiverSkip = isStatic ? 0 : 1;
Assumptions assumptions = adder.getAssumptions();
ResolvedJavaMethod realTarget = null;
if (target.canBeStaticallyBound()) {
realTarget = target;
} else {
ResolvedJavaType targetType = target.getDeclaringClass();
// Try to bind based on the declaredType
AssumptionResult<ResolvedJavaMethod> concreteMethod = targetType.findUniqueConcreteMethod(target);
if (concreteMethod == null) {
// Try to get the most accurate receiver type
if (intrinsicMethod == IntrinsicMethod.LINK_TO_VIRTUAL || intrinsicMethod == IntrinsicMethod.LINK_TO_INTERFACE) {
ValueNode receiver = getReceiver(originalArguments);
TypeReference receiverType = StampTool.typeReferenceOrNull(receiver.stamp(NodeView.DEFAULT));
if (receiverType != null) {
concreteMethod = receiverType.getType().findUniqueConcreteMethod(target);
}
}
}
if (concreteMethod != null && concreteMethod.canRecordTo(assumptions)) {
concreteMethod.recordTo(assumptions);
realTarget = concreteMethod.getResult();
}
}
if (realTarget != null) {
// Don't mutate the passed in arguments
ValueNode[] arguments = originalArguments.clone();
// Cast receiver to its type.
if (!isStatic) {
JavaType receiverType = target.getDeclaringClass();
maybeCastArgument(adder, arguments, 0, receiverType);
}
// Cast reference arguments to its type.
for (int index = 0; index < signature.getParameterCount(false); index++) {
JavaType parameterType = signature.getParameterType(index, target.getDeclaringClass());
maybeCastArgument(adder, arguments, receiverSkip + index, parameterType);
}
InvokeNode invoke = createTargetInvokeNode(assumptions, intrinsicMethod, realTarget, original, bci, returnStamp, arguments);
assert invoke != null : "graph has been modified so this must result an invoke";
return invoke;
}
return null;
}
use of org.graalvm.compiler.nodes.InvokeNode in project graal by oracle.
the class MethodHandleNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
MethodHandleAccessProvider methodHandleAccess = tool.getConstantReflection().getMethodHandleAccess();
ValueNode[] argumentsArray = arguments.toArray(new ValueNode[arguments.size()]);
final FixedNode before = this;
GraphAdder adder = new GraphAdder(graph()) {
@Override
public <T extends ValueNode> T add(T node) {
T added = graph().addOrUnique(node);
if (added instanceof FixedWithNextNode) {
graph().addBeforeFixed(before, (FixedWithNextNode) added);
}
return added;
}
};
InvokeNode invoke = tryResolveTargetInvoke(adder, methodHandleAccess, intrinsicMethod, targetMethod, bci, returnStamp, argumentsArray);
if (invoke != null) {
assert invoke.graph() == null;
invoke = graph().addOrUniqueWithInputs(invoke);
invoke.setStateAfter(stateAfter());
FixedNode currentNext = next();
replaceAtUsages(invoke);
GraphUtil.removeFixedWithUnusedInputs(this);
graph().addBeforeFixed(currentNext, invoke);
}
}
use of org.graalvm.compiler.nodes.InvokeNode in project graal by oracle.
the class BytecodeParser method createInvoke.
protected InvokeNode createInvoke(int invokeBci, CallTargetNode callTarget, JavaKind resultType) {
InvokeNode invoke = append(new InvokeNode(callTarget, invokeBci));
frameState.pushReturn(resultType, invoke);
invoke.setStateAfter(createFrameState(stream.nextBCI(), invoke));
return invoke;
}
Aggregations