|
142 | 142 | import com.oracle.graal.python.nodes.SpecialAttributeNames;
|
143 | 143 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
144 | 144 | import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
|
145 |
| -import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode; |
146 | 145 | import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
|
| 146 | +import com.oracle.graal.python.nodes.attributes.WriteAttributeToPythonObjectNode; |
147 | 147 | import com.oracle.graal.python.nodes.call.CallNode;
|
148 | 148 | import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode.LookupAndCallUnaryDynamicNode;
|
149 | 149 | import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
|
@@ -582,42 +582,49 @@ public abstract static class PointerCompareNode extends Node {
|
582 | 582 |
|
583 | 583 | public abstract boolean execute(Node inliningTarget, ComparisonOp op, Object a, Object b);
|
584 | 584 |
|
585 |
| - private static boolean executeCFunction(Node inliningTarget, int op, Object a, Object b, InteropLibrary interopLibrary) { |
586 |
| - try { |
587 |
| - Object sym = CApiContext.getNativeSymbol(inliningTarget, FUN_PTR_COMPARE); |
588 |
| - return (int) interopLibrary.execute(sym, a, b, op) != 0; |
589 |
| - } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) { |
590 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
591 |
| - throw new IllegalStateException(FUN_PTR_COMPARE + " didn't work!"); |
592 |
| - } |
593 |
| - } |
594 |
| - |
595 | 585 | @Specialization(guards = "op.isEqualityOp()", limit = "2")
|
596 | 586 | static boolean doEqNe(ComparisonOp op, PythonAbstractNativeObject a, PythonAbstractNativeObject b,
|
597 | 587 | @CachedLibrary("a") InteropLibrary aLib,
|
598 | 588 | @CachedLibrary(limit = "3") InteropLibrary bLib) {
|
599 | 589 | return aLib.isIdentical(a, b, bLib) == (op == ComparisonOp.EQ);
|
600 | 590 | }
|
601 | 591 |
|
602 |
| - @Specialization |
603 |
| - static boolean doPythonNativeObject(Node inliningTarget, ComparisonOp op, PythonNativeObject a, PythonNativeObject b, |
604 |
| - @Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary) { |
| 592 | + @Specialization(guards = {"isNativeObjectOrVoidPointer(a)", "isNativeObjectOrLong(b)"}) |
| 593 | + static boolean doGeneric(Node inliningTarget, ComparisonOp op, Object a, Object b, |
| 594 | + @CachedLibrary(limit = "1") InteropLibrary interopLibrary, |
| 595 | + @Cached InlinedConditionProfile aProfile, |
| 596 | + @Cached InlinedConditionProfile bProfile) { |
605 | 597 | CompilerAsserts.partialEvaluationConstant(op);
|
606 |
| - return executeCFunction(inliningTarget, op.opCode, a.getPtr(), b.getPtr(), interopLibrary); |
| 598 | + Object ptrA; |
| 599 | + if (aProfile.profile(inliningTarget, a instanceof PythonNativeObject)) { |
| 600 | + ptrA = ((PythonNativeObject) a).getPtr(); |
| 601 | + } else { |
| 602 | + // guaranteed by the guard |
| 603 | + assert a instanceof PythonNativeVoidPtr; |
| 604 | + ptrA = ((PythonNativeVoidPtr) a).getNativePointer(); |
| 605 | + } |
| 606 | + Object ptrB; |
| 607 | + if (bProfile.profile(inliningTarget, b instanceof PythonNativeObject)) { |
| 608 | + ptrB = ((PythonNativeObject) b).getPtr(); |
| 609 | + } else { |
| 610 | + // guaranteed by the guard |
| 611 | + assert b instanceof Long; |
| 612 | + ptrB = b; |
| 613 | + } |
| 614 | + try { |
| 615 | + Object sym = CApiContext.getNativeSymbol(inliningTarget, FUN_PTR_COMPARE); |
| 616 | + return (int) interopLibrary.execute(sym, ptrA, ptrB, op.opCode) != 0; |
| 617 | + } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) { |
| 618 | + throw CompilerDirectives.shouldNotReachHere(e); |
| 619 | + } |
607 | 620 | }
|
608 | 621 |
|
609 |
| - @Specialization |
610 |
| - static boolean doPythonNativeObjectLong(Node inliningTarget, ComparisonOp op, PythonNativeObject a, long b, |
611 |
| - @Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary) { |
612 |
| - CompilerAsserts.partialEvaluationConstant(op); |
613 |
| - return executeCFunction(inliningTarget, op.opCode, a.getPtr(), b, interopLibrary); |
| 622 | + static boolean isNativeObjectOrVoidPointer(Object object) { |
| 623 | + return object instanceof PythonNativeObject || object instanceof PythonNativeVoidPtr; |
614 | 624 | }
|
615 | 625 |
|
616 |
| - @Specialization |
617 |
| - static boolean doNativeVoidPtrLong(Node inliningTarget, ComparisonOp op, PythonNativeVoidPtr a, long b, |
618 |
| - @Shared @CachedLibrary(limit = "1") InteropLibrary interopLibrary) { |
619 |
| - CompilerAsserts.partialEvaluationConstant(op); |
620 |
| - return executeCFunction(inliningTarget, op.opCode, a.getPointerObject(), b, interopLibrary); |
| 626 | + static boolean isNativeObjectOrLong(Object object) { |
| 627 | + return object instanceof PythonNativeObject || object instanceof Long; |
621 | 628 | }
|
622 | 629 | }
|
623 | 630 |
|
|
0 commit comments