Skip to content

Commit e724a4c

Browse files
committed
use special unary/binary/ternary dispatch where possible
1 parent ad6bf1b commit e724a4c

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/DeleteAttributeNode.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,16 @@
4040
*/
4141
package com.oracle.graal.python.nodes.attributes;
4242

43+
import com.oracle.graal.python.builtins.objects.type.PythonClass;
4344
import com.oracle.graal.python.nodes.PNode;
44-
import com.oracle.graal.python.nodes.argument.CreateArgumentsNode;
45-
import com.oracle.graal.python.nodes.call.CallDispatchNode;
45+
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
4646
import com.oracle.graal.python.nodes.object.GetClassNode;
4747
import com.oracle.truffle.api.dsl.Cached;
4848
import com.oracle.truffle.api.dsl.NodeChild;
4949
import com.oracle.truffle.api.dsl.NodeChildren;
5050
import com.oracle.truffle.api.dsl.Specialization;
5151
import com.oracle.truffle.api.profiles.ValueProfile;
5252

53-
import com.oracle.graal.python.builtins.objects.function.PKeyword;
54-
import com.oracle.graal.python.builtins.objects.type.PythonClass;
55-
5653
@NodeChildren({@NodeChild(value = "object", type = PNode.class), @NodeChild(value = "key", type = PNode.class)})
5754
public abstract class DeleteAttributeNode extends PNode {
5855
public static DeleteAttributeNode create() {
@@ -70,10 +67,9 @@ protected Object doIt(Object object, Object key,
7067
@Cached("createIdentityProfile()") ValueProfile setattributeProfile,
7168
@Cached("create()") GetClassNode getClassNode,
7269
@Cached("create(__DELATTR__)") LookupAttributeInMRONode lookupDelAttr,
73-
@Cached("create()") CallDispatchNode dispatchSetattribute,
74-
@Cached("create()") CreateArgumentsNode createArgs) {
70+
@Cached("create()") CallBinaryMethodNode dispatchSetattribute) {
7571
PythonClass type = getClassNode.execute(object);
7672
Object descr = setattributeProfile.profile(lookupDelAttr.execute(type));
77-
return dispatchSetattribute.executeCall(descr, createArgs.execute(object, key), new PKeyword[0]);
73+
return dispatchSetattribute.executeObject(descr, object, key);
7874
}
7975
}

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
import com.oracle.graal.python.builtins.objects.function.PBuiltinFunction;
4444
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4545
import com.oracle.graal.python.nodes.call.CallNode;
46+
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
47+
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
48+
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
4649
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
4750
import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode.VarargsBuiltinDirectInvocationNotSupported;
4851
import com.oracle.truffle.api.dsl.Cached;
@@ -57,11 +60,32 @@ public static CallVarargsMethodNode create() {
5760

5861
@Specialization(guards = {"func == cachedFunc", "builtinNode != null"}, limit = "getCallSiteInlineCacheMaxDepth()", rewriteOn = VarargsBuiltinDirectInvocationNotSupported.class)
5962
Object call(@SuppressWarnings("unused") PBuiltinFunction func, Object[] arguments, PKeyword[] keywords,
60-
@SuppressWarnings("unused") @Cached("func") PBuiltinFunction cachedFunc,
63+
@Cached("func") @SuppressWarnings("unused") PBuiltinFunction cachedFunc,
6164
@Cached("getVarargs(func)") PythonVarargsBuiltinNode builtinNode) throws VarargsBuiltinDirectInvocationNotSupported {
6265
return builtinNode.varArgExecute(arguments, keywords);
6366
}
6467

68+
@Specialization(guards = {"arguments.length == 1", "keywords.length == 0", "func == cachedFunc", "builtinNode != null"}, limit = "getCallSiteInlineCacheMaxDepth()")
69+
Object callUnary(@SuppressWarnings("unused") PBuiltinFunction func, Object[] arguments, @SuppressWarnings("unused") PKeyword[] keywords,
70+
@Cached("func") @SuppressWarnings("unused") PBuiltinFunction cachedFunc,
71+
@Cached("getUnary(func)") PythonUnaryBuiltinNode builtinNode) throws VarargsBuiltinDirectInvocationNotSupported {
72+
return builtinNode.execute(arguments[0]);
73+
}
74+
75+
@Specialization(guards = {"arguments.length == 2", "keywords.length == 0", "func == cachedFunc", "builtinNode != null"}, limit = "getCallSiteInlineCacheMaxDepth()")
76+
Object callBinary(@SuppressWarnings("unused") PBuiltinFunction func, Object[] arguments, @SuppressWarnings("unused") PKeyword[] keywords,
77+
@Cached("func") @SuppressWarnings("unused") PBuiltinFunction cachedFunc,
78+
@Cached("getBinary(func)") PythonBinaryBuiltinNode builtinNode) throws VarargsBuiltinDirectInvocationNotSupported {
79+
return builtinNode.execute(arguments[0], arguments[1]);
80+
}
81+
82+
@Specialization(guards = {"arguments.length == 3", "keywords.length == 0", "func == cachedFunc", "builtinNode != null"}, limit = "getCallSiteInlineCacheMaxDepth()")
83+
Object callTernary(@SuppressWarnings("unused") PBuiltinFunction func, Object[] arguments, @SuppressWarnings("unused") PKeyword[] keywords,
84+
@Cached("func") @SuppressWarnings("unused") PBuiltinFunction cachedFunc,
85+
@Cached("getTernary(func)") PythonTernaryBuiltinNode builtinNode) throws VarargsBuiltinDirectInvocationNotSupported {
86+
return builtinNode.execute(arguments[0], arguments[1], arguments[2]);
87+
}
88+
6589
@Specialization
6690
Object call(Object func, Object[] arguments, PKeyword[] keywords,
6791
@Cached("create()") CallNode callNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/GetIteratorNode.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import com.oracle.graal.python.builtins.objects.array.PDoubleArray;
3333
import com.oracle.graal.python.builtins.objects.array.PIntArray;
3434
import com.oracle.graal.python.builtins.objects.array.PLongArray;
35-
import com.oracle.graal.python.builtins.objects.function.PKeyword;
3635
import com.oracle.graal.python.builtins.objects.iterator.PBuiltinIterator;
3736
import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
3837
import com.oracle.graal.python.builtins.objects.iterator.PStringIterator;
@@ -42,9 +41,8 @@
4241
import com.oracle.graal.python.builtins.objects.type.PythonClass;
4342
import com.oracle.graal.python.nodes.PNode;
4443
import com.oracle.graal.python.nodes.SpecialMethodNames;
45-
import com.oracle.graal.python.nodes.argument.CreateArgumentsNode;
4644
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
47-
import com.oracle.graal.python.nodes.call.CallDispatchNode;
45+
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
4846
import com.oracle.graal.python.nodes.control.GetIteratorNodeGen.IsIteratorObjectNodeGen;
4947
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
5048
import com.oracle.graal.python.nodes.object.GetClassNode;
@@ -150,13 +148,12 @@ public Object doGeneric(Object value,
150148
@Cached("createIdentityProfile()") ValueProfile getattributeProfile,
151149
@Cached("create(__ITER__)") LookupAttributeInMRONode lookupAttrMroNode,
152150
@Cached("create(__GETITEM__)") LookupAttributeInMRONode lookupGetitemAttrMroNode,
153-
@Cached("create()") CallDispatchNode dispatchGetattribute,
154-
@Cached("create()") CreateArgumentsNode createArgs,
151+
@Cached("create()") CallUnaryMethodNode dispatchGetattribute,
155152
@Cached("create()") IsIteratorObjectNode isIteratorObjectNode) {
156153
PythonClass clazz = getClass(value);
157154
Object attrObj = getattributeProfile.profile(lookupAttrMroNode.execute(clazz));
158155
if (attrObj != PNone.NO_VALUE && attrObj != PNone.NONE) {
159-
Object iterObj = dispatchGetattribute.executeCall(attrObj, createArgs.execute(value), PKeyword.EMPTY_KEYWORDS);
156+
Object iterObj = dispatchGetattribute.executeObject(attrObj, value);
160157
if (isIteratorObjectNode.execute(iterObj)) {
161158
return iterObj;
162159
} else {

0 commit comments

Comments
 (0)