67
67
import com .oracle .truffle .api .library .LibraryFactory ;
68
68
import com .oracle .truffle .api .nodes .Node ;
69
69
import com .oracle .truffle .api .nodes .NodeCost ;
70
- import com .oracle .truffle .api .profiles .BranchProfile ;
71
70
72
71
/**
73
72
* The standard Python object library. This implements a general-purpose Python object interface.
@@ -249,14 +248,18 @@ public final long hash(double receiver) {
249
248
}
250
249
251
250
private static class DefaultNodes extends Node {
251
+ private static final byte REVERSE_COMP = 0b001;
252
+ private static final byte LEFT_COMPARE = 0b010;
253
+ private static final byte SUBT_COMPARE = 0b100;
254
+
252
255
@ Child private IsSubtypeNode isSubtype ;
253
256
@ Child private IsSameTypeNode isSameType ;
254
- @ CompilationFinal private BranchProfile reverseEquals ;
255
- @ CompilationFinal private BranchProfile subtypeEquals ;
257
+ @ CompilationFinal byte state = 0 ;
256
258
257
259
protected IsSubtypeNode getIsSubtypeNode () {
258
260
if (isSubtype == null ) {
259
261
CompilerDirectives .transferToInterpreterAndInvalidate ();
262
+ reportPolymorphicSpecialize ();
260
263
isSubtype = insert (IsSubtypeNode .create ());
261
264
}
262
265
return isSubtype ;
@@ -270,20 +273,28 @@ protected IsSameTypeNode getIsSameTypeNode() {
270
273
return isSameType ;
271
274
}
272
275
273
- protected BranchProfile getReverseProfile () {
274
- if (reverseEquals == null ) {
276
+ protected void enterReverseCompare () {
277
+ if ((state & REVERSE_COMP ) == 0 ) {
278
+ CompilerDirectives .transferToInterpreterAndInvalidate ();
279
+ reportPolymorphicSpecialize ();
280
+ state |= REVERSE_COMP ;
281
+ }
282
+ }
283
+
284
+ protected void enterLeftCompare () {
285
+ if ((state & LEFT_COMPARE ) == 0 ) {
275
286
CompilerDirectives .transferToInterpreterAndInvalidate ();
276
- reverseEquals = BranchProfile .create ();
287
+ reportPolymorphicSpecialize ();
288
+ state |= LEFT_COMPARE ;
277
289
}
278
- return reverseEquals ;
279
290
}
280
291
281
- protected BranchProfile getSubtypeProfile () {
282
- if (subtypeEquals == null ) {
292
+ protected void enterSubtypeCompare () {
293
+ if (( state & SUBT_COMPARE ) == 0 ) {
283
294
CompilerDirectives .transferToInterpreterAndInvalidate ();
284
- subtypeEquals = BranchProfile .create ();
295
+ reportPolymorphicSpecialize ();
296
+ state |= SUBT_COMPARE ;
285
297
}
286
- return subtypeEquals ;
287
298
}
288
299
289
300
private static final class Disabled extends DefaultNodes {
@@ -300,13 +311,15 @@ protected IsSameTypeNode getIsSameTypeNode() {
300
311
}
301
312
302
313
@ Override
303
- protected BranchProfile getReverseProfile () {
304
- return BranchProfile .getUncached ();
314
+ protected void enterReverseCompare () {
305
315
}
306
316
307
317
@ Override
308
- protected BranchProfile getSubtypeProfile () {
309
- return BranchProfile .getUncached ();
318
+ protected void enterLeftCompare () {
319
+ }
320
+
321
+ @ Override
322
+ protected void enterSubtypeCompare () {
310
323
}
311
324
}
312
325
@@ -365,20 +378,20 @@ public boolean equalsWithState(Object receiver, Object other, PythonObjectLibrar
365
378
int result ;
366
379
boolean isSameType = getDefaultNodes ().getIsSameTypeNode ().execute (leftClass , rightClass );
367
380
if (!isSameType && getDefaultNodes ().getIsSubtypeNode ().execute (rightClass , leftClass )) {
368
- getDefaultNodes ().getSubtypeProfile (). enter ();
381
+ getDefaultNodes ().enterSubtypeCompare ();
369
382
checkedReverseOp = true ;
370
383
result = otherLibrary .equalsInternal (other , receiver , threadState );
371
384
if (result != -1 ) {
372
385
return result == 1 ;
373
386
}
374
387
}
375
-
388
+ getDefaultNodes (). enterLeftCompare ();
376
389
result = equalsInternal (receiver , other , threadState );
377
390
if (result != -1 ) {
378
391
return result == 1 ;
379
392
}
380
393
if (!isSameType && !checkedReverseOp ) {
381
- getDefaultNodes ().getReverseProfile (). enter ();
394
+ getDefaultNodes ().enterReverseCompare ();
382
395
result = otherLibrary .equalsInternal (other , receiver , threadState );
383
396
}
384
397
0 commit comments