use of org.graalvm.compiler.nodes.PiNode in project graal by oracle.
the class GraphUtil method skipPiWhileNonNull.
public static ValueNode skipPiWhileNonNull(ValueNode node) {
ValueNode n = node;
while (n instanceof PiNode) {
PiNode piNode = (PiNode) n;
ObjectStamp originalStamp = (ObjectStamp) piNode.getOriginalNode().stamp(NodeView.DEFAULT);
if (originalStamp.nonNull()) {
n = piNode.getOriginalNode();
} else {
break;
}
}
return n;
}
use of org.graalvm.compiler.nodes.PiNode in project graal by oracle.
the class MethodCallTargetNode method tryCheckCastSingleImplementor.
private boolean tryCheckCastSingleImplementor(ValueNode receiver, TypeReference speculatedType) {
ResolvedJavaType singleImplementor = speculatedType.getType();
if (singleImplementor != null) {
ResolvedJavaMethod singleImplementorMethod = singleImplementor.resolveConcreteMethod(targetMethod(), invoke().getContextType());
if (singleImplementorMethod != null) {
/**
* We have an invoke on an interface with a single implementor. We can replace this
* with an invoke virtual.
*
* To do so we need to ensure two properties: 1) the receiver must implement the
* interface (declaredReceiverType). The verifier does not prove this so we need a
* dynamic check. 2) we need to ensure that there is still only one implementor of
* this interface, i.e. that we are calling the right method. We could do this with
* an assumption but as we need an instanceof check anyway we can verify both
* properties by checking of the receiver is an instance of the single implementor.
*/
ValueAnchorNode anchor = new ValueAnchorNode(null);
if (anchor != null) {
graph().add(anchor);
graph().addBeforeFixed(invoke().asNode(), anchor);
}
LogicNode condition = graph().addOrUniqueWithInputs(InstanceOfNode.create(speculatedType, receiver, getProfile(), anchor));
FixedGuardNode guard = graph().add(new FixedGuardNode(condition, DeoptimizationReason.OptimizedTypeCheckViolated, DeoptimizationAction.InvalidateRecompile, false));
graph().addBeforeFixed(invoke().asNode(), guard);
ValueNode valueNode = graph().addOrUnique(new PiNode(receiver, StampFactory.objectNonNull(speculatedType), guard));
arguments().set(0, valueNode);
if (speculatedType.isExact()) {
setInvokeKind(InvokeKind.Special);
} else {
setInvokeKind(InvokeKind.Virtual);
}
setTargetMethod(singleImplementorMethod);
return true;
}
}
return false;
}
use of org.graalvm.compiler.nodes.PiNode in project graal by oracle.
the class PushNodesThroughPiTest method test1.
@Ignore
@Test
@SuppressWarnings("try")
public void test1() {
final String snippet = "test1Snippet";
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("PushThroughPi", new DebugDumpScope(snippet))) {
StructuredGraph graph = compileTestSnippet(snippet);
for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
long disp = address.getOffset().asJavaConstant().asLong();
ResolvedJavaType receiverType = StampTool.typeOrNull(address.getBase());
ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(disp, rn.getStackKind());
assert field != null : "Node " + rn + " tries to access a field which doesn't exists for this type";
if (field.getName().equals("x")) {
Assert.assertTrue(address.getBase() instanceof ParameterNode);
} else {
Assert.assertTrue(address.getBase().toString(), address.getBase() instanceof PiNode);
}
}
Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of org.graalvm.compiler.nodes.PiNode in project graal by oracle.
the class MultiTypeGuardInlineInfo method devirtualizeWithTypeSwitch.
private void devirtualizeWithTypeSwitch(StructuredGraph graph, InvokeKind kind, ResolvedJavaMethod target, StampProvider stampProvider, ConstantReflectionProvider constantReflection) {
AbstractBeginNode invocationEntry = graph.add(new BeginNode());
AbstractBeginNode unknownTypeSux = createUnknownTypeSuccessor(graph);
AbstractBeginNode[] successors = new AbstractBeginNode[] { invocationEntry, unknownTypeSux };
createDispatchOnTypeBeforeInvoke(graph, successors, true, stampProvider, constantReflection);
invocationEntry.setNext(invoke.asNode());
ValueNode receiver = ((MethodCallTargetNode) invoke.callTarget()).receiver();
PiNode anchoredReceiver = InliningUtil.createAnchoredReceiver(graph, invocationEntry, target.getDeclaringClass(), receiver, false);
invoke.callTarget().replaceFirstInput(receiver, anchoredReceiver);
InliningUtil.replaceInvokeCallTarget(invoke, graph, kind, target);
}
use of org.graalvm.compiler.nodes.PiNode in project graal by oracle.
the class ReflectionSubstitutionType method createCheckcast.
private static ValueNode createCheckcast(HostedGraphKit graphKit, ValueNode value, ResolvedJavaType type, boolean nonNull) {
TypeReference typeRef = TypeReference.createTrusted(graphKit.getAssumptions(), type);
LogicNode condition;
if (nonNull) {
condition = graphKit.append(InstanceOfNode.create(typeRef, value));
} else {
condition = graphKit.append(InstanceOfNode.createAllowNull(typeRef, value, null, null));
}
graphKit.startIf(condition, BranchProbabilityNode.FAST_PATH_PROBABILITY);
graphKit.thenPart();
PiNode ret = graphKit.createPiNode(value, StampFactory.object(typeRef, nonNull));
graphKit.elsePart();
throwFailedCast(graphKit, type, value);
graphKit.endIf();
return ret;
}
Aggregations