Skip to content

Commit d1f33d2

Browse files
committed
Compare root nodes in inline cache guards instead of call targets
1 parent cbc538f commit d1f33d2

8 files changed

Lines changed: 38 additions & 49 deletions

File tree

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,6 @@ public Signature getSignature() {
579579
return signature;
580580
}
581581

582-
public RootCallTarget getRootCallTargetOrNull() {
583-
return callTarget;
584-
}
585-
586582
public RootCallTarget getRootCallTarget() {
587583
RootCallTarget ct = callTarget;
588584
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, ct == null)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PBuiltinFunction.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ public Signature getSignature() {
198198
return signature;
199199
}
200200

201-
public RootCallTarget getCallTargetOrNull() {
202-
return callTarget;
203-
}
204-
205201
public RootCallTarget getCallTarget() {
206202
RootCallTarget ct = callTarget;
207203
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, ct == null)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,6 @@ public PCode getCode() {
165165
return code;
166166
}
167167

168-
public RootCallTarget getCallTargetOrNull() {
169-
RootCallTarget ct = callTarget;
170-
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, ct == null)) {
171-
ct = getCode().getRootCallTargetOrNull();
172-
callTarget = ct;
173-
}
174-
return ct;
175-
}
176-
177168
public RootCallTarget getCallTarget() {
178169
RootCallTarget ct = callTarget;
179170
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, ct == null)) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/CallDispatchers.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import com.oracle.truffle.api.nodes.DirectCallNode;
7676
import com.oracle.truffle.api.nodes.IndirectCallNode;
7777
import com.oracle.truffle.api.nodes.Node;
78+
import com.oracle.truffle.api.nodes.RootNode;
7879
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
7980

8081
public class CallDispatchers {
@@ -192,8 +193,9 @@ static Object callBuiltinFunctionCached(VirtualFrame frame, Node inliningTarget,
192193
return invoke.execute(frame, inliningTarget, callNode, arguments);
193194
}
194195

195-
@Specialization(guards = "sameCallTarget(callee.getCallTargetOrNull(), callNode)", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached")
196+
@Specialization(guards = "callee.getFunctionRootNode() == rootNode", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached")
196197
static Object callBuiltinFunctionCachedCt(VirtualFrame frame, Node inliningTarget, @SuppressWarnings("unused") PBuiltinFunction callee, Object[] arguments,
198+
@SuppressWarnings("unused") @Cached(value = "callee.getFunctionRootNode()", adopt = false) RootNode rootNode,
197199
@Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode,
198200
@Exclusive @Cached SimpleDirectInvokeNode invoke) {
199201
return invoke.execute(frame, inliningTarget, callNode, arguments);
@@ -231,8 +233,9 @@ static Object callBuiltinFunctionCached(VirtualFrame frame, Node inliningTarget,
231233
return invoke.execute(frame, inliningTarget, callNode, pArguments);
232234
}
233235

234-
@Specialization(guards = "sameCallTarget(callee.getCallTargetOrNull(), callNode)", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached")
236+
@Specialization(guards = "callee.getFunctionRootNode() == rootNode", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinFunctionCached")
235237
static Object callBuiltinFunctionCachedCt(VirtualFrame frame, Node inliningTarget, PBuiltinFunction callee, Object[] arguments, PKeyword[] keywords,
238+
@SuppressWarnings("unused") @Cached(value = "callee.getFunctionRootNode()", adopt = false) RootNode rootNode,
236239
@Exclusive @Cached CreateArgumentsNode createArgs,
237240
@Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode,
238241
@Exclusive @Cached SimpleDirectInvokeNode invoke) {
@@ -287,9 +290,10 @@ static Object callBuiltinMethodCached(VirtualFrame frame, Node inliningTarget, @
287290
return invoke.execute(frame, inliningTarget, callNode, pArguments);
288291
}
289292

290-
@Specialization(guards = "sameCallTarget(function.getCallTargetOrNull(), callNode)", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinMethodCached")
293+
@Specialization(guards = "function.getFunctionRootNode() == rootNode", limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callBuiltinMethodCached")
291294
static Object callBuiltinMethodCachedCt(VirtualFrame frame, Node inliningTarget, PBuiltinMethod callee, Object[] arguments, PKeyword[] keywords,
292295
@Bind("callee.getBuiltinFunction()") PBuiltinFunction function,
296+
@SuppressWarnings("unused") @Cached(value = "function.getFunctionRootNode()", adopt = false) RootNode rootNode,
293297
@Exclusive @Cached CreateArgumentsNode createArgs,
294298
@Cached("createDirectCallNodeFor(function)") DirectCallNode callNode,
295299
@Exclusive @Cached SimpleDirectInvokeNode invoke) {
@@ -390,8 +394,9 @@ static Object callFunctionCached(VirtualFrame frame, Node inliningTarget, @Suppr
390394
}
391395

392396
// We have multiple contexts, don't cache the objects so that contexts can be cleaned up
393-
@Specialization(guards = {"sameCallTarget(callee.getCallTargetOrNull(), callNode)"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached")
397+
@Specialization(guards = {"callee.getCode().getRootNode() == rootNode"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached")
394398
static Object callFunctionCachedCt(VirtualFrame frame, Node inliningTarget, PFunction callee, Object[] arguments,
399+
@SuppressWarnings("unused") @Cached(value = "callee.getCode().getRootNode()", adopt = false) RootNode rootNode,
395400
@Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode,
396401
@Exclusive @Cached FunctionDirectInvokeNode invoke) {
397402
return invoke.execute(frame, inliningTarget, callNode, callee, arguments);
@@ -408,7 +413,7 @@ static Object callFunctionMegamorphic(VirtualFrame frame, Node inliningTarget, P
408413

409414
/**
410415
* Node for calling python functions with an inline cache on the function object and a secondary
411-
* inline cache on the call target. Takes PArguments
416+
* inline cache on the call target.
412417
*/
413418
@GenerateInline
414419
@GenerateCached(false)
@@ -430,8 +435,9 @@ static Object callFunctionCached(VirtualFrame frame, Node inliningTarget, @Suppr
430435
}
431436

432437
// We have multiple contexts, don't cache the objects so that contexts can be cleaned up
433-
@Specialization(guards = {"sameCallTarget(callee.getCallTargetOrNull(), callNode)"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached")
438+
@Specialization(guards = {"callee.getCode().getRootNode() == rootNode"}, limit = "getCallSiteInlineCacheMaxDepth()", replaces = "callFunctionCached")
434439
static Object callFunctionCachedCt(VirtualFrame frame, Node inliningTarget, PFunction callee, Object[] arguments, PKeyword[] keywords,
440+
@SuppressWarnings("unused") @Cached(value = "callee.getCode().getRootNode()", adopt = false) RootNode rootNode,
435441
@Exclusive @Cached CreateArgumentsNode createArgs,
436442
@Cached("createDirectCallNodeFor(callee)") DirectCallNode callNode,
437443
@Exclusive @Cached FunctionDirectInvokeNode invoke) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallBinaryMethodNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.graal.python.nodes.call.CallNode;
4848
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4949
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
50-
import com.oracle.truffle.api.RootCallTarget;
5150
import com.oracle.truffle.api.dsl.Bind;
5251
import com.oracle.truffle.api.dsl.Cached;
5352
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -59,6 +58,7 @@
5958
import com.oracle.truffle.api.frame.Frame;
6059
import com.oracle.truffle.api.frame.VirtualFrame;
6160
import com.oracle.truffle.api.nodes.Node;
61+
import com.oracle.truffle.api.nodes.RootNode;
6262
import com.oracle.truffle.api.nodes.UnexpectedResultException;
6363
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
6464

@@ -93,10 +93,10 @@ static Object callObjectSingleContext(VirtualFrame frame, @SuppressWarnings("unu
9393
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
9494
}
9595

96-
@Specialization(guards = {"func.getCallTargetOrNull() == ct", "builtinNode != null"}, //
96+
@Specialization(guards = {"func.getFunctionRootNode() == rootNode", "builtinNode != null"}, //
9797
limit = "getCallSiteInlineCacheMaxDepth()")
9898
static Object callObject(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2,
99-
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
99+
@SuppressWarnings("unused") @Cached(value = "func.getFunctionRootNode()", adopt = false) RootNode rootNode,
100100
@Cached("getBuiltin(frame, func, 2)") PythonBuiltinBaseNode builtinNode) {
101101
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
102102
}
@@ -109,9 +109,9 @@ static Object callMethodSingleContext(VirtualFrame frame, @SuppressWarnings("unu
109109
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
110110
}
111111

112-
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getCallTargetOrNull() == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
112+
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
113113
static Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2,
114-
@SuppressWarnings("unused") @Cached("func.getBuiltinFunction().getCallTarget()") RootCallTarget ct,
114+
@SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode,
115115
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
116116
@Cached("getBuiltin(frame, func.getBuiltinFunction(), 2)") PythonBuiltinBaseNode builtinNode) {
117117
return callBinaryBuiltin(frame, builtinNode, arg1, arg2);
@@ -125,9 +125,9 @@ static Object callMethodSingleContextSelf(VirtualFrame frame, @SuppressWarnings(
125125
return callTernaryBuiltin(frame, builtinNode, cachedFunc.getSelf(), arg1, arg2);
126126
}
127127

128-
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getCallTargetOrNull() == ct", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
128+
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
129129
static Object callMethodSelf(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2,
130-
@SuppressWarnings("unused") @Cached("func.getBuiltinFunction().getCallTarget()") RootCallTarget ct,
130+
@SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode,
131131
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
132132
@Cached("getBuiltin(frame, func.getBuiltinFunction(), 3)") PythonBuiltinBaseNode builtinNode) {
133133
return callTernaryBuiltin(frame, builtinNode, func.getSelf(), arg1, arg2);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallQuaternaryMethodNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.graal.python.nodes.call.CallNode;
4848
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4949
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
50-
import com.oracle.truffle.api.RootCallTarget;
5150
import com.oracle.truffle.api.dsl.Bind;
5251
import com.oracle.truffle.api.dsl.Cached;
5352
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -56,6 +55,7 @@
5655
import com.oracle.truffle.api.frame.Frame;
5756
import com.oracle.truffle.api.frame.VirtualFrame;
5857
import com.oracle.truffle.api.nodes.Node;
58+
import com.oracle.truffle.api.nodes.RootNode;
5959
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
6060

6161
@GenerateUncached
@@ -79,10 +79,10 @@ Object callSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFuncti
7979
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);
8080
}
8181

82-
@Specialization(guards = {"func.getCallTargetOrNull() == ct", "builtinNode != null"}, //
82+
@Specialization(guards = {"func.getFunctionRootNode() == rootNode", "builtinNode != null"}, //
8383
limit = "getCallSiteInlineCacheMaxDepth()")
8484
Object call(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3, Object arg4,
85-
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
85+
@SuppressWarnings("unused") @Cached(value = "func.getFunctionRootNode()", adopt = false) RootNode rootNode,
8686
@Cached("getBuiltin(frame, func, 4)") PythonBuiltinBaseNode builtinNode) {
8787
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);
8888
}
@@ -95,9 +95,9 @@ Object callMethodSingle(VirtualFrame frame, @SuppressWarnings("unused") PBuiltin
9595
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);
9696
}
9797

98-
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getCallTargetOrNull() == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
98+
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
9999
Object callMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3, Object arg4,
100-
@SuppressWarnings("unused") @Cached("func.getBuiltinFunction().getCallTarget()") RootCallTarget ct,
100+
@SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode,
101101
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
102102
@Cached("getBuiltin(frame, func.getBuiltinFunction(), 4)") PythonBuiltinBaseNode builtinNode) {
103103
return callQuaternaryBuiltin(frame, builtinNode, arg1, arg2, arg3, arg4);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/CallTernaryMethodNode.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import com.oracle.graal.python.nodes.call.CallNode;
4848
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4949
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
50-
import com.oracle.truffle.api.RootCallTarget;
5150
import com.oracle.truffle.api.dsl.Bind;
5251
import com.oracle.truffle.api.dsl.Cached;
5352
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -57,6 +56,7 @@
5756
import com.oracle.truffle.api.frame.Frame;
5857
import com.oracle.truffle.api.frame.VirtualFrame;
5958
import com.oracle.truffle.api.nodes.Node;
59+
import com.oracle.truffle.api.nodes.RootNode;
6060
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
6161

6262
@GenerateUncached
@@ -79,10 +79,10 @@ static Object doBuiltinFunctionCached(VirtualFrame frame, @SuppressWarnings("unu
7979
return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3);
8080
}
8181

82-
@Specialization(guards = {"func.getCallTargetOrNull() == ct", "builtinNode != null"}, //
82+
@Specialization(guards = {"func.getFunctionRootNode() == rootNode", "builtinNode != null"}, //
8383
limit = "getCallSiteInlineCacheMaxDepth()")
8484
static Object doBuiltinFunctionCtCached(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2, Object arg3,
85-
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
85+
@SuppressWarnings("unused") @Cached(value = "func.getFunctionRootNode()", adopt = false) RootNode rootNode,
8686
@Cached("getBuiltin(frame, func, 3)") PythonBuiltinBaseNode builtinNode) {
8787
return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3);
8888
}
@@ -95,9 +95,9 @@ static Object doBuiltinMethodCached(VirtualFrame frame, @SuppressWarnings("unuse
9595
return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3);
9696
}
9797

98-
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getCallTargetOrNull() == ct", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
98+
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "!takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
9999
static Object doBuiltinMethodCtCached(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3,
100-
@SuppressWarnings("unused") @Cached("func.getBuiltinFunction().getCallTarget()") RootCallTarget ct,
100+
@SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode,
101101
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
102102
@Cached("getBuiltin(frame, func.getBuiltinFunction(), 3)") PythonBuiltinBaseNode builtinNode) {
103103
return callTernaryBuiltin(frame, builtinNode, arg1, arg2, arg3);
@@ -111,9 +111,9 @@ static Object callSelfMethodSingleContext(VirtualFrame frame, @SuppressWarnings(
111111
return callQuaternaryBuiltin(frame, builtinNode, func.getSelf(), arg1, arg2, arg3);
112112
}
113113

114-
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getCallTargetOrNull() == ct", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
114+
@Specialization(guards = {"builtinNode != null", "func.getBuiltinFunction().getFunctionRootNode() == rootNode", "takesSelfArg"}, limit = "getCallSiteInlineCacheMaxDepth()")
115115
static Object callSelfMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMethod func, Object arg1, Object arg2, Object arg3,
116-
@SuppressWarnings("unused") @Cached("func.getBuiltinFunction().getCallTarget()") RootCallTarget ct,
116+
@SuppressWarnings("unused") @Cached(value = "func.getBuiltinFunction().getFunctionRootNode()", adopt = false) RootNode rootNode,
117117
@SuppressWarnings("unused") @Cached("takesSelfArg(func)") boolean takesSelfArg,
118118
@Cached("getBuiltin(frame, func.getBuiltinFunction(), 4)") PythonBuiltinBaseNode builtinNode) {
119119
return callQuaternaryBuiltin(frame, builtinNode, func.getSelf(), arg1, arg2, arg3);

0 commit comments

Comments
 (0)