Skip to content

Commit fe6ca92

Browse files
committed
Improve getNativeType for built-in types in multi-context
1 parent fbe023e commit fe6ca92

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/PGetDynamicTypeNode.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import com.oracle.truffle.api.CompilerDirectives;
5858
import com.oracle.truffle.api.dsl.Bind;
5959
import com.oracle.truffle.api.dsl.Cached;
60+
import com.oracle.truffle.api.dsl.Cached.Shared;
6061
import com.oracle.truffle.api.dsl.CachedContext;
6162
import com.oracle.truffle.api.dsl.GenerateUncached;
6263
import com.oracle.truffle.api.dsl.Specialization;
@@ -67,26 +68,44 @@ abstract class PGetDynamicTypeNode extends PNodeWithContext {
6768

6869
public abstract Object execute(PythonNativeWrapper obj);
6970

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,
7273
@Cached(value = "getLongobjectType()", allowUncached = true) Object cachedSulongType) {
7374
return cachedSulongType;
7475
}
7576

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,
7879
@Cached(value = "getBoolobjectType()", allowUncached = true) Object cachedSulongType) {
7980
return cachedSulongType;
8081
}
8182

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,
8485
@Cached(value = "getFloatobjectType()", allowUncached = true) Object cachedSulongType) {
8586
return cachedSulongType;
8687
}
8788

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,
90109
@Cached GetSulongTypeNode getSulongTypeNode,
91110
@Cached AsPythonObjectNode getDelegate,
92111
@Cached GetClassNode getClassNode) {
@@ -111,14 +130,21 @@ abstract static class GetSulongTypeNode extends PNodeWithContext {
111130
public abstract Object execute(Object clazz);
112131

113132
@Specialization(guards = "clazz == cachedClass", limit = "10", assumptions = "singleContextAssumption()")
114-
static Object doBuiltinCached(@SuppressWarnings("unused") PythonBuiltinClassType clazz,
133+
static Object doBuiltinCachedResult(@SuppressWarnings("unused") PythonBuiltinClassType clazz,
115134
@Cached("clazz") @SuppressWarnings("unused") PythonBuiltinClassType cachedClass,
116135
@CachedContext(PythonLanguage.class) @SuppressWarnings("unused") PythonContext context,
117136
@Cached("getLLVMTypeForBuiltinClass(clazz, context)") Object llvmType) {
118137
return llvmType;
119138
}
120139

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"})
122148
static Object doBuiltinGeneric(PythonBuiltinClassType clazz,
123149
@CachedContext(PythonLanguage.class) PythonContext context) {
124150
return getLLVMTypeForBuiltinClass(clazz, context);

0 commit comments

Comments
 (0)