Skip to content

Commit 7921c16

Browse files
committed
attempt to improve inlining through PyObjectGetItem
1 parent 69cb277 commit 7921c16

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
import com.oracle.truffle.api.CompilerDirectives;
157157
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
158158
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
159+
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
159160
import com.oracle.truffle.api.dsl.Bind;
160161
import com.oracle.truffle.api.dsl.Cached;
161162
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -312,30 +313,37 @@ protected static boolean isEmpty(LenNode lenNode, SequenceStorage left) {
312313
return lenNode.execute(left) == 0;
313314
}
314315

316+
@InliningCutoff
315317
protected static boolean isBoolean(GetElementType getElementTypeNode, SequenceStorage s) {
316318
return getElementTypeNode.execute(s) == ListStorageType.Boolean;
317319
}
318320

321+
@InliningCutoff
319322
protected static boolean isByte(GetElementType getElementTypeNode, SequenceStorage s) {
320323
return getElementTypeNode.execute(s) == ListStorageType.Byte;
321324
}
322325

326+
@InliningCutoff
323327
protected static boolean isByteLike(GetElementType getElementTypeNode, SequenceStorage s) {
324328
return isByte(getElementTypeNode, s) || isInt(getElementTypeNode, s) || isLong(getElementTypeNode, s);
325329
}
326330

331+
@InliningCutoff
327332
protected static boolean isInt(GetElementType getElementTypeNode, SequenceStorage s) {
328333
return getElementTypeNode.execute(s) == ListStorageType.Int;
329334
}
330335

336+
@InliningCutoff
331337
protected static boolean isLong(GetElementType getElementTypeNode, SequenceStorage s) {
332338
return getElementTypeNode.execute(s) == ListStorageType.Long;
333339
}
334340

341+
@InliningCutoff
335342
protected static boolean isDouble(GetElementType getElementTypeNode, SequenceStorage s) {
336343
return getElementTypeNode.execute(s) == ListStorageType.Double;
337344
}
338345

346+
@InliningCutoff
339347
protected static boolean isObject(GetElementType getElementTypeNode, SequenceStorage s) {
340348
return getElementTypeNode.execute(s) == ListStorageType.Generic;
341349
}
@@ -462,16 +470,19 @@ protected Object doScalarLong(VirtualFrame frame, SequenceStorage storage, long
462470
return getGetItemScalarNode().execute(storage, normalizeIndex(frame, idx, storage));
463471
}
464472

473+
@InliningCutoff
465474
@Specialization
466475
protected Object doScalarPInt(VirtualFrame frame, SequenceStorage storage, PInt idx) {
467476
return getGetItemScalarNode().execute(storage, normalizeIndex(frame, idx, storage));
468477
}
469478

479+
@InliningCutoff
470480
@Specialization(guards = "!isPSlice(idx)")
471481
protected Object doScalarGeneric(VirtualFrame frame, SequenceStorage storage, Object idx) {
472482
return getGetItemScalarNode().execute(storage, normalizeIndex(frame, idx, storage));
473483
}
474484

485+
@InliningCutoff
475486
@Specialization
476487
protected Object doSlice(VirtualFrame frame, SequenceStorage storage, PSlice slice,
477488
@Cached LenNode lenNode,
@@ -682,6 +693,7 @@ protected static Object doMro(MroSequenceStorage storage, int idx) {
682693
return storage.getItemNormalized(idx);
683694
}
684695

696+
@InliningCutoff
685697
@Specialization(guards = "isObject(getElementType, storage)", limit = "1")
686698
protected static Object doNativeObject(NativeSequenceStorage storage, int idx,
687699
@CachedLibrary("storage.getPtr()") InteropLibrary lib,
@@ -700,6 +712,7 @@ protected static Object doNativeObject(NativeSequenceStorage storage, int idx,
700712
}
701713
}
702714

715+
@InliningCutoff
703716
@Specialization(guards = "isByteStorage(storage)", limit = "1")
704717
protected static int doNativeByte(NativeSequenceStorage storage, int idx,
705718
@CachedLibrary("storage.getPtr()") InteropLibrary lib,
@@ -711,6 +724,7 @@ protected static int doNativeByte(NativeSequenceStorage storage, int idx,
711724
return (byte) result & 0xFF;
712725
}
713726

727+
@InliningCutoff
714728
@Specialization(guards = {"!isByteStorage(storage)", "!isObject(getElementType, storage)"}, limit = "1")
715729
protected static Object doNative(NativeSequenceStorage storage, int idx,
716730
@CachedLibrary("storage.getPtr()") InteropLibrary lib,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorageFactory;
124124
import com.oracle.truffle.api.CompilerDirectives;
125125
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
126+
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
126127
import com.oracle.truffle.api.dsl.Cached;
127128
import com.oracle.truffle.api.dsl.Cached.Shared;
128129
import com.oracle.truffle.api.dsl.Fallback;
@@ -339,13 +340,21 @@ protected Object doGeneric(Object self, @SuppressWarnings("unused") Object objec
339340
@GenerateNodeFactory
340341
public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
341342

343+
@Specialization(guards = {"index >= 0", "index < self.getSequenceStorage().length()"})
344+
protected Object doInBounds(PList self, int index,
345+
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
346+
return getItemNode.execute(self.getSequenceStorage(), index);
347+
}
348+
349+
@InliningCutoff
342350
@Specialization(guards = "indexCheckNode.execute(key) || isPSlice(key)", limit = "1")
343351
protected Object doScalar(VirtualFrame frame, PList self, Object key,
344352
@SuppressWarnings("unused") @Cached PyIndexCheckNode indexCheckNode,
345353
@Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
346354
return getItemNode.execute(frame, self.getSequenceStorage(), key);
347355
}
348356

357+
@InliningCutoff
349358
@SuppressWarnings("unused")
350359
@Fallback
351360
public Object doListError(VirtualFrame frame, Object self, Object key) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import com.oracle.graal.python.runtime.sequence.storage.LongSequenceStorage;
101101
import com.oracle.graal.python.runtime.sequence.storage.ObjectSequenceStorage;
102102
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
103+
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
103104
import com.oracle.truffle.api.dsl.Cached;
104105
import com.oracle.truffle.api.dsl.Fallback;
105106
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -260,18 +261,27 @@ public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
260261

261262
public abstract Object execute(VirtualFrame frame, PTuple tuple, Object index);
262263

264+
@Specialization(guards = {"index >= 0", "index < tuple.getSequenceStorage().length()"})
265+
protected Object doInBounds(PTuple tuple, int index,
266+
@Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
267+
return getItemNode.execute(tuple.getSequenceStorage(), index);
268+
}
269+
270+
@InliningCutoff
263271
@Specialization(guards = "!isPSlice(key)")
264272
Object doPTuple(VirtualFrame frame, PTuple tuple, Object key,
265273
@Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
266274
return getItemNode.execute(frame, tuple.getSequenceStorage(), key);
267275
}
268276

277+
@InliningCutoff
269278
@Specialization
270279
Object doPTuple(VirtualFrame frame, PTuple tuple, PSlice key,
271280
@Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
272281
return getItemNode.execute(frame, tuple.getSequenceStorage(), key);
273282
}
274283

284+
@InliningCutoff
275285
@Specialization
276286
Object doNative(PythonNativeObject tuple, long key,
277287
@Cached PCallCapiFunction callSetItem,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyIndexCheckNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.graal.python.nodes.PNodeWithContext;
4848
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
4949
import com.oracle.graal.python.nodes.object.GetClassNode;
50+
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
5051
import com.oracle.truffle.api.dsl.Cached;
5152
import com.oracle.truffle.api.dsl.GenerateUncached;
5253
import com.oracle.truffle.api.dsl.ImportStatic;
@@ -76,6 +77,7 @@ static boolean doString(@SuppressWarnings("unused") TruffleString object) {
7677
return false;
7778
}
7879

80+
@InliningCutoff
7981
@Specialization
8082
static boolean doPythonObject(PythonAbstractObject object,
8183
@Cached GetClassNode getClassNode,
@@ -103,6 +105,7 @@ static boolean doPBCT(@SuppressWarnings("unused") PythonBuiltinClassType object)
103105
return false;
104106
}
105107

108+
@InliningCutoff
106109
@Specialization(replaces = "doPythonObject")
107110
static boolean doGeneric(Object object,
108111
@CachedLibrary(limit = "3") InteropLibrary interopLibrary,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyObjectGetItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Object doTuple(VirtualFrame frame, PTuple object, Object key,
8787
return getItemNode.execute(frame, object, key);
8888
}
8989

90+
@InliningCutoff // TODO: inline this probably?
9091
@Specialization(guards = "cannotBeOverridden(object, getClassNode)", limit = "1")
9192
Object doDict(VirtualFrame frame, PDict object, Object key,
9293
@SuppressWarnings("unused") @Shared("getClass") @Cached GetClassNode getClassNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/object/GetClassNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.graal.python.nodes.PNodeWithContext;
6060
import com.oracle.graal.python.nodes.truffle.PythonTypes;
6161
import com.oracle.graal.python.runtime.exception.PException;
62+
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
6263
import com.oracle.truffle.api.dsl.Bind;
6364
import com.oracle.truffle.api.dsl.Cached;
6465
import com.oracle.truffle.api.dsl.Fallback;
@@ -156,12 +157,14 @@ static Object getPythonObject(@SuppressWarnings("unused") PythonObject object,
156157
return klass;
157158
}
158159

160+
@InliningCutoff
159161
@Specialization(guards = "!hasInitialClass(object.getShape())", replaces = "getPythonObjectConstantClass")
160162
static Object getPythonObject(PythonObject object,
161163
@CachedLibrary(limit = "4") DynamicObjectLibrary dylib) {
162164
return dylib.getOrDefault(object, CLASS, object.getInitialPythonClass());
163165
}
164166

167+
@InliningCutoff
165168
@Specialization
166169
static Object getNativeObject(PythonAbstractNativeObject object,
167170
@Cached CExtNodes.GetNativeClassNode getNativeClassNode) {

0 commit comments

Comments
 (0)