Skip to content

Commit 26ad86e

Browse files
committed
split GetItemScalarNode into managed and native parts to aid inlining
1 parent f355052 commit 26ad86e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/SequenceStorageNodes.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ abstract static class SequenceStorageBaseNode extends PNodeWithContext {
279279
protected static final int MAX_SEQUENCE_STORAGES = 9;
280280
protected static final int MAX_ARRAY_STORAGES = 7;
281281

282+
@InliningCutoff
282283
protected static boolean isByteStorage(NativeSequenceStorage store) {
283284
return store.getElementType() == ListStorageType.Byte;
284285
}
@@ -694,6 +695,18 @@ protected static Object doMro(MroSequenceStorage storage, int idx) {
694695
}
695696

696697
@InliningCutoff
698+
@Specialization
699+
protected static Object doNative(NativeSequenceStorage storage, int idx,
700+
@Cached GetNativeItemScalarNode getItem) {
701+
return getItem.execute(storage, idx);
702+
}
703+
}
704+
705+
@GenerateUncached
706+
@ImportStatic(SequenceStorageBaseNode.class)
707+
protected abstract static class GetNativeItemScalarNode extends Node {
708+
public abstract Object execute(NativeSequenceStorage s, int idx);
709+
697710
@Specialization(guards = "isObject(getElementType, storage)", limit = "1")
698711
protected static Object doNativeObject(NativeSequenceStorage storage, int idx,
699712
@CachedLibrary("storage.getPtr()") InteropLibrary lib,
@@ -712,7 +725,6 @@ protected static Object doNativeObject(NativeSequenceStorage storage, int idx,
712725
}
713726
}
714727

715-
@InliningCutoff
716728
@Specialization(guards = "isByteStorage(storage)", limit = "1")
717729
protected static int doNativeByte(NativeSequenceStorage storage, int idx,
718730
@CachedLibrary("storage.getPtr()") InteropLibrary lib,
@@ -724,7 +736,6 @@ protected static int doNativeByte(NativeSequenceStorage storage, int idx,
724736
return (byte) result & 0xFF;
725737
}
726738

727-
@InliningCutoff
728739
@Specialization(guards = {"!isByteStorage(storage)", "!isObject(getElementType, storage)"}, limit = "1")
729740
protected static Object doNative(NativeSequenceStorage storage, int idx,
730741
@CachedLibrary("storage.getPtr()") InteropLibrary lib,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/ListBuiltins.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ protected Object doInBounds(PList self, int index,
347347
}
348348

349349
@InliningCutoff
350-
@Specialization(guards = "indexCheckNode.execute(key) || isPSlice(key)", limit = "1")
350+
@Specialization(guards = "isIndexOrSlice(indexCheckNode, key)", limit = "1")
351351
protected Object doScalar(VirtualFrame frame, PList self, Object key,
352352
@SuppressWarnings("unused") @Cached PyIndexCheckNode indexCheckNode,
353353
@Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
@@ -356,11 +356,17 @@ protected Object doScalar(VirtualFrame frame, PList self, Object key,
356356

357357
@InliningCutoff
358358
@SuppressWarnings("unused")
359-
@Fallback
360-
public Object doListError(VirtualFrame frame, Object self, Object key) {
359+
@Specialization(guards = "!isIndexOrSlice(indexCheckNode, key)")
360+
public Object doListError(VirtualFrame frame, Object self, Object key,
361+
@SuppressWarnings("unused") @Cached PyIndexCheckNode indexCheckNode) {
361362
throw raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "list", key);
362363
}
363364

365+
@InliningCutoff
366+
protected static boolean isIndexOrSlice(PyIndexCheckNode indexCheckNode, Object key) {
367+
return indexCheckNode.execute(key) || PGuards.isPSlice(key);
368+
}
369+
364370
protected static SequenceStorageNodes.GetItemNode createGetItemNode() {
365371
return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forList(), (s, f) -> f.createList(s));
366372
}

0 commit comments

Comments
 (0)