Skip to content

Commit b15be29

Browse files
committed
Enable AST-inlining for ternary/quaternary functions in binary calls
1 parent 2cfa186 commit b15be29

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@
4141
package com.oracle.graal.python.nodes.call.special;
4242

4343
import com.oracle.graal.python.PythonLanguage;
44+
import com.oracle.graal.python.builtins.objects.PNone;
4445
import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor.BinaryBuiltinInfo;
4546
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
4647
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4748
import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
4849
import com.oracle.graal.python.nodes.call.CallNode;
4950
import com.oracle.graal.python.nodes.call.special.LookupSpecialBaseNode.BoundDescriptor;
5051
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
52+
import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode;
5153
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
5254
import com.oracle.graal.python.runtime.PythonContext;
5355
import com.oracle.truffle.api.RootCallTarget;
@@ -365,10 +367,40 @@ Object callSelfMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMe
365367
return builtinNode.call(frame, func.getSelf(), arg1, arg2);
366368
}
367369

370+
/**
371+
* In case the function takes less or equal to 2 arguments (so it is <it>at least</it> binary)
372+
* we also try to call a ternary function.
373+
*/
374+
@Specialization(guards = {"builtinNode != null", "minArgs <= 2", "func.getCallTarget() == ct", "frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
375+
static Object callTernaryFunction(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2,
376+
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
377+
@SuppressWarnings("unused") @Cached("getMinArgs(func)") int minArgs,
378+
@SuppressWarnings("unused") @Cached("isForReverseBinaryOperation(ct)") boolean isReverse,
379+
@Cached("getTernary(frame, func)") PythonTernaryBuiltinNode builtinNode,
380+
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
381+
if (isReverse) {
382+
return builtinNode.call(frame, arg2, arg1, PNone.NO_VALUE);
383+
}
384+
return builtinNode.call(frame, arg1, arg2, PNone.NO_VALUE);
385+
}
386+
387+
/**
388+
* In case the function takes less or equal to 2 arguments (so it is <it>at least</it> binary)
389+
* we also try to call a quaternary function.
390+
*/
391+
@Specialization(guards = {"builtinNode != null", "minArgs <= 2", "func.getCallTarget() == ct", "frame != null || unusedFrame"}, limit = "getCallSiteInlineCacheMaxDepth()")
392+
static Object callQuaternaryFunction(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinFunction func, Object arg1, Object arg2,
393+
@SuppressWarnings("unused") @Cached("func.getCallTarget()") RootCallTarget ct,
394+
@SuppressWarnings("unused") @Cached("getMinArgs(func)") int minArgs,
395+
@Cached("getQuaternary(frame, func)") PythonQuaternaryBuiltinNode builtinNode,
396+
@SuppressWarnings("unused") @Cached("frameIsUnused(builtinNode)") boolean unusedFrame) {
397+
return builtinNode.call(frame, arg1, arg2, PNone.NO_VALUE, PNone.NO_VALUE);
398+
}
399+
368400
@Specialization(guards = "!isBinaryBuiltinInfo(func)", //
369401
replaces = {"callBoolSingle", "callBool", "callIntSingle", "callInt", "callBoolIntSingle", "callBoolInt", "callLongSingle", "callLong", "callBoolLongSingle",
370402
"callBoolLong", "callDoubleSingle", "callDouble", "callBoolDoubleSingle", "callBoolDouble", "callObjectSingleContext", "callObject",
371-
"callMethodSingleContext", "callSelfMethodSingleContext", "callMethod", "callSelfMethod"})
403+
"callMethodSingleContext", "callSelfMethodSingleContext", "callMethod", "callSelfMethod", "callTernaryFunction", "callQuaternaryFunction"})
372404
@Megamorphic
373405
static Object call(VirtualFrame frame, Object func, Object arg1, Object arg2,
374406
@Cached CallNode callNode,

0 commit comments

Comments
 (0)