|
41 | 41 | package com.oracle.graal.python.nodes.call.special;
|
42 | 42 |
|
43 | 43 | import com.oracle.graal.python.PythonLanguage;
|
| 44 | +import com.oracle.graal.python.builtins.objects.PNone; |
44 | 45 | import com.oracle.graal.python.builtins.objects.function.BuiltinMethodDescriptor.BinaryBuiltinInfo;
|
45 | 46 | import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
|
46 | 47 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
47 | 48 | import com.oracle.graal.python.builtins.objects.method.PBuiltinMethod;
|
48 | 49 | import com.oracle.graal.python.nodes.call.CallNode;
|
49 | 50 | import com.oracle.graal.python.nodes.call.special.LookupSpecialBaseNode.BoundDescriptor;
|
50 | 51 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
| 52 | +import com.oracle.graal.python.nodes.function.builtins.PythonQuaternaryBuiltinNode; |
51 | 53 | import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
|
52 | 54 | import com.oracle.graal.python.runtime.PythonContext;
|
53 | 55 | import com.oracle.truffle.api.RootCallTarget;
|
@@ -365,10 +367,40 @@ Object callSelfMethod(VirtualFrame frame, @SuppressWarnings("unused") PBuiltinMe
|
365 | 367 | return builtinNode.call(frame, func.getSelf(), arg1, arg2);
|
366 | 368 | }
|
367 | 369 |
|
| 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 | + |
368 | 400 | @Specialization(guards = "!isBinaryBuiltinInfo(func)", //
|
369 | 401 | replaces = {"callBoolSingle", "callBool", "callIntSingle", "callInt", "callBoolIntSingle", "callBoolInt", "callLongSingle", "callLong", "callBoolLongSingle",
|
370 | 402 | "callBoolLong", "callDoubleSingle", "callDouble", "callBoolDoubleSingle", "callBoolDouble", "callObjectSingleContext", "callObject",
|
371 |
| - "callMethodSingleContext", "callSelfMethodSingleContext", "callMethod", "callSelfMethod"}) |
| 403 | + "callMethodSingleContext", "callSelfMethodSingleContext", "callMethod", "callSelfMethod", "callTernaryFunction", "callQuaternaryFunction"}) |
372 | 404 | @Megamorphic
|
373 | 405 | static Object call(VirtualFrame frame, Object func, Object arg1, Object arg2,
|
374 | 406 | @Cached CallNode callNode,
|
|
0 commit comments