|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.nodes.argument;
|
42 | 42 |
|
| 43 | +import java.util.ArrayList; |
43 | 44 | import java.util.Arrays;
|
| 45 | +import java.util.List; |
44 | 46 |
|
45 | 47 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
46 | 48 | import com.oracle.graal.python.builtins.objects.function.PArguments;
|
|
72 | 74 | import com.oracle.graal.python.util.PythonUtils;
|
73 | 75 | import com.oracle.truffle.api.CompilerDirectives;
|
74 | 76 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 77 | +import com.oracle.truffle.api.RootCallTarget; |
75 | 78 | import com.oracle.truffle.api.dsl.Cached;
|
76 | 79 | import com.oracle.truffle.api.dsl.Cached.Exclusive;
|
77 | 80 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
|
83 | 86 | import com.oracle.truffle.api.nodes.Node;
|
84 | 87 | import com.oracle.truffle.api.profiles.BranchProfile;
|
85 | 88 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
86 |
| -import java.util.ArrayList; |
87 |
| -import java.util.List; |
88 | 89 |
|
89 | 90 | @ImportStatic({PythonOptions.class, PGuards.class})
|
90 | 91 | @GenerateUncached
|
@@ -166,7 +167,25 @@ Object[] doFunctionCached(PythonObject callable, Object[] userArguments, PKeywor
|
166 | 167 | return createAndCheckArgumentsNode.execute(callable, userArguments, keywords, signature, null, defaults, kwdefaults, false);
|
167 | 168 | }
|
168 | 169 |
|
169 |
| - @Specialization(replaces = {"doFunctionCached", "doMethodCached", "doMethodFunctionAndSelfCached", "doMethodFunctionCached"}) |
| 170 | + @Specialization(guards = {"getCallTarget(callable) == cachedCallTarget", "cachedCallTarget != null"}, limit = "getVariableArgumentInlineCacheLimit()", replaces = {"doMethodFunctionCached", "doFunctionCached"}) |
| 171 | + Object[] doCallTargetCached(PythonObject callable, Object[] userArguments, PKeyword[] keywords, |
| 172 | + @Cached CreateAndCheckArgumentsNode createAndCheckArgumentsNode, |
| 173 | + @SuppressWarnings("unused") @Cached GetSignatureNode getSignatureNode, |
| 174 | + @Cached("getSignatureNode.execute(callable)") Signature signature, // signatures are attached to PRootNodes |
| 175 | + @Cached ConditionProfile gotMethod, |
| 176 | + @Cached GetDefaultsNode getDefaultsNode, |
| 177 | + @Cached GetKeywordDefaultsNode getKwDefaultsNode, |
| 178 | + @Cached("getCallTarget(callable)") @SuppressWarnings("unused") RootCallTarget cachedCallTarget) { |
| 179 | + Object[] defaults = getDefaultsNode.execute(callable); |
| 180 | + PKeyword[] kwdefaults = getKwDefaultsNode.execute(callable); |
| 181 | + Object self = null; |
| 182 | + if (gotMethod.profile(PGuards.isMethod(callable))) { |
| 183 | + self = getSelf(callable); |
| 184 | + } |
| 185 | + return createAndCheckArgumentsNode.execute(callable, userArguments, keywords, signature, self, defaults, kwdefaults, isMethodCall(self)); |
| 186 | + } |
| 187 | + |
| 188 | + @Specialization(replaces = {"doFunctionCached", "doMethodCached", "doMethodFunctionAndSelfCached", "doMethodFunctionCached", "doCallTargetCached"}) |
170 | 189 | Object[] uncached(PythonObject callable, Object[] userArguments, PKeyword[] keywords,
|
171 | 190 | @Cached("create()") CreateAndCheckArgumentsNode createAndCheckArgumentsNode) {
|
172 | 191 |
|
@@ -866,6 +885,19 @@ protected static Object getFunction(Object callable) {
|
866 | 885 | return null;
|
867 | 886 | }
|
868 | 887 |
|
| 888 | + protected static RootCallTarget getCallTarget(Object callable) { |
| 889 | + if (callable instanceof PBuiltinMethod) { |
| 890 | + return ((PBuiltinMethod) callable).getFunction().getCallTarget(); |
| 891 | + } else if (callable instanceof PMethod) { |
| 892 | + return getCallTarget(((PMethod) callable).getFunction()); |
| 893 | + } else if (callable instanceof PBuiltinFunction) { |
| 894 | + return ((PBuiltinFunction) callable).getCallTarget(); |
| 895 | + } else if (callable instanceof PFunction) { |
| 896 | + return ((PFunction) callable).getCallTarget(); |
| 897 | + } |
| 898 | + return null; |
| 899 | + } |
| 900 | + |
869 | 901 | protected static boolean isMethodCall(Object self) {
|
870 | 902 | return !(self instanceof PythonModule);
|
871 | 903 | }
|
|
0 commit comments