Skip to content

Commit

Permalink
compiler: handle FallbackInvokeWithExceptionNode in SnippetTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
zapster committed Jul 5, 2021
1 parent 7fcee9f commit a6d12ed
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import org.graalvm.compiler.nodes.FixedWithNextNode;
import org.graalvm.compiler.nodes.FrameState;
import org.graalvm.compiler.nodes.InliningLog;
import org.graalvm.compiler.nodes.InvokeWithExceptionNode;
import org.graalvm.compiler.nodes.LogicNode;
import org.graalvm.compiler.nodes.LoopBeginNode;
import org.graalvm.compiler.nodes.LoopExitNode;
Expand Down Expand Up @@ -169,7 +170,9 @@
import org.graalvm.compiler.phases.util.Providers;
import org.graalvm.compiler.replacements.nodes.CStringConstant;
import org.graalvm.compiler.replacements.nodes.ExplodeLoopNode;
import org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode;
import org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode;
import org.graalvm.compiler.replacements.nodes.MacroStateSplitWithExceptionNode;
import org.graalvm.compiler.virtual.phases.ea.PartialEscapePhase;
import org.graalvm.util.CollectionsUtil;
import org.graalvm.word.LocationIdentity;
Expand Down Expand Up @@ -867,6 +870,15 @@ protected SnippetTemplate(OptionValues options, DebugContext debug, final Provid
unwindPath.setNext(snippetCopy.add(new UnreachableControlSinkNode()));
}

List<FallbackInvokeWithExceptionNode> fallbackInvokes = snippetCopy.getNodes().filter(FallbackInvokeWithExceptionNode.class).snapshot();
if (fallbackInvokes.size() == 0) {
fallbackInvoke = null;
} else if (fallbackInvokes.size() > 1) {
throw GraalError.shouldNotReachHere("Graph has more than one " + FallbackInvokeWithExceptionNode.class.getSimpleName());
} else {
fallbackInvoke = fallbackInvokes.get(0);
}

CanonicalizerPhase canonicalizer;
if (GraalOptions.ImmutableCode.getValue(snippetCopy.getOptions())) {
canonicalizer = CanonicalizerPhase.createWithoutReadCanonicalization();
Expand Down Expand Up @@ -1234,6 +1246,11 @@ private static boolean checkNonNull(ResolvedJavaMethod method, String parameterN
*/
private final FixedWithNextNode unwindPath;

/**
* The fallback invoke (if any) of the snippet.
*/
private final FallbackInvokeWithExceptionNode fallbackInvoke;

/**
* The memory anchor (if any) of the snippet.
*/
Expand Down Expand Up @@ -1686,6 +1703,17 @@ public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAc
}
}

if (fallbackInvoke != null) {
GraalError.guarantee(replacee instanceof MacroStateSplitWithExceptionNode, "%s can only be used in snippets replacing %s", FallbackInvokeWithExceptionNode.class.getSimpleName(),
MacroStateSplitWithExceptionNode.class.getSimpleName());
WithExceptionNode fallbackInvokeNode = (WithExceptionNode) duplicates.get(fallbackInvoke);
MacroStateSplitWithExceptionNode macroNode = (MacroStateSplitWithExceptionNode) replacee;
// create fallback invoke
InvokeWithExceptionNode invoke = macroNode.createInvoke(returnValue);
// replace placeholder
replaceeGraph.replaceWithExceptionSplit(fallbackInvokeNode, invoke);
}

if (killReplacee) {
// Remove the replacee from its graph
GraphUtil.killCFG(replacee);
Expand Down

0 comments on commit a6d12ed

Please sign in to comment.