Skip to content

Commit ba8803a

Browse files
committed
Add class profile for storage.
1 parent bd37f63 commit ba8803a

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public abstract static class GetItemNode extends PBaseNode {
160160
@Child private NormalizeIndexNode normalizeIndexNode;
161161
@Child private CastToIndexNode castToIndexNode;
162162

163+
@CompilationFinal private ValueProfile storeProfile;
164+
163165
private final String keyTypeErrorMessage;
164166
private final BiFunction<SequenceStorage, PythonObjectFactory, Object> factoryMethod;
165167

@@ -181,22 +183,22 @@ public GetItemNode(NormalizeIndexNode normalizeIndexNode, String keyTypeErrorMes
181183

182184
@Specialization
183185
protected Object doScalarInt(SequenceStorage storage, int idx) {
184-
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage.length()));
186+
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage));
185187
}
186188

187189
@Specialization
188190
protected Object doScalarLong(SequenceStorage storage, long idx) {
189-
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage.length()));
191+
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage));
190192
}
191193

192194
@Specialization
193195
protected Object doScalarPInt(SequenceStorage storage, PInt idx) {
194-
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage.length()));
196+
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage));
195197
}
196198

197199
@Specialization(guards = "!isPSlice(idx)")
198200
protected Object doScalarPInt(SequenceStorage storage, Object idx) {
199-
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage.length()));
201+
return getGetItemScalarNode().execute(storage, normalizeIndex(idx, storage));
200202
}
201203

202204
@Specialization
@@ -242,29 +244,37 @@ private CastToIndexNode getCastToIndexNode() {
242244
return castToIndexNode;
243245
}
244246

245-
private int normalizeIndex(Object idx, int length) {
247+
private int normalizeIndex(Object idx, SequenceStorage store) {
246248
int intIdx = getCastToIndexNode().execute(idx);
247249
if (normalizeIndexNode != null) {
248-
return normalizeIndexNode.doInt(intIdx, length);
250+
return normalizeIndexNode.doInt(intIdx, getStoreProfile().profile(store).length());
249251
}
250252
return intIdx;
251253
}
252254

253-
private int normalizeIndex(int idx, int length) {
255+
private int normalizeIndex(int idx, SequenceStorage store) {
254256
if (normalizeIndexNode != null) {
255-
return normalizeIndexNode.doInt(idx, length);
257+
return normalizeIndexNode.doInt(idx, getStoreProfile().profile(store).length());
256258
}
257259
return idx;
258260
}
259261

260-
private int normalizeIndex(long idx, int length) {
262+
private int normalizeIndex(long idx, SequenceStorage store) {
261263
int intIdx = getCastToIndexNode().execute(idx);
262264
if (normalizeIndexNode != null) {
263-
return normalizeIndexNode.doInt(intIdx, length);
265+
return normalizeIndexNode.doInt(intIdx, getStoreProfile().profile(store).length());
264266
}
265267
return intIdx;
266268
}
267269

270+
private ValueProfile getStoreProfile() {
271+
if (storeProfile == null) {
272+
CompilerDirectives.transferToInterpreterAndInvalidate();
273+
storeProfile = ValueProfile.createClassProfile();
274+
}
275+
return storeProfile;
276+
}
277+
268278
public static GetItemNode createNotNormalized() {
269279
return GetItemNodeGen.create(null, KEY_TYPE_ERROR_MESSAGE, null);
270280
}

0 commit comments

Comments
 (0)