50
50
import java .util .Arrays ;
51
51
import java .util .List ;
52
52
53
+ import com .oracle .graal .python .PythonLanguage ;
53
54
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
54
55
import com .oracle .graal .python .builtins .objects .code .CodeNodes ;
55
56
import com .oracle .graal .python .builtins .objects .code .PCode ;
85
86
import com .oracle .truffle .api .dsl .Bind ;
86
87
import com .oracle .truffle .api .dsl .Cached ;
87
88
import com .oracle .truffle .api .dsl .Cached .Exclusive ;
89
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
88
90
import com .oracle .truffle .api .dsl .GenerateCached ;
89
91
import com .oracle .truffle .api .dsl .GenerateInline ;
90
92
import com .oracle .truffle .api .dsl .GenerateUncached ;
93
+ import com .oracle .truffle .api .dsl .Idempotent ;
91
94
import com .oracle .truffle .api .dsl .ImportStatic ;
92
95
import com .oracle .truffle .api .dsl .Specialization ;
93
96
import com .oracle .truffle .api .nodes .ExplodeLoop ;
@@ -113,12 +116,11 @@ public abstract class CreateArgumentsNode extends PNodeWithContext {
113
116
Object [] doMethodCached (@ SuppressWarnings ("unused" ) PMethodBase method , Object [] userArguments , PKeyword [] keywords ,
114
117
@ Bind ("this" ) Node inliningTarget ,
115
118
@ Cached CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
116
- @ Cached InlinedBranchProfile wasFirst ,
117
119
@ Cached (value = "method" , weak = true ) PMethodBase cachedMethod ) {
118
120
119
121
CompilerAsserts .partialEvaluationConstant (getFunction (cachedMethod ));
120
122
// Following getters should fold since getFunction(cachedMethod) is constant
121
- Signature signature = GetSignatureNode .getMethodSignatureSingleContext (cachedMethod , inliningTarget , wasFirst );
123
+ Signature signature = GetSignatureNode .getMethodSignatureSingleContext (cachedMethod , inliningTarget );
122
124
Object [] defaults = GetDefaultsNode .getMethodDefaults (cachedMethod );
123
125
PKeyword [] kwdefaults = GetKeywordDefaultsNode .getMethodKeywords (cachedMethod );
124
126
Object self = cachedMethod .getSelf ();
@@ -133,12 +135,11 @@ Object[] doMethodCached(@SuppressWarnings("unused") PMethodBase method, Object[]
133
135
Object [] doMethodFunctionAndSelfCached (PMethodBase method , Object [] userArguments , PKeyword [] keywords ,
134
136
@ Bind ("this" ) Node inliningTarget ,
135
137
@ Cached CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
136
- @ Cached InlinedBranchProfile wasFirst ,
137
138
@ Cached (value = "getFunction(method)" , weak = true ) @ SuppressWarnings ("unused" ) Object cachedFunction ,
138
139
@ Cached (value = "method.getSelf()" , weak = true ) Object cachedSelf ,
139
140
@ Cached (value = "getClassObject(method)" , weak = true ) Object cachedClassObject ) {
140
141
// Following getters should fold since getFunction(cachedMethod) is constant
141
- Signature signature = GetSignatureNode .getFunctionSignatureSingleContext (inliningTarget , wasFirst , cachedFunction );
142
+ Signature signature = GetSignatureNode .getFunctionSignatureSingleContext (inliningTarget , cachedFunction );
142
143
Object [] defaults = GetDefaultsNode .getFunctionDefaults (cachedFunction );
143
144
PKeyword [] kwdefaults = GetKeywordDefaultsNode .getFunctionKeywords (cachedFunction );
144
145
return createAndCheckArgumentsNode .execute (inliningTarget , method , userArguments , keywords , signature , cachedSelf , cachedClassObject , defaults , kwdefaults , isMethodCall (cachedSelf ));
@@ -147,11 +148,10 @@ Object[] doMethodFunctionAndSelfCached(PMethodBase method, Object[] userArgument
147
148
@ Specialization (guards = {"isSingleContext()" , "getFunction(method) == cachedFunction" }, limit = "getVariableArgumentInlineCacheLimit()" , replaces = "doMethodFunctionAndSelfCached" )
148
149
Object [] doMethodFunctionCached (PMethodBase method , Object [] userArguments , PKeyword [] keywords ,
149
150
@ Bind ("this" ) Node inliningTarget ,
150
- @ Cached InlinedBranchProfile wasFirst ,
151
151
@ Cached CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
152
152
@ Cached (value = "getFunction(method)" , weak = true ) @ SuppressWarnings ("unused" ) Object cachedFunction ) {
153
153
// Following getters should fold since getFunction(cachedMethod) is constant
154
- Signature signature = GetSignatureNode .getFunctionSignatureSingleContext (inliningTarget , wasFirst , cachedFunction );
154
+ Signature signature = GetSignatureNode .getFunctionSignatureSingleContext (inliningTarget , cachedFunction );
155
155
Object [] defaults = GetDefaultsNode .getFunctionDefaults (cachedFunction );
156
156
PKeyword [] kwdefaults = GetKeywordDefaultsNode .getFunctionKeywords (cachedFunction );
157
157
Object self = method .getSelf ();
@@ -163,10 +163,8 @@ Object[] doMethodFunctionCached(PMethodBase method, Object[] userArguments, PKey
163
163
Object [] doFunctionCached (PFunction callable , Object [] userArguments , PKeyword [] keywords ,
164
164
@ Bind ("this" ) Node inliningTarget ,
165
165
@ Cached CreateAndCheckArgumentsNode createAndCheckArgumentsNode ,
166
- @ Cached InlinedBranchProfile firstExecution ,
167
166
@ Cached (value = "callable" , weak = true ) @ SuppressWarnings ("unused" ) PFunction cachedCallable ) {
168
-
169
- Signature signature = CodeNodes .GetCodeSignatureNode .getInSingleContextMode (inliningTarget , callable , firstExecution );
167
+ Signature signature = CodeNodes .GetCodeSignatureNode .getInSingleContextMode (inliningTarget , cachedCallable );
170
168
Object [] defaults = cachedCallable .getDefaults ();
171
169
PKeyword [] kwdefaults = cachedCallable .getKwDefaults ();
172
170
return createAndCheckArgumentsNode .execute (inliningTarget , callable , userArguments , keywords , signature , null , null , defaults , kwdefaults , false );
@@ -706,11 +704,26 @@ private static void storeKeywordsOrRaise(Object callee, Object[] arguments, PKey
706
704
protected abstract static class SearchNamedParameterNode extends Node {
707
705
public abstract int execute (TruffleString [] parameters , TruffleString name );
708
706
709
- @ Specialization (guards = {"cachedLen == parameters.length" , "cachedLen <= 32" })
707
+ @ Idempotent // I think this is true, I would just like the assertion
708
+ protected static boolean nameIsAtIndex (TruffleString [] parameters , TruffleString name , int index ) {
709
+ return uncached (parameters , name , TruffleString .EqualNode .getUncached ()) == index ;
710
+ }
711
+
712
+ @ SuppressWarnings ("unused" )
713
+ @ Specialization (guards = {"name == cachedName" , "parameters == cachedParameters" , "nameIsAtIndex(cachedParameters, cachedName, index)" }, limit = "1" )
714
+ static int cachedSingle (TruffleString [] parameters , TruffleString name ,
715
+ @ Cached ("name" ) TruffleString cachedName ,
716
+ @ Cached (value = "parameters" , dimensions = 0 ) TruffleString [] cachedParameters ,
717
+ @ Shared @ Cached TruffleString .EqualNode equalNode ,
718
+ @ Cached ("uncached(parameters, name, equalNode)" ) int index ) {
719
+ return index ;
720
+ }
721
+
722
+ @ Specialization (guards = {"cachedLen == parameters.length" , "cachedLen <= 32" }, replaces = "cachedSingle" )
710
723
@ ExplodeLoop
711
- int cached (TruffleString [] parameters , TruffleString name ,
724
+ static int cached (TruffleString [] parameters , TruffleString name ,
712
725
@ Cached ("parameters.length" ) int cachedLen ,
713
- @ Cached TruffleString .EqualNode equalNode ) {
726
+ @ Shared @ Cached TruffleString .EqualNode equalNode ) {
714
727
int idx = -1 ;
715
728
for (int i = 0 ; i < cachedLen ; i ++) {
716
729
if (equalNode .execute (parameters [i ], name , TS_ENCODING )) {
@@ -721,8 +734,8 @@ int cached(TruffleString[] parameters, TruffleString name,
721
734
}
722
735
723
736
@ Specialization (replaces = "cached" )
724
- int uncached (TruffleString [] parameters , TruffleString name ,
725
- @ Cached TruffleString .EqualNode equalNode ) {
737
+ static int uncached (TruffleString [] parameters , TruffleString name ,
738
+ @ Shared @ Cached TruffleString .EqualNode equalNode ) {
726
739
for (int i = 0 ; i < parameters .length ; i ++) {
727
740
if (equalNode .execute (parameters [i ], name , TS_ENCODING )) {
728
741
return i ;
@@ -919,11 +932,34 @@ protected abstract static class FindKwDefaultNode extends Node {
919
932
920
933
public abstract PKeyword execute (PKeyword [] kwdefaults , TruffleString kwname );
921
934
922
- @ Specialization (guards = {"kwdefaults.length == cachedLength" , "cachedLength < 32" })
935
+ @ Idempotent
936
+ protected final boolean isSingleContext () {
937
+ return PythonLanguage .get (this ).isSingleContext ();
938
+ }
939
+
940
+ @ Idempotent // I think this is true, I would just like the assertion
941
+ protected static boolean kwIsCorrect (PKeyword [] kwdefaults , TruffleString kwname , PKeyword result ) {
942
+ return doUncached (kwdefaults , kwname , TruffleString .EqualNode .getUncached ()) == result ;
943
+ }
944
+
945
+ protected static TruffleString .EqualNode getUncachedEqualNode () {
946
+ return TruffleString .EqualNode .getUncached ();
947
+ }
948
+
949
+ @ SuppressWarnings ("unused" )
950
+ @ Specialization (guards = {"kwname == cachedKwName" , "kwdefaults == cachedKwdefaults" , "isSingleContext()" , "kwIsCorrect(cachedKwdefaults, cachedKwName, result)" }, limit = "1" )
951
+ PKeyword cachedSingle (PKeyword [] kwdefaults , TruffleString kwname ,
952
+ @ Cached ("kwname" ) TruffleString cachedKwName ,
953
+ @ Cached (value = "kwdefaults" , weak = true , dimensions = 0 ) PKeyword [] cachedKwdefaults ,
954
+ @ Cached (value = "doUncached(kwdefaults, kwname, getUncachedEqualNode())" , weak = true ) PKeyword result ) {
955
+ return result ;
956
+ }
957
+
958
+ @ Specialization (guards = {"kwdefaults.length == cachedLength" , "cachedLength < 32" }, replaces = "cachedSingle" )
923
959
@ ExplodeLoop (kind = LoopExplosionKind .FULL_UNROLL_UNTIL_RETURN )
924
- PKeyword doCached (PKeyword [] kwdefaults , TruffleString kwname ,
960
+ static PKeyword doCached (PKeyword [] kwdefaults , TruffleString kwname ,
925
961
@ Cached ("kwdefaults.length" ) int cachedLength ,
926
- @ Cached TruffleString .EqualNode equalNode ) {
962
+ @ Shared @ Cached TruffleString .EqualNode equalNode ) {
927
963
for (int j = 0 ; j < cachedLength ; j ++) {
928
964
if (equalNode .execute (kwdefaults [j ].getName (), kwname , TS_ENCODING )) {
929
965
return kwdefaults [j ];
@@ -933,8 +969,8 @@ PKeyword doCached(PKeyword[] kwdefaults, TruffleString kwname,
933
969
}
934
970
935
971
@ Specialization (replaces = "doCached" )
936
- PKeyword doUncached (PKeyword [] kwdefaults , TruffleString kwname ,
937
- @ Cached TruffleString .EqualNode equalNode ) {
972
+ static PKeyword doUncached (PKeyword [] kwdefaults , TruffleString kwname ,
973
+ @ Shared @ Cached TruffleString .EqualNode equalNode ) {
938
974
for (int j = 0 ; j < kwdefaults .length ; j ++) {
939
975
if (equalNode .execute (kwdefaults [j ].getName (), kwname , TS_ENCODING )) {
940
976
return kwdefaults [j ];
0 commit comments