Skip to content

Commit 4d20f4a

Browse files
committed
[GR-32229] Allow to fixup the stamp of FallbackInvokeWithExceptionNode.
PullRequest: graal/9499
2 parents bdd73ee + 0bcfad2 commit 4d20f4a

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

compiler/src/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/Graph.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ public int nodeIdCount() {
12411241
* @param replacementsMap the replacement map (can be null if no replacement is to be performed)
12421242
* @return a map which associates the original nodes from {@code nodes} to their duplicates
12431243
*/
1244-
public UnmodifiableEconomicMap<Node, Node> addDuplicates(Iterable<? extends Node> newNodes, final Graph oldGraph, int estimatedNodeCount, EconomicMap<Node, Node> replacementsMap) {
1244+
public EconomicMap<Node, Node> addDuplicates(Iterable<? extends Node> newNodes, final Graph oldGraph, int estimatedNodeCount, EconomicMap<Node, Node> replacementsMap) {
12451245
DuplicationReplacement replacements;
12461246
if (replacementsMap == null) {
12471247
replacements = null;

compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/SnippetTemplate.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,7 @@ public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAc
16081608
StructuredGraph replaceeGraph = replacee.graph();
16091609
EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
16101610
replacements.put(entryPointNode, AbstractBeginNode.prevBegin(replacee));
1611-
UnmodifiableEconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
1611+
EconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
16121612

16131613
// Re-wire the control flow graph around the replacee
16141614
FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
@@ -1712,6 +1712,8 @@ public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAc
17121712
InvokeWithExceptionNode invoke = macroNode.createInvoke(returnValue);
17131713
// replace placeholder
17141714
replaceeGraph.replaceWithExceptionSplit(fallbackInvokeNode, invoke);
1715+
// register the invoke as the replacement for the fallback invoke
1716+
duplicates.put(fallbackInvoke, invoke);
17151717
}
17161718

17171719
if (killReplacee) {
@@ -1724,15 +1726,15 @@ public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAc
17241726
}
17251727
}
17261728

1727-
private UnmodifiableEconomicMap<Node, Node> inlineSnippet(Node replacee, DebugContext debug, StructuredGraph replaceeGraph, EconomicMap<Node, Node> replacements) {
1729+
private EconomicMap<Node, Node> inlineSnippet(Node replacee, DebugContext debug, StructuredGraph replaceeGraph, EconomicMap<Node, Node> replacements) {
17281730
Mark mark = replaceeGraph.getMark();
17291731
try (InliningLog.UpdateScope scope = replaceeGraph.getInliningLog().openUpdateScope((oldNode, newNode) -> {
17301732
InliningLog log = replaceeGraph.getInliningLog();
17311733
if (oldNode == null) {
17321734
log.trackNewCallsite(newNode);
17331735
}
17341736
})) {
1735-
UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements);
1737+
EconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements);
17361738
if (scope != null) {
17371739
replaceeGraph.getInliningLog().addLog(duplicates, snippet.getInliningLog());
17381740
}

compiler/src/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/nodes/FallbackInvokeWithExceptionNode.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,17 @@
3131
import static org.graalvm.compiler.nodes.Invoke.CYCLES_UNKNOWN_RATIONALE;
3232
import static org.graalvm.compiler.nodes.Invoke.SIZE_UNKNOWN_RATIONALE;
3333

34-
import org.graalvm.compiler.core.common.type.StampFactory;
35-
import org.graalvm.compiler.core.common.type.TypeReference;
34+
import org.graalvm.compiler.core.common.type.Stamp;
3635
import org.graalvm.compiler.graph.NodeClass;
3736
import org.graalvm.compiler.nodeinfo.NodeInfo;
3837
import org.graalvm.compiler.nodes.WithExceptionNode;
3938
import org.graalvm.compiler.nodes.memory.SingleMemoryKill;
4039
import org.graalvm.word.LocationIdentity;
4140

42-
import jdk.vm.ci.meta.MetaAccessProvider;
43-
4441
/**
4542
* Placeholder for a fallback call from a {@link MacroStateSplitWithExceptionNode}.
4643
*
47-
* The {@link #fallbackFunctionCallThrowing()} intrinsic can be used in snippets that lower a
44+
* The {@link #fallbackFunctionCall()} intrinsic can be used in snippets that lower a
4845
* {@link MacroStateSplitWithExceptionNode}. The {@link FallbackInvokeWithExceptionNode} will be
4946
* replaced with the {@linkplain MacroStateSplitWithExceptionNode#createInvoke original call} of the
5047
* macro node. This can be useful for handling exceptional and/or slow path cases.
@@ -60,18 +57,27 @@ public final class FallbackInvokeWithExceptionNode extends WithExceptionNode imp
6057

6158
public static final NodeClass<FallbackInvokeWithExceptionNode> TYPE = NodeClass.create(FallbackInvokeWithExceptionNode.class);
6259

63-
public FallbackInvokeWithExceptionNode(@InjectedNodeParameter MetaAccessProvider metaAccess) {
64-
super(TYPE, StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Object.class))));
60+
public FallbackInvokeWithExceptionNode(@InjectedNodeParameter Stamp stamp) {
61+
super(TYPE, stamp);
6562
}
6663

6764
@Override
6865
public LocationIdentity getKilledLocationIdentity() {
6966
return LocationIdentity.any();
7067
}
7168

69+
/**
70+
* At the time when this node was created (i.e. when creating the snippet template), we did not
71+
* have actual parameters so the precise stamp was not known. To fix that, we allow updating it
72+
* after the snippet was instantiated.
73+
*/
74+
public boolean updateInitialStamp(Stamp newStamp) {
75+
return updateStamp(newStamp);
76+
}
77+
7278
/**
7379
* @see FallbackInvokeWithExceptionNode
7480
*/
7581
@NodeIntrinsic
76-
public static native void fallbackFunctionCallThrowing();
82+
public static native Object fallbackFunctionCall();
7783
}

0 commit comments

Comments
 (0)