Skip to content

Commit f2f0302

Browse files
committed
[GR-61943] Uninline some lib nodes used in the bytecode interpreter.
PullRequest: graalpython/3677
2 parents f8f4e1e + 5ee3714 commit f2f0302

File tree

78 files changed

+487
-549
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+487
-549
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinConstructors.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,9 +1347,8 @@ static Object doWithBase(VirtualFrame frame, Node inliningTarget, Object x, Obje
13471347
public abstract static class BoolNode extends PythonBinaryBuiltinNode {
13481348
@Specialization
13491349
public static boolean bool(VirtualFrame frame, @SuppressWarnings("unused") Object cls, Object obj,
1350-
@Bind("this") Node inliningTarget,
13511350
@Cached PyObjectIsTrueNode isTrue) {
1352-
return isTrue.execute(frame, inliningTarget, obj);
1351+
return isTrue.execute(frame, obj);
13531352
}
13541353
}
13551354

@@ -1952,7 +1951,7 @@ static PZip zip(VirtualFrame frame, Object cls, Object[] args, PKeyword[] kw,
19521951
@Shared @Cached PythonObjectFactory factory,
19531952
@Exclusive @Cached PRaiseNode.Lazy raiseNode) {
19541953
if (profile.profile(inliningTarget, eqNode.execute(kw[0].getName(), T_STRICT, TS_ENCODING))) {
1955-
return zip(frame, inliningTarget, cls, args, isTrueNode.execute(frame, inliningTarget, kw[0].getValue()), getIter, factory);
1954+
return zip(frame, inliningTarget, cls, args, isTrueNode.execute(frame, kw[0].getValue()), getIter, factory);
19561955
}
19571956
throw raiseNode.get(inliningTarget).raise(TypeError, ErrorMessages.S_IS_AN_INVALID_ARG_FOR_S, kw[0].getName(), T_ZIP);
19581957
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@
218218
import com.oracle.graal.python.nodes.expression.BinaryArithmetic;
219219
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
220220
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
221-
import com.oracle.graal.python.nodes.expression.CoerceToBooleanNode;
222221
import com.oracle.graal.python.nodes.expression.TernaryArithmetic;
223222
import com.oracle.graal.python.nodes.frame.GetFrameLocalsNode;
224223
import com.oracle.graal.python.nodes.frame.ReadCallerFrameNode;
@@ -334,9 +333,8 @@ public abstract static class AbsNode extends PythonUnaryBuiltinNode {
334333

335334
@Specialization
336335
static Object absObject(VirtualFrame frame, Object object,
337-
@Bind("this") Node inliningTarget,
338336
@Cached PyNumberAbsoluteNode absoluteNode) {
339-
return absoluteNode.execute(frame, inliningTarget, object);
337+
return absoluteNode.executeCached(frame, object);
340338
}
341339
}
342340

@@ -403,11 +401,11 @@ static boolean doGenericSequence(VirtualFrame frame, Node inliningTarget, Sequen
403401

404402
for (int i = 0; loopConditionProfile.profile(inliningTarget, i < seqLength); i++) {
405403
if (nodeType == AnyOrAllNodeType.ALL &&
406-
earlyExitProfile.profile(inliningTarget, !isTrueNode.execute(frame, inliningTarget, getItem.execute(inliningTarget, sequenceStorage, i)))) {
404+
earlyExitProfile.profile(inliningTarget, !isTrueNode.execute(frame, getItem.execute(inliningTarget, sequenceStorage, i)))) {
407405
LoopNode.reportLoopCount(inliningTarget, i);
408406
return false;
409407
} else if (nodeType == AnyOrAllNodeType.ANY &&
410-
earlyExitProfile.profile(inliningTarget, isTrueNode.execute(frame, inliningTarget, getItem.execute(inliningTarget, sequenceStorage, i)))) {
408+
earlyExitProfile.profile(inliningTarget, isTrueNode.execute(frame, getItem.execute(inliningTarget, sequenceStorage, i)))) {
411409
LoopNode.reportLoopCount(inliningTarget, i);
412410
return true;
413411
}
@@ -436,10 +434,10 @@ protected boolean doHashStorage(VirtualFrame frame, HashingStorage hashingStorag
436434
while (loopConditionProfile.profile(inliningTarget, getIterNext.execute(inliningTarget, hashingStorage, it))) {
437435
Object key = getIterKey.execute(inliningTarget, hashingStorage, it);
438436
if (nodeType == AnyOrAllNodeType.ALL) {
439-
if (!isTrueNode.execute(frame, inliningTarget, key)) {
437+
if (!isTrueNode.execute(frame, key)) {
440438
return false;
441439
}
442-
} else if (nodeType == AnyOrAllNodeType.ANY && isTrueNode.execute(frame, inliningTarget, key)) {
440+
} else if (nodeType == AnyOrAllNodeType.ANY && isTrueNode.execute(frame, key)) {
443441
return true;
444442
}
445443
}
@@ -485,7 +483,7 @@ static boolean doObject(VirtualFrame frame, Object object,
485483
try {
486484
Object next = nextNode.execute(frame, iterator);
487485
nbrIter++;
488-
if (!isTrueNode.execute(frame, inliningTarget, next)) {
486+
if (!isTrueNode.execute(frame, next)) {
489487
return false;
490488
}
491489
} catch (PException e) {
@@ -538,7 +536,7 @@ static boolean doObject(VirtualFrame frame, Object object,
538536
try {
539537
Object next = nextNode.execute(frame, iterator);
540538
nbrIter++;
541-
if (isTrueNode.execute(frame, inliningTarget, next)) {
539+
if (isTrueNode.execute(frame, next)) {
542540
return true;
543541
}
544542
} catch (PException e) {
@@ -1458,35 +1456,35 @@ public IsInstanceNode createRecursive(byte newDepth) {
14581456
return BuiltinFunctionsFactory.IsInstanceNodeFactory.create(newDepth);
14591457
}
14601458

1461-
private static TriState isInstanceCheckInternal(VirtualFrame frame, Node inliningTarget, Object instance, Object cls, LookupAndCallBinaryNode instanceCheckNode,
1462-
CoerceToBooleanNode castToBooleanNode) {
1459+
private static TriState isInstanceCheckInternal(VirtualFrame frame, Object instance, Object cls, LookupAndCallBinaryNode instanceCheckNode,
1460+
PyObjectIsTrueNode castToBooleanNode) {
14631461
Object instanceCheckResult = instanceCheckNode.executeObject(frame, cls, instance);
14641462
if (instanceCheckResult == NOT_IMPLEMENTED) {
14651463
return TriState.UNDEFINED;
14661464
}
1467-
return TriState.valueOf(castToBooleanNode.executeBoolean(frame, inliningTarget, instanceCheckResult));
1465+
return TriState.valueOf(castToBooleanNode.execute(frame, instanceCheckResult));
14681466
}
14691467

14701468
@Specialization(guards = "isPythonClass(cls)")
14711469
static boolean isInstance(VirtualFrame frame, Object instance, Object cls,
14721470
@Bind("this") Node inliningTarget,
14731471
@Shared("instanceCheck") @Cached("create(InstanceCheck)") LookupAndCallBinaryNode instanceCheckNode,
1474-
@Exclusive @Cached CoerceToBooleanNode.YesNode castToBooleanNode,
1472+
@Exclusive @Cached PyObjectIsTrueNode castToBooleanNode,
14751473
@Cached GetClassNode getClassNode,
14761474
@Cached IsSameTypeNode isSameTypeNode,
14771475
@Cached IsSubtypeNode isSubtypeNode) {
14781476
Object instanceClass = getClassNode.execute(inliningTarget, instance);
14791477
return isSameTypeNode.execute(inliningTarget, instanceClass, cls) || isSubtypeNode.execute(frame, instanceClass, cls)//
1480-
|| isInstanceCheckInternal(frame, inliningTarget, instance, cls, instanceCheckNode, castToBooleanNode) == TriState.TRUE;
1478+
|| isInstanceCheckInternal(frame, instance, cls, instanceCheckNode, castToBooleanNode) == TriState.TRUE;
14811479
}
14821480

14831481
@Specialization(guards = {"!isPTuple(cls)", "!isPythonClass(cls)"})
14841482
static boolean isInstance(VirtualFrame frame, Object instance, Object cls,
14851483
@Bind("this") Node inliningTarget,
14861484
@Shared("instanceCheck") @Cached("create(InstanceCheck)") LookupAndCallBinaryNode instanceCheckNode,
1487-
@Exclusive @Cached CoerceToBooleanNode.YesNode castToBooleanNode,
1485+
@Exclusive @Cached PyObjectIsTrueNode castToBooleanNode,
14881486
@Cached TypeBuiltins.InstanceCheckNode typeInstanceCheckNode) {
1489-
TriState check = isInstanceCheckInternal(frame, inliningTarget, instance, cls, instanceCheckNode, castToBooleanNode);
1487+
TriState check = isInstanceCheckInternal(frame, instance, cls, instanceCheckNode, castToBooleanNode);
14901488
if (check == TriState.UNDEFINED) {
14911489
return typeInstanceCheckNode.executeWith(frame, cls, instance);
14921490
}
@@ -1515,13 +1513,12 @@ public IsSubClassNode createRecursive(byte newDepth) {
15151513

15161514
@Specialization(guards = "!isPTuple(cls)")
15171515
static boolean isSubclass(VirtualFrame frame, Object derived, Object cls,
1518-
@Bind("this") Node inliningTarget,
15191516
@Cached("create(Subclasscheck)") LookupAndCallBinaryNode subclassCheckNode,
1520-
@Cached CoerceToBooleanNode.YesNode castToBooleanNode,
1517+
@Cached PyObjectIsTrueNode castToBooleanNode,
15211518
@Cached IsSubtypeNode isSubtypeNode) {
15221519
Object instanceCheckResult = subclassCheckNode.executeObject(frame, cls, derived);
15231520
if (instanceCheckResult != NOT_IMPLEMENTED) {
1524-
return castToBooleanNode.executeBoolean(frame, inliningTarget, instanceCheckResult);
1521+
return castToBooleanNode.execute(frame, instanceCheckResult);
15251522
}
15261523
return isSubtypeNode.execute(frame, derived, cls);
15271524
}
@@ -1583,7 +1580,7 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
15831580
BinaryComparisonNode compare,
15841581
@Exclusive @Cached PyObjectGetIter getIter,
15851582
@Cached(inline = false) GetNextNode nextNode,
1586-
@Exclusive @Cached CoerceToBooleanNode.YesNode castToBooleanNode,
1583+
@Exclusive @Cached PyObjectIsTrueNode castToBooleanNode,
15871584
@Exclusive @Cached CallNode.Lazy keyCall,
15881585
@Exclusive @Cached InlinedBranchProfile seenNonBoolean,
15891586
@Exclusive @Cached InlinedConditionProfile keywordArgIsNone,
@@ -1624,10 +1621,10 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
16241621
isTrue = compare.executeBool(frame, nextKey, currentKey);
16251622
} catch (UnexpectedResultException e) {
16261623
seenNonBoolean.enter(inliningTarget);
1627-
isTrue = castToBooleanNode.executeBoolean(frame, inliningTarget, e.getResult());
1624+
isTrue = castToBooleanNode.execute(frame, e.getResult());
16281625
}
16291626
} else {
1630-
isTrue = castToBooleanNode.executeBoolean(frame, inliningTarget, compare.executeObject(frame, nextKey, currentKey));
1627+
isTrue = castToBooleanNode.execute(frame, compare.executeObject(frame, nextKey, currentKey));
16311628
}
16321629
if (isTrue) {
16331630
currentKey = nextKey;
@@ -1644,7 +1641,7 @@ static Object minmaxSequenceWithKey(VirtualFrame frame, Node inliningTarget, Obj
16441641
@Specialization(guards = {"args.length != 0"})
16451642
static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Object arg1, Object[] args, Object keywordArgIn, Object defaultVal, String name, BinaryComparisonNode compare,
16461643
@Exclusive @Cached CallNode.Lazy keyCall,
1647-
@Exclusive @Cached CoerceToBooleanNode.YesNode castToBooleanNode,
1644+
@Exclusive @Cached PyObjectIsTrueNode castToBooleanNode,
16481645
@Exclusive @Cached InlinedBranchProfile seenNonBoolean,
16491646
@Exclusive @Cached InlinedConditionProfile keywordArgIsNone,
16501647
@Exclusive @Cached InlinedConditionProfile moreThanTwo,
@@ -1668,10 +1665,10 @@ static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Objec
16681665
isTrue = compare.executeBool(frame, nextKey, currentKey);
16691666
} catch (UnexpectedResultException e) {
16701667
seenNonBoolean.enter(inliningTarget);
1671-
isTrue = castToBooleanNode.executeBoolean(frame, inliningTarget, e.getResult());
1668+
isTrue = castToBooleanNode.execute(frame, e.getResult());
16721669
}
16731670
} else {
1674-
isTrue = castToBooleanNode.executeBoolean(frame, inliningTarget, compare.executeObject(frame, nextKey, currentKey));
1671+
isTrue = castToBooleanNode.execute(frame, compare.executeObject(frame, nextKey, currentKey));
16751672
}
16761673
if (isTrue) {
16771674
currentKey = nextKey;
@@ -1688,10 +1685,10 @@ static Object minmaxBinaryWithKey(VirtualFrame frame, Node inliningTarget, Objec
16881685
isTrue = compare.executeBool(frame, nextKey, currentKey);
16891686
} catch (UnexpectedResultException e) {
16901687
seenNonBoolean.enter(inliningTarget);
1691-
isTrue = castToBooleanNode.executeBoolean(frame, inliningTarget, e.getResult());
1688+
isTrue = castToBooleanNode.execute(frame, e.getResult());
16921689
}
16931690
} else {
1694-
isTrue = castToBooleanNode.executeBoolean(frame, inliningTarget, compare.executeObject(frame, nextKey, currentKey));
1691+
isTrue = castToBooleanNode.execute(frame, compare.executeObject(frame, nextKey, currentKey));
16951692
}
16961693
if (isTrue) {
16971694
currentKey = nextKey;
@@ -1882,7 +1879,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
18821879
@Bind("this") Node inliningTarget,
18831880
@Cached CastToTruffleStringNode castSep,
18841881
@Cached CastToTruffleStringNode castEnd,
1885-
@Cached CoerceToBooleanNode.YesNode castFlush,
1882+
@Cached PyObjectIsTrueNode castFlush,
18861883
@Exclusive @Cached PyObjectGetAttr getWriteMethod,
18871884
@Exclusive @Cached CallNode callWrite,
18881885
@Exclusive @Cached PyObjectCallMethodObjArgs callFlush,
@@ -1916,7 +1913,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
19161913
if (flushIn instanceof PNone) {
19171914
flush = false;
19181915
} else {
1919-
flush = castFlush.executeBoolean(frame, inliningTarget, flushIn);
1916+
flush = castFlush.execute(frame, flushIn);
19201917
}
19211918
return printAllGiven(frame, values, sep, end, file, flush, inliningTarget, getWriteMethod, callWrite, callFlush, strNode);
19221919
}
@@ -2152,21 +2149,18 @@ public abstract static class SumFunctionNode extends PythonBuiltinNode {
21522149

21532150
@Child private LookupAndCallUnaryNode next = LookupAndCallUnaryNode.create(SpecialMethodSlot.Next);
21542151

2155-
@Specialization(guards = "isNoValue(start)", rewriteOn = UnexpectedResultException.class)
2156-
int sumIntNone(VirtualFrame frame, Object arg1, @SuppressWarnings("unused") PNone start,
2157-
@Bind("this") Node inliningTarget,
2158-
@Shared @Cached PyNumberAddNode addNode,
2159-
@Shared @Cached IsBuiltinObjectProfile errorProfile,
2160-
@Shared("getIter") @Cached PyObjectGetIter getIter) throws UnexpectedResultException {
2161-
return sumIntInternal(frame, inliningTarget, arg1, 0, addNode, getIter, errorProfile);
2152+
public static boolean isIntOrNone(Object o) {
2153+
return o instanceof Integer || PGuards.isNoValue(o);
21622154
}
21632155

2164-
@Specialization(rewriteOn = UnexpectedResultException.class)
2165-
int sumIntInt(VirtualFrame frame, Object arg1, int start,
2156+
@Specialization(guards = "isIntOrNone(startIn)", rewriteOn = UnexpectedResultException.class)
2157+
int sumInt(VirtualFrame frame, Object arg1, Object startIn,
21662158
@Bind("this") Node inliningTarget,
2159+
@Shared @Cached InlinedConditionProfile hasStart,
21672160
@Shared @Cached PyNumberAddNode addNode,
21682161
@Shared @Cached IsBuiltinObjectProfile errorProfile,
21692162
@Shared("getIter") @Cached PyObjectGetIter getIter) throws UnexpectedResultException {
2163+
int start = hasStart.profile(inliningTarget, startIn instanceof Integer) ? (Integer) startIn : 0;
21702164
return sumIntInternal(frame, inliningTarget, arg1, start, addNode, getIter, errorProfile);
21712165
}
21722166

@@ -2229,7 +2223,7 @@ private double sumDoubleInternal(VirtualFrame frame, Node inliningTarget, Object
22292223
}
22302224
}
22312225

2232-
@Specialization(replaces = {"sumIntNone", "sumIntInt", "sumDoubleDouble"})
2226+
@Specialization(replaces = {"sumInt", "sumDoubleDouble"})
22332227
Object sum(VirtualFrame frame, Object arg1, Object start,
22342228
@Bind("this") Node inliningTarget,
22352229
@Shared @Cached PyNumberAddNode addNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/OperatorModuleBuiltins.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, 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
@@ -91,9 +91,8 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
9191
abstract static class TruthNode extends PythonUnaryBuiltinNode {
9292
@Specialization
9393
static Object doObject(VirtualFrame frame, Object object,
94-
@Bind("this") Node inliningTarget,
9594
@Cached PyObjectIsTrueNode isTrueNode) {
96-
return isTrueNode.execute(frame, inliningTarget, object);
95+
return isTrueNode.execute(frame, object);
9796
}
9897
}
9998

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/WarningsModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ private boolean checkMatched(VirtualFrame frame, Object obj, Object arg) {
480480
}
481481
} catch (CannotCastException e) {
482482
Object result = getCallMethodNode().executeCached(frame, obj, T_MATCH, arg);
483-
return getIsTrueNode().executeCached(frame, result);
483+
return getIsTrueNode().execute(frame, result);
484484
}
485485
}
486486

@@ -647,7 +647,7 @@ private static boolean alreadyWarned(VirtualFrame frame, PythonModule _warnings,
647647
} else {
648648
Object alreadyWarned = getItem.executeCached(frame, registry, key);
649649
if (alreadyWarned != null) {
650-
return isTrueNode.executeCached(frame, alreadyWarned);
650+
return isTrueNode.execute(frame, alreadyWarned);
651651
}
652652
}
653653
if (shouldSet) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, 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
@@ -139,7 +139,7 @@ Object getModule(Object name,
139139
try {
140140
Object spec = getAttr.execute(null, inliningTarget, m, T___SPEC__);
141141
Object initializingObj = getAttr.execute(null, inliningTarget, spec, T___INITIALIZING__);
142-
if (isTrueNode.execute(null, inliningTarget, initializingObj)) {
142+
if (isTrueNode.execute(null, initializingObj)) {
143143
initializing = true;
144144
}
145145
} catch (PException e) {

0 commit comments

Comments
 (0)