Skip to content

Commit c7aa987

Browse files
committed
Allow HashingStorageForEachCallback to be inlineable
1 parent 3ff7c6a commit c7aa987

File tree

10 files changed

+74
-52
lines changed

10 files changed

+74
-52
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/objects/ObjectHashMapTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.oracle.graal.python.lib.PyObjectRichCompareBool;
7171
import com.oracle.truffle.api.frame.Frame;
7272
import com.oracle.truffle.api.interop.TruffleObject;
73+
import com.oracle.truffle.api.nodes.Node;
7374
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
7475
import com.oracle.truffle.api.profiles.InlinedCountingConditionProfile;
7576

@@ -296,7 +297,7 @@ static <T> void assertEqual(String message, LinkedHashMap<T, Object> expected, O
296297
int[] size = new int[]{0};
297298
HashingStorageForEachNodeGen.getUncached().execute(null, storage, new HashingStorageForEachCallback<>() {
298299
@Override
299-
public Object execute(Frame frame, HashingStorage s, HashingStorageIterator cbIt, Object accumulator) {
300+
public Object execute(Frame frame, Node inliningTarget, HashingStorage s, HashingStorageIterator cbIt, Object accumulator) {
300301
Object key = HashingStorageIteratorKey.executeUncached(s, cbIt);
301302
assertTrue(key.toString(), expected.containsKey(key));
302303
size[0]++;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextSlotBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@
289289
import com.oracle.truffle.api.interop.UnknownIdentifierException;
290290
import com.oracle.truffle.api.interop.UnsupportedMessageException;
291291
import com.oracle.truffle.api.library.CachedLibrary;
292+
import com.oracle.truffle.api.nodes.Node;
292293
import com.oracle.truffle.api.object.DynamicObjectLibrary;
293294
import com.oracle.truffle.api.profiles.ConditionProfile;
294295
import com.oracle.truffle.api.profiles.ValueProfile;
@@ -1859,10 +1860,10 @@ public abstract static class Py_set_PyTypeObject_tp_subclasses extends CApiBinar
18591860
abstract static class EachSubclassAdd extends HashingStorageForEachCallback<Set<PythonAbstractClass>> {
18601861

18611862
@Override
1862-
public abstract Set<PythonAbstractClass> execute(Frame frame, HashingStorage storage, HashingStorageIterator it, Set<PythonAbstractClass> subclasses);
1863+
public abstract Set<PythonAbstractClass> execute(Frame frame, Node inliningTarget, HashingStorage storage, HashingStorageIterator it, Set<PythonAbstractClass> subclasses);
18631864

18641865
@Specialization
1865-
public Set<PythonAbstractClass> doIt(Frame frame, HashingStorage storage, HashingStorageIterator it, Set<PythonAbstractClass> subclasses,
1866+
public Set<PythonAbstractClass> doIt(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage storage, HashingStorageIterator it, Set<PythonAbstractClass> subclasses,
18661867
@Cached HashingStorageIteratorKey itKey,
18671868
@Cached HashingStorageIteratorKeyHash itKeyHash,
18681869
@Cached HashingStorageGetItemWithHash getItemNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/lzma/LZMANodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -266,10 +266,10 @@ private static int getOptionIndex(TruffleString key, OptionsState s, TruffleStri
266266
}
267267

268268
@Override
269-
public abstract OptionsState execute(Frame frame, HashingStorage storage, HashingStorageIterator it, OptionsState s);
269+
public abstract OptionsState execute(Frame frame, Node inliningTarget, HashingStorage storage, HashingStorageIterator it, OptionsState s);
270270

271271
@Specialization
272-
OptionsState doit(Frame frame, HashingStorage storage, HashingStorageIterator it, OptionsState s,
272+
OptionsState doit(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage storage, HashingStorageIterator it, OptionsState s,
273273
@Cached HashingStorageIteratorKey itKey,
274274
@Cached PyObjectStrAsTruffleStringNode strNode,
275275
@Cached CastToJavaLongLossyNode toLong,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,11 @@ static void doTpAsBuffer(Object object, @SuppressWarnings("unused") PythonNative
14701470
abstract static class EachSubclassAdd extends HashingStorageForEachCallback<Set<PythonAbstractClass>> {
14711471

14721472
@Override
1473-
public abstract Set<PythonAbstractClass> execute(Frame frame, HashingStorage storage, HashingStorageIterator it, Set<PythonAbstractClass> subclasses);
1473+
public abstract Set<PythonAbstractClass> execute(Frame frame, Node inliningTarget, HashingStorage storage, HashingStorageIterator it, Set<PythonAbstractClass> subclasses);
14741474

14751475
@Specialization
1476-
public Set<PythonAbstractClass> doIt(Frame frame, HashingStorage storage, HashingStorageIterator it, Set<PythonAbstractClass> subclasses,
1476+
public Set<PythonAbstractClass> doIt(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage storage, HashingStorageIterator it,
1477+
Set<PythonAbstractClass> subclasses,
14771478
@Cached HashingStorageIteratorKey itKey,
14781479
@Cached HashingStorageIteratorKeyHash itKeyHash,
14791480
@Cached HashingStorageGetItemWithHash getItemNode) {

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

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import com.oracle.truffle.api.dsl.Cached.Exclusive;
6868
import com.oracle.truffle.api.dsl.Cached.Shared;
6969
import com.oracle.truffle.api.dsl.Fallback;
70+
import com.oracle.truffle.api.dsl.GenerateCached;
71+
import com.oracle.truffle.api.dsl.GenerateInline;
7072
import com.oracle.truffle.api.dsl.GenerateUncached;
7173
import com.oracle.truffle.api.dsl.ImportStatic;
7274
import com.oracle.truffle.api.dsl.NeverDefault;
@@ -873,6 +875,7 @@ static Object keywords(KeywordsStorage self, HashingStorageIterator it) {
873875
}
874876
}
875877

878+
// TODO: DSL inlining: inline this other nodes in this file
876879
@GenerateUncached
877880
@ImportStatic({PGuards.class})
878881
public abstract static class HashingStorageIteratorKey extends Node {
@@ -1003,7 +1006,7 @@ public Throwable fillInStackTrace() {
10031006
}
10041007

10051008
public abstract static class HashingStorageForEachCallback<T> extends Node {
1006-
public abstract T execute(Frame frame, HashingStorage storage, HashingStorageIterator it, T accumulator);
1009+
public abstract T execute(Frame frame, Node inliningTarget, HashingStorage storage, HashingStorageIterator it, T accumulator);
10071010
}
10081011

10091012
@GenerateUncached
@@ -1012,13 +1015,19 @@ public abstract static class HashingStorageForEach extends Node {
10121015
@SuppressWarnings("unchecked")
10131016
public final <T> T execute(Frame frame, HashingStorage storage, HashingStorageForEachCallback<T> callback, T accumulator) {
10141017
CompilerAsserts.partialEvaluationConstant(callback);
1015-
return (T) executeUntyped(frame, storage, (HashingStorageForEachCallback<Object>) callback, accumulator);
1018+
return (T) executeUntyped(frame, null, storage, (HashingStorageForEachCallback<Object>) callback, accumulator);
10161019
}
10171020

1018-
abstract Object executeUntyped(Frame frame, HashingStorage storage, HashingStorageForEachCallback<Object> callback, Object accumulator);
1021+
@SuppressWarnings("unchecked")
1022+
public final <T> T execute(Frame frame, Node callbackInliningTarget, HashingStorage storage, HashingStorageForEachCallback<T> callback, T accumulator) {
1023+
CompilerAsserts.partialEvaluationConstant(callback);
1024+
return (T) executeUntyped(frame, callbackInliningTarget, storage, (HashingStorageForEachCallback<Object>) callback, accumulator);
1025+
}
1026+
1027+
abstract Object executeUntyped(Frame frame, Node callbackInliningTarget, HashingStorage storage, HashingStorageForEachCallback<Object> callback, Object accumulator);
10191028

10201029
@Specialization
1021-
static Object doIt(Frame frame, HashingStorage storage, HashingStorageForEachCallback<Object> callback, Object accumulatorIn,
1030+
static Object doIt(Frame frame, Node callbackInliningTarget, HashingStorage storage, HashingStorageForEachCallback<Object> callback, Object accumulatorIn,
10221031
@Cached HashingStorageGetIterator getIter,
10231032
@Cached HashingStorageIteratorNext iterNext,
10241033
@Cached LoopConditionProfile loopProfile) {
@@ -1030,7 +1039,7 @@ static Object doIt(Frame frame, HashingStorage storage, HashingStorageForEachCal
10301039
if (CompilerDirectives.hasNextTier()) {
10311040
index++;
10321041
}
1033-
accumulator = callback.execute(frame, storage, aIter, accumulator);
1042+
accumulator = callback.execute(frame, callbackInliningTarget, storage, aIter, accumulator);
10341043
}
10351044
} finally {
10361045
if (index != 0) {
@@ -1053,19 +1062,21 @@ public ResultAndOther(ObjectHashMap result, HashingStorage other) {
10531062
}
10541063

10551064
@GenerateUncached
1065+
@GenerateInline
1066+
@GenerateCached(false)
10561067
@ImportStatic({PGuards.class})
10571068
public abstract static class HashingStorageXorCallback extends HashingStorageForEachCallback<ResultAndOther> {
10581069

10591070
@Override
1060-
public abstract ResultAndOther execute(Frame frame, HashingStorage storage, HashingStorageIterator it, ResultAndOther accumulator);
1071+
public abstract ResultAndOther execute(Frame frame, Node inliningTarget, HashingStorage storage, HashingStorageIterator it, ResultAndOther accumulator);
10611072

10621073
@Specialization
1063-
static ResultAndOther doGeneric(Frame frame, HashingStorage storage, HashingStorageIterator it, ResultAndOther acc,
1064-
@Cached ObjectHashMap.PutNode putResultNode,
1065-
@Cached HashingStorageGetItemWithHash getFromOther,
1066-
@Cached HashingStorageIteratorKey iterKey,
1067-
@Cached HashingStorageIteratorValue iterValue,
1068-
@Cached HashingStorageIteratorKeyHash iterHash) {
1074+
static ResultAndOther doGeneric(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage storage, HashingStorageIterator it, ResultAndOther acc,
1075+
@Cached(inline = false) ObjectHashMap.PutNode putResultNode,
1076+
@Cached(inline = false) HashingStorageGetItemWithHash getFromOther,
1077+
@Cached(inline = false) HashingStorageIteratorKey iterKey,
1078+
@Cached(inline = false) HashingStorageIteratorValue iterValue,
1079+
@Cached(inline = false) HashingStorageIteratorKeyHash iterHash) {
10691080
Object key = iterKey.execute(storage, it);
10701081
long hash = iterHash.execute(storage, it);
10711082
Object otherValue = getFromOther.execute(frame, acc.other, key, hash);
@@ -1083,6 +1094,7 @@ public abstract static class HashingStorageXor extends Node {
10831094

10841095
@Specialization
10851096
static HashingStorage doIt(Frame frame, HashingStorage aStorage, HashingStorage bStorage,
1097+
@Bind("this") Node inliningTarget,
10861098
@Cached HashingStorageForEach forEachA,
10871099
@Cached HashingStorageForEach forEachB,
10881100
@Cached HashingStorageXorCallback callbackA,
@@ -1091,28 +1103,30 @@ static HashingStorage doIt(Frame frame, HashingStorage aStorage, HashingStorage
10911103
ObjectHashMap resultMap = result.map;
10921104

10931105
ResultAndOther accA = new ResultAndOther(resultMap, bStorage);
1094-
forEachA.execute(frame, aStorage, callbackA, accA);
1106+
forEachA.execute(frame, inliningTarget, aStorage, callbackA, accA);
10951107

10961108
ResultAndOther accB = new ResultAndOther(resultMap, aStorage);
1097-
forEachB.execute(frame, bStorage, callbackB, accB);
1109+
forEachB.execute(frame, inliningTarget, bStorage, callbackB, accB);
10981110

10991111
return result;
11001112
}
11011113
}
11021114

11031115
@GenerateUncached
1116+
@GenerateInline
1117+
@GenerateCached(false)
11041118
@ImportStatic({PGuards.class})
11051119
public abstract static class HashingStorageIntersectCallback extends HashingStorageForEachCallback<ResultAndOther> {
11061120

11071121
@Override
1108-
public abstract ResultAndOther execute(Frame frame, HashingStorage storage, HashingStorageIterator it, ResultAndOther accumulator);
1122+
public abstract ResultAndOther execute(Frame frame, Node inliningTarget, HashingStorage storage, HashingStorageIterator it, ResultAndOther accumulator);
11091123

11101124
@Specialization
11111125
static ResultAndOther doGeneric(Frame frame, HashingStorage storage, HashingStorageIterator it, ResultAndOther acc,
1112-
@Cached ObjectHashMap.PutNode putResultNode,
1113-
@Cached HashingStorageGetItemWithHash getFromOther,
1114-
@Cached HashingStorageIteratorKey iterKey,
1115-
@Cached HashingStorageIteratorKeyHash iterHash) {
1126+
@Cached(inline = false) ObjectHashMap.PutNode putResultNode,
1127+
@Cached(inline = false) HashingStorageGetItemWithHash getFromOther,
1128+
@Cached(inline = false) HashingStorageIteratorKey iterKey,
1129+
@Cached(inline = false) HashingStorageIteratorKeyHash iterHash) {
11161130
Object key = iterKey.execute(storage, it);
11171131
long hash = iterHash.execute(storage, it);
11181132
Object otherValue = getFromOther.execute(frame, acc.other, key, hash);
@@ -1133,11 +1147,12 @@ public abstract static class HashingStorageIntersect extends Node {
11331147

11341148
@Specialization
11351149
static HashingStorage doIt(Frame frame, HashingStorage aStorage, HashingStorage bStorage,
1150+
@Bind("this") Node inliningTarget,
11361151
@Cached HashingStorageForEach forEachA,
11371152
@Cached HashingStorageIntersectCallback callback) {
11381153
final EconomicMapStorage result = EconomicMapStorage.createWithSideEffects();
11391154
ResultAndOther acc = new ResultAndOther(result.map, bStorage);
1140-
forEachA.execute(frame, aStorage, callback, acc);
1155+
forEachA.execute(frame, inliningTarget, aStorage, callback, acc);
11411156
return result;
11421157
}
11431158
}
@@ -1147,10 +1162,10 @@ static HashingStorage doIt(Frame frame, HashingStorage aStorage, HashingStorage
11471162
public abstract static class HashingStorageDiffCallback extends HashingStorageForEachCallback<ResultAndOther> {
11481163

11491164
@Override
1150-
public abstract ResultAndOther execute(Frame frame, HashingStorage storage, HashingStorageIterator it, ResultAndOther accumulator);
1165+
public abstract ResultAndOther execute(Frame frame, Node inliningTarget, HashingStorage storage, HashingStorageIterator it, ResultAndOther accumulator);
11511166

11521167
@Specialization
1153-
static ResultAndOther doGeneric(Frame frame, HashingStorage storage, HashingStorageIterator it, ResultAndOther acc,
1168+
static ResultAndOther doGeneric(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage storage, HashingStorageIterator it, ResultAndOther acc,
11541169
@Cached ObjectHashMap.PutNode putResultNode,
11551170
@Cached HashingStorageGetItemWithHash getFromOther,
11561171
@Cached HashingStorageIteratorKey iterKey,
@@ -1193,10 +1208,10 @@ static HashingStorage doIt(Frame frame, HashingStorage aStorage, HashingStorage
11931208
public abstract static class HashingStorageCompareKeysCallback extends HashingStorageForEachCallback<HashingStorage> {
11941209

11951210
@Override
1196-
public abstract HashingStorage execute(Frame frame, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage);
1211+
public abstract HashingStorage execute(Frame frame, Node inliningTarget, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage);
11971212

11981213
@Specialization
1199-
static HashingStorage doGeneric(Frame frame, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage,
1214+
static HashingStorage doGeneric(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage,
12001215
@Cached HashingStorageGetItemWithHash getFromOther,
12011216
@Cached HashingStorageIteratorKey iterKey,
12021217
@Cached HashingStorageIteratorKeyHash iterHash) {
@@ -1253,10 +1268,10 @@ static int doGeneric(Frame frame, HashingStorage aStorage, HashingStorage bStora
12531268
public abstract static class HashingStorageAreDisjointCallback extends HashingStorageForEachCallback<HashingStorage> {
12541269

12551270
@Override
1256-
public abstract HashingStorage execute(Frame frame, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage);
1271+
public abstract HashingStorage execute(Frame frame, Node inliningTarget, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage);
12571272

12581273
@Specialization
1259-
static HashingStorage doGeneric(Frame frame, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage,
1274+
static HashingStorage doGeneric(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage,
12601275
@Cached HashingStorageGetItemWithHash getFromOther,
12611276
@Cached HashingStorageIteratorKey iterKey,
12621277
@Cached HashingStorageIteratorKeyHash iterHash) {
@@ -1299,18 +1314,18 @@ static boolean doGeneric(Frame frame, HashingStorage aStorage, HashingStorage bS
12991314
@GenerateUncached
13001315
public abstract static class HashingStorageTransferItem extends HashingStorageForEachCallback<HashingStorage> {
13011316
@Override
1302-
public abstract HashingStorage execute(Frame frame, HashingStorage src, HashingStorageIterator it, HashingStorage destStorage);
1317+
public abstract HashingStorage execute(Frame frame, Node inliningTarget, HashingStorage src, HashingStorageIterator it, HashingStorage destStorage);
13031318

13041319
@Specialization
1305-
static EconomicMapStorage economic2Economic(Frame frame, EconomicMapStorage src, HashingStorageIterator it, EconomicMapStorage destStorage,
1320+
static EconomicMapStorage economic2Economic(Frame frame, @SuppressWarnings("unused") Node inliningTarget, EconomicMapStorage src, HashingStorageIterator it, EconomicMapStorage destStorage,
13061321
@Cached PutNode putNode) {
13071322
ObjectHashMap srcMap = src.map;
13081323
putNode.put(frame, destStorage.map, srcMap.getKey(it.index), srcMap.hashes[it.index], srcMap.getValue(it.index));
13091324
return destStorage;
13101325
}
13111326

13121327
@Specialization(replaces = "economic2Economic")
1313-
static HashingStorage economic2Generic(Frame frame, EconomicMapStorage src, HashingStorageIterator it, HashingStorage destStorage,
1328+
static HashingStorage economic2Generic(Frame frame, @SuppressWarnings("unused") Node inliningTarget, EconomicMapStorage src, HashingStorageIterator it, HashingStorage destStorage,
13141329
@Cached HashingStorageSetItemWithHash setItemWithHash) {
13151330
// Note that the point is to avoid side-effecting __hash__ call. Since the source is
13161331
// economic map, the key may be an arbitrary object.
@@ -1319,7 +1334,7 @@ static HashingStorage economic2Generic(Frame frame, EconomicMapStorage src, Hash
13191334
}
13201335

13211336
@Fallback
1322-
static HashingStorage generic2Generic(Frame frame, HashingStorage src, HashingStorageIterator it, HashingStorage destStorage,
1337+
static HashingStorage generic2Generic(Frame frame, @SuppressWarnings("unused") Node inliningTarget, HashingStorage src, HashingStorageIterator it, HashingStorage destStorage,
13231338
@Cached HashingStorageIteratorKey iterKey,
13241339
@Cached HashingStorageIteratorValue iterValue,
13251340
@Cached HashingStorageSetItem setItem) {

0 commit comments

Comments
 (0)