Skip to content

Commit e425797

Browse files
committed
Uninline and make public lib nodes that will be needed in BytecodeDSL interpreter
1 parent 72c627a commit e425797

File tree

55 files changed

+1036
-517
lines changed

Some content is hidden

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

55 files changed

+1036
-517
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -2083,9 +2083,8 @@ public abstract static class PowNode extends PythonTernaryBuiltinNode {
20832083

20842084
@Specialization
20852085
Object ternary(VirtualFrame frame, Object x, Object y, Object z,
2086-
@Bind("this") Node inliningTarget,
20872086
@Cached PyNumberPowerNode power) {
2088-
return power.execute(frame, inliningTarget, x, y, z);
2087+
return power.execute(frame, x, y, z);
20892088
}
20902089
}
20912090

@@ -2134,9 +2133,9 @@ static Object sumIntIterator(VirtualFrame frame, Node inliningTarget, PIntegerSe
21342133
longResult = PythonUtils.addExact(longResult, next);
21352134
} catch (OverflowException e) {
21362135
overflowProfile.enter(inliningTarget);
2137-
Object objectResult = addNode.execute(frame, inliningTarget, longResult, next);
2136+
Object objectResult = addNode.execute(frame, longResult, next);
21382137
while (loopProfileGeneric.profile(inliningTarget, iterator.hasNext())) {
2139-
objectResult = addNode.execute(frame, inliningTarget, objectResult, iterator.next());
2138+
objectResult = addNode.execute(frame, objectResult, iterator.next());
21402139
}
21412140
return objectResult;
21422141
}
@@ -2158,9 +2157,9 @@ static Object sumLongIterator(VirtualFrame frame, Node inliningTarget, PLongSequ
21582157
longResult = PythonUtils.addExact(longResult, next);
21592158
} catch (OverflowException e) {
21602159
overflowProfile.enter(inliningTarget);
2161-
Object objectResult = addNode.execute(frame, inliningTarget, longResult, next);
2160+
Object objectResult = addNode.execute(frame, longResult, next);
21622161
while (loopProfileGeneric.profile(inliningTarget, iterator.hasNext())) {
2163-
objectResult = addNode.execute(frame, inliningTarget, objectResult, iterator.next());
2162+
objectResult = addNode.execute(frame, objectResult, iterator.next());
21642163
}
21652164
return objectResult;
21662165
}
@@ -2205,7 +2204,7 @@ static Object sumGeneric(VirtualFrame frame, Node inliningTarget, Object iterato
22052204
} catch (IteratorExhausted e) {
22062205
return start;
22072206
}
2208-
Object acc = addNode.execute(frame, inliningTarget, start, next);
2207+
Object acc = addNode.execute(frame, start, next);
22092208
/*
22102209
* We try to process integers/longs/doubles as long as we can. Then we always fall
22112210
* through to the generic path. `next` and `acc` are always properly set so that the
@@ -2268,7 +2267,7 @@ static Object sumGeneric(VirtualFrame frame, Node inliningTarget, Object iterato
22682267
}
22692268
boolean exhausted = false;
22702269
do {
2271-
acc = addNode.execute(frame, inliningTarget, acc, next);
2270+
acc = addNode.execute(frame, acc, next);
22722271
try {
22732272
next = nextNode.execute(frame, inliningTarget, iterator);
22742273
} catch (IteratorExhausted e) {

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MathModuleBuiltins.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,7 @@ public Object doGeneric(VirtualFrame frame, Object iterable, Object startIn,
24962496
while (loopProfile.profile(inliningTarget, !exhausted)) {
24972497
try {
24982498
Object next = nextNode.execute(frame, inliningTarget, iterator);
2499-
acc = multiplyNode.execute(frame, inliningTarget, acc, next);
2499+
acc = multiplyNode.execute(frame, acc, next);
25002500
} catch (IteratorExhausted e) {
25012501
exhausted = true;
25022502
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ static Object doObject(VirtualFrame frame, Object left, Object right,
133133
abstract static class MulNode extends PythonBinaryBuiltinNode {
134134
@Specialization
135135
static Object doObject(VirtualFrame frame, Object left, Object right,
136-
@Bind("this") Node inliningTarget,
137136
@Cached PyNumberMultiplyNode mulNode) {
138-
return mulNode.execute(frame, inliningTarget, left, right);
137+
return mulNode.execute(frame, left, right);
139138
}
140139
}
141140

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextAbstractBuiltins.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ abstract static class PyTrufflePyNumber_Add extends CApiBinaryBuiltinNode {
266266

267267
@Specialization
268268
static Object doGeneric(Object o1, Object o2,
269-
@Bind Node inliningTarget,
270269
@Cached PyNumberAddNode addNode) {
271-
return addNode.execute(null, inliningTarget, o1, o2);
270+
return addNode.execute(null, o1, o2);
272271
}
273272
}
274273

@@ -287,9 +286,8 @@ abstract static class PyTrufflePyNumber_Multiply extends CApiBinaryBuiltinNode {
287286

288287
@Specialization
289288
static Object doGeneric(Object o1, Object o2,
290-
@Bind Node inliningTarget,
291289
@Cached PyNumberMultiplyNode multiplyNode) {
292-
return multiplyNode.execute(null, inliningTarget, o1, o2);
290+
return multiplyNode.execute(null, o1, o2);
293291
}
294292
}
295293

@@ -528,9 +526,8 @@ abstract static class PyTrufflePyNumber_Power extends CApiTernaryBuiltinNode {
528526

529527
@Specialization
530528
Object doGeneric(Object o1, Object o2, Object o3,
531-
@Bind("this") Node inliningTarget,
532529
@Cached PyNumberPowerNode powerNode) {
533-
return powerNode.execute(null, inliningTarget, o1, o2, o3);
530+
return powerNode.execute(null, o1, o2, o3);
534531
}
535532
}
536533

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/asyncio/GetAwaitableNode.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
import com.oracle.truffle.api.dsl.GenerateUncached;
5858
import com.oracle.truffle.api.dsl.ImportStatic;
5959
import com.oracle.truffle.api.dsl.Specialization;
60-
import com.oracle.truffle.api.frame.Frame;
60+
import com.oracle.truffle.api.frame.VirtualFrame;
6161
import com.oracle.truffle.api.nodes.Node;
6262

6363
@GenerateUncached
6464
@ImportStatic(SpecialMethodSlot.class)
6565
@SuppressWarnings("truffle-inlining")
6666
public abstract class GetAwaitableNode extends Node {
67-
public abstract Object execute(Frame frame, Object arg);
67+
public abstract Object execute(VirtualFrame frame, Object arg);
6868

6969
@Specialization
7070
public static Object doGenerator(PGenerator generator,
@@ -83,7 +83,7 @@ public static Object doGenerator(PGenerator generator,
8383
}
8484

8585
@Specialization
86-
public static Object doGeneric(Frame frame, Object awaitable,
86+
public static Object doGeneric(VirtualFrame frame, Object awaitable,
8787
@Bind("this") Node inliningTarget,
8888
@Exclusive @Cached PRaiseNode raiseNoAwait,
8989
@Exclusive @Cached PRaiseNode raiseNotIter,

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,8 @@ public abstract static class GraalHPyAdd extends HPyTernaryContextFunction {
890890

891891
@Specialization
892892
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
893-
@Bind Node inliningTarget,
894893
@Cached PyNumberAddNode arithmeticNode) {
895-
return arithmeticNode.execute(null, inliningTarget, arg0, arg1);
894+
return arithmeticNode.execute(null, arg0, arg1);
896895
}
897896
}
898897

@@ -913,9 +912,8 @@ public abstract static class GraalHPyMultiply extends HPyTernaryContextFunction
913912

914913
@Specialization
915914
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1,
916-
@Bind Node inliningTarget,
917915
@Cached PyNumberMultiplyNode arithmeticNode) {
918-
return arithmeticNode.execute(null, inliningTarget, arg0, arg1);
916+
return arithmeticNode.execute(null, arg0, arg1);
919917
}
920918
}
921919

@@ -1035,9 +1033,8 @@ public abstract static class GraalHPyPower extends HPyQuaternaryContextFunction
10351033

10361034
@Specialization
10371035
static Object doGeneric(@SuppressWarnings("unused") Object hpyContext, Object arg0, Object arg1, Object arg2,
1038-
@Bind("this") Node inliningTarget,
10391036
@Cached PyNumberPowerNode powerNode) {
1040-
return powerNode.execute(null, inliningTarget, arg0, arg1, arg2);
1037+
return powerNode.execute(null, arg0, arg1, arg2);
10411038
}
10421039
}
10431040

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/floats/FloatBuiltins.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static double doDD(VirtualFrame frame, double left, double right, @SuppressWarni
392392
CompilerDirectives.transferToInterpreterAndInvalidate();
393393
// Negative numbers raised to fractional powers become complex.
394394
PythonLanguage language = PythonLanguage.get(inliningTarget);
395-
throw new UnexpectedResultException(powerNode.execute(frame, inliningTarget, PFactory.createComplex(language, left, 0), PFactory.createComplex(language, right, 0), none));
395+
throw new UnexpectedResultException(powerNode.execute(frame, PFactory.createComplex(language, left, 0), PFactory.createComplex(language, right, 0), none));
396396
}
397397
return Math.pow(left, right);
398398
}
@@ -409,7 +409,7 @@ static Object doDDToComplex(VirtualFrame frame, double left, double right, PNone
409409
if (left < 0 && Double.isFinite(left) && Double.isFinite(right) && (right % 1 != 0)) {
410410
// Negative numbers raised to fractional powers become complex.
411411
PythonLanguage language = PythonLanguage.get(inliningTarget);
412-
return powerNode.execute(frame, inliningTarget, PFactory.createComplex(language, left, 0), PFactory.createComplex(language, right, 0), none);
412+
return powerNode.execute(frame, PFactory.createComplex(language, left, 0), PFactory.createComplex(language, right, 0), none);
413413
}
414414
return Math.pow(left, right);
415415
}

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/ForeignNumberBuiltins.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ static Object doIt(VirtualFrame frame, Object v, Object w, Object z,
596596
if (v == null || w == null || z == null) {
597597
return PNotImplemented.NOT_IMPLEMENTED;
598598
}
599-
return power.execute(frame, inliningTarget, v, w, z);
599+
return power.execute(frame, v, w, z);
600600
}
601601
}
602602

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/AccumulateBuiltins.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static Object next(VirtualFrame frame, PAccumulate self,
123123
return value;
124124
}
125125
if (hasFuncProfile.profile(inliningTarget, self.getFunc() == null)) {
126-
self.setTotal(addNode.execute(frame, inliningTarget, self.getTotal(), value));
126+
self.setTotal(addNode.execute(frame, self.getTotal(), value));
127127
} else {
128128
self.setTotal(callNode.execute(frame, self.getFunc(), self.getTotal(), value));
129129
}

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/itertools/CountBuiltins.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ static Object iter(PCount self) {
101101
public abstract static class NextNode extends TpIterNextBuiltin {
102102
@Specialization
103103
static Object next(VirtualFrame frame, PCount self,
104-
@Bind("this") Node inliningTarget,
105104
@Cached PyNumberAddNode addNode) {
106105
Object cnt = self.getCnt();
107-
self.setCnt(addNode.execute(frame, inliningTarget, self.getCnt(), self.getStep()));
106+
self.setCnt(addNode.execute(frame, self.getCnt(), self.getStep()));
108107
return cnt;
109108
}
110109
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.lib;
42+
43+
import static com.oracle.graal.python.builtins.objects.ints.IntBuiltins.AddNode.add;
44+
45+
import com.oracle.graal.python.PythonLanguage;
46+
import com.oracle.graal.python.builtins.objects.ints.PInt;
47+
import com.oracle.graal.python.nodes.expression.BinaryOpNode;
48+
import com.oracle.graal.python.nodes.truffle.PythonIntegerTypes;
49+
import com.oracle.graal.python.runtime.object.PFactory;
50+
import com.oracle.truffle.api.dsl.Bind;
51+
import com.oracle.truffle.api.dsl.GenerateCached;
52+
import com.oracle.truffle.api.dsl.Specialization;
53+
import com.oracle.truffle.api.dsl.TypeSystemReference;
54+
55+
/**
56+
* Helper class with shared fast-paths. Must be public so that it is accessible by the Bytecode DSL
57+
* generated code.
58+
*/
59+
@GenerateCached(false)
60+
@TypeSystemReference(PythonIntegerTypes.class)
61+
public abstract class PyNumberAddFastPaths extends BinaryOpNode {
62+
63+
/*
64+
* All the following fast paths need to be kept in sync with the corresponding builtin functions
65+
* in IntBuiltins
66+
*/
67+
@Specialization(rewriteOn = ArithmeticException.class)
68+
public static int doII(int left, int right) {
69+
return Math.addExact(left, right);
70+
}
71+
72+
@Specialization(replaces = "doII", rewriteOn = ArithmeticException.class)
73+
public static long doLL(long left, long right) {
74+
return Math.addExact(left, right);
75+
}
76+
77+
@Specialization(replaces = "doLL")
78+
public static Object doLLOvf(long x, long y,
79+
@Bind PythonLanguage language) {
80+
/* Inlined version of Math.addExact(x, y) with BigInteger fallback. */
81+
long r = x + y;
82+
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
83+
if (((x ^ r) & (y ^ r)) < 0) {
84+
return PFactory.createInt(language, add(PInt.longToBigInteger(x), PInt.longToBigInteger(y)));
85+
}
86+
return r;
87+
}
88+
89+
/*
90+
* All the following fast paths need to be kept in sync with the corresponding builtin functions
91+
* in FloatBuiltins
92+
*/
93+
@Specialization
94+
public static double doDD(double left, double right) {
95+
return left + right;
96+
}
97+
98+
@Specialization
99+
public static double doDL(double left, long right) {
100+
return left + right;
101+
}
102+
103+
@Specialization
104+
public static double doLD(long left, double right) {
105+
return left + right;
106+
}
107+
}

0 commit comments

Comments
 (0)