use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.
the class GraphKit method startIf.
/**
* Starts an if-block. This call can be followed by a call to {@link #thenPart} to start
* emitting the code executed when the condition hold; and a call to {@link #elsePart} to start
* emititng the code when the condition does not hold. It must be followed by a call to
* {@link #endIf} to close the if-block.
*
* @param condition The condition for the if-block
* @param trueProbability The estimated probability the condition is true
* @return the created {@link IfNode}.
*/
public IfNode startIf(LogicNode condition, double trueProbability) {
AbstractBeginNode thenSuccessor = graph.add(new BeginNode());
AbstractBeginNode elseSuccessor = graph.add(new BeginNode());
IfNode node = append(new IfNode(condition, thenSuccessor, elseSuccessor, trueProbability));
lastFixedNode = null;
IfStructure s = new IfStructure();
s.state = IfState.CONDITION;
s.thenPart = thenSuccessor;
s.elsePart = elseSuccessor;
pushStructure(s);
return node;
}
use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.
the class IntegerExactArithmeticSplitNode method lower.
static void lower(LoweringTool tool, IntegerExactArithmeticNode node) {
if (node.asNode().graph().getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
FloatingNode floatingNode = (FloatingNode) node;
FixedWithNextNode previous = tool.lastFixedNode();
FixedNode next = previous.next();
previous.setNext(null);
DeoptimizeNode deopt = floatingNode.graph().add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.ArithmeticException));
AbstractBeginNode normalBegin = floatingNode.graph().add(new BeginNode());
normalBegin.setNext(next);
IntegerExactArithmeticSplitNode split = node.createSplit(normalBegin, BeginNode.begin(deopt));
previous.setNext(split);
floatingNode.replaceAndDelete(split);
}
}
use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.
the class ProbabilityDirectiveTest method checkLowTierGraph.
@Override
protected boolean checkLowTierGraph(StructuredGraph graph) {
NodeIterable<IfNode> ifNodes = graph.getNodes(IfNode.TYPE);
Assert.assertEquals("IfNode count", 1, ifNodes.count());
IfNode ifNode = ifNodes.first();
AbstractBeginNode oneSuccessor;
if (returnValue(ifNode.trueSuccessor()) == 1) {
oneSuccessor = ifNode.trueSuccessor();
} else {
assert returnValue(ifNode.falseSuccessor()) == 1;
oneSuccessor = ifNode.falseSuccessor();
}
Assert.assertEquals("branch probability of " + ifNode, 0.125, ifNode.probability(oneSuccessor), 0);
return true;
}
use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.
the class BytecodeParser method guardIntrinsic.
/**
* Weaves a test of the receiver type to ensure the dispatch will select {@code targetMethod}
* and not another method that overrides it. This should only be called if there is an intrinsic
* (i.e., an {@link InvocationPlugin}) for {@code targetMethod} and the invocation is indirect.
*
* The control flow woven around the intrinsic is as follows:
*
* <pre>
* if (LoadMethod(LoadHub(receiver)) == targetMethod) {
* <intrinsic for targetMethod>
* } else {
* <virtual call to targetMethod>
* }
* </pre>
*
* The {@code else} branch is woven by {@link #afterInvocationPluginExecution}.
*
* @return {@code null} if the intrinsic cannot be used otherwise an object to be used by
* {@link #afterInvocationPluginExecution} to weave code for the non-intrinsic branch
*/
protected IntrinsicGuard guardIntrinsic(ValueNode[] args, ResolvedJavaMethod targetMethod, InvocationPluginReceiver pluginReceiver) {
ValueNode intrinsicReceiver = args[0];
ResolvedJavaType receiverType = StampTool.typeOrNull(intrinsicReceiver);
if (receiverType == null) {
// The verifier guarantees it to be at least type declaring targetMethod
receiverType = targetMethod.getDeclaringClass();
}
ResolvedJavaMethod resolvedMethod = receiverType.resolveMethod(targetMethod, method.getDeclaringClass());
if (resolvedMethod == null || resolvedMethod.equals(targetMethod)) {
assert resolvedMethod == null || targetMethod.getDeclaringClass().isAssignableFrom(resolvedMethod.getDeclaringClass());
Mark mark = graph.getMark();
FixedWithNextNode currentLastInstr = lastInstr;
ValueNode nonNullReceiver = pluginReceiver.get();
Stamp methodStamp = stampProvider.createMethodStamp();
LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, nonNullReceiver));
LoadMethodNode actual = append(new LoadMethodNode(methodStamp, targetMethod, receiverType, method.getDeclaringClass(), hub));
ConstantNode expected = graph.unique(ConstantNode.forConstant(methodStamp, targetMethod.getEncoding(), getMetaAccess()));
LogicNode compare = graph.addOrUniqueWithInputs(CompareNode.createCompareNode(constantReflection, metaAccess, options, null, CanonicalCondition.EQ, actual, expected, NodeView.DEFAULT));
JavaTypeProfile profile = null;
if (profilingInfo != null && this.optimisticOpts.useTypeCheckHints(getOptions())) {
profile = profilingInfo.getTypeProfile(bci());
if (profile != null) {
JavaTypeProfile newProfile = adjustProfileForInvocationPlugin(profile, targetMethod);
if (newProfile != profile) {
if (newProfile.getTypes().length == 0) {
// All profiled types select the intrinsic so
// emit a fixed guard instead of an if-then-else.
lastInstr = append(new FixedGuardNode(compare, TypeCheckedInliningViolated, InvalidateReprofile, false));
return new IntrinsicGuard(currentLastInstr, intrinsicReceiver, mark, null, null);
}
} else {
// No profiled types select the intrinsic so emit a virtual call
return null;
}
profile = newProfile;
}
}
AbstractBeginNode intrinsicBranch = graph.add(new BeginNode());
AbstractBeginNode nonIntrinsicBranch = graph.add(new BeginNode());
append(new IfNode(compare, intrinsicBranch, nonIntrinsicBranch, FAST_PATH_PROBABILITY));
lastInstr = intrinsicBranch;
return new IntrinsicGuard(currentLastInstr, intrinsicReceiver, mark, nonIntrinsicBranch, profile);
} else {
// Receiver selects an overriding method so emit a virtual call
return null;
}
}
use of org.graalvm.compiler.nodes.AbstractBeginNode in project graal by oracle.
the class BytecodeParser method createNonInlinedInvoke.
protected Invoke createNonInlinedInvoke(ExceptionEdgeAction exceptionEdge, int invokeBci, CallTargetNode callTarget, JavaKind resultType) {
if (exceptionEdge == ExceptionEdgeAction.OMIT) {
return createInvoke(invokeBci, callTarget, resultType);
} else {
Invoke invoke = createInvokeWithException(invokeBci, callTarget, resultType, exceptionEdge);
AbstractBeginNode beginNode = graph.add(KillingBeginNode.create(LocationIdentity.any()));
invoke.setNext(beginNode);
lastInstr = beginNode;
return invoke;
}
}
Aggregations