57
57
import com .oracle .truffle .api .CompilerDirectives ;
58
58
import com .oracle .truffle .api .dsl .Bind ;
59
59
import com .oracle .truffle .api .dsl .Cached ;
60
+ import com .oracle .truffle .api .dsl .Cached .Shared ;
60
61
import com .oracle .truffle .api .dsl .CachedContext ;
61
62
import com .oracle .truffle .api .dsl .GenerateUncached ;
62
63
import com .oracle .truffle .api .dsl .Specialization ;
@@ -67,26 +68,44 @@ abstract class PGetDynamicTypeNode extends PNodeWithContext {
67
68
68
69
public abstract Object execute (PythonNativeWrapper obj );
69
70
70
- @ Specialization (guards = "obj.isIntLike()" )
71
- Object doIntLike (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
71
+ @ Specialization (guards = "obj.isIntLike()" , assumptions = "singleContextAssumption()" )
72
+ static Object doIntLikeSingleContext (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
72
73
@ Cached (value = "getLongobjectType()" , allowUncached = true ) Object cachedSulongType ) {
73
74
return cachedSulongType ;
74
75
}
75
76
76
- @ Specialization (guards = "obj.isBool()" )
77
- Object doBool (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
77
+ @ Specialization (guards = "obj.isBool()" , assumptions = "singleContextAssumption()" )
78
+ static Object doBoolSingleContext (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
78
79
@ Cached (value = "getBoolobjectType()" , allowUncached = true ) Object cachedSulongType ) {
79
80
return cachedSulongType ;
80
81
}
81
82
82
- @ Specialization (guards = "obj.isDouble()" )
83
- Object doDouble (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
83
+ @ Specialization (guards = "obj.isDouble()" , assumptions = "singleContextAssumption()" )
84
+ static Object doDoubleSingleContext (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
84
85
@ Cached (value = "getFloatobjectType()" , allowUncached = true ) Object cachedSulongType ) {
85
86
return cachedSulongType ;
86
87
}
87
88
88
- @ Specialization
89
- Object doGeneric (PythonNativeWrapper obj ,
89
+ @ Specialization (guards = "obj.isIntLike()" )
90
+ static Object doIntLike (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
91
+ @ Shared ("getSulongTypeNode" ) @ Cached GetSulongTypeNode getSulongTypeNode ) {
92
+ return getSulongTypeNode .execute (PythonBuiltinClassType .PInt );
93
+ }
94
+
95
+ @ Specialization (guards = "obj.isBool()" )
96
+ static Object doBool (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
97
+ @ Shared ("getSulongTypeNode" ) @ Cached GetSulongTypeNode getSulongTypeNode ) {
98
+ return getSulongTypeNode .execute (PythonBuiltinClassType .Boolean );
99
+ }
100
+
101
+ @ Specialization (guards = "obj.isDouble()" )
102
+ static Object doDouble (@ SuppressWarnings ("unused" ) DynamicObjectNativeWrapper .PrimitiveNativeWrapper obj ,
103
+ @ Shared ("getSulongTypeNode" ) @ Cached GetSulongTypeNode getSulongTypeNode ) {
104
+ return getSulongTypeNode .execute (PythonBuiltinClassType .PFloat );
105
+ }
106
+
107
+ @ Specialization (replaces = {"doIntLike" , "doBool" , "doDouble" })
108
+ static Object doGeneric (PythonNativeWrapper obj ,
90
109
@ Cached GetSulongTypeNode getSulongTypeNode ,
91
110
@ Cached AsPythonObjectNode getDelegate ,
92
111
@ Cached GetClassNode getClassNode ) {
@@ -111,14 +130,21 @@ abstract static class GetSulongTypeNode extends PNodeWithContext {
111
130
public abstract Object execute (Object clazz );
112
131
113
132
@ Specialization (guards = "clazz == cachedClass" , limit = "10" , assumptions = "singleContextAssumption()" )
114
- static Object doBuiltinCached (@ SuppressWarnings ("unused" ) PythonBuiltinClassType clazz ,
133
+ static Object doBuiltinCachedResult (@ SuppressWarnings ("unused" ) PythonBuiltinClassType clazz ,
115
134
@ Cached ("clazz" ) @ SuppressWarnings ("unused" ) PythonBuiltinClassType cachedClass ,
116
135
@ CachedContext (PythonLanguage .class ) @ SuppressWarnings ("unused" ) PythonContext context ,
117
136
@ Cached ("getLLVMTypeForBuiltinClass(clazz, context)" ) Object llvmType ) {
118
137
return llvmType ;
119
138
}
120
139
121
- @ Specialization (replaces = "doBuiltinCached" )
140
+ @ Specialization (guards = "clazz == cachedClass" , limit = "1" )
141
+ static Object doBuiltinCached (@ SuppressWarnings ("unused" ) PythonBuiltinClassType clazz ,
142
+ @ Cached ("clazz" ) @ SuppressWarnings ("unused" ) PythonBuiltinClassType cachedClass ,
143
+ @ CachedContext (PythonLanguage .class ) @ SuppressWarnings ("unused" ) PythonContext context ) {
144
+ return getLLVMTypeForBuiltinClass (cachedClass , context );
145
+ }
146
+
147
+ @ Specialization (replaces = {"doBuiltinCachedResult" , "doBuiltinCached" })
122
148
static Object doBuiltinGeneric (PythonBuiltinClassType clazz ,
123
149
@ CachedContext (PythonLanguage .class ) PythonContext context ) {
124
150
return getLLVMTypeForBuiltinClass (clazz , context );
0 commit comments