25
25
*/
26
26
package com .oracle .graal .python .builtins .modules ;
27
27
28
- import com .oracle .truffle .api .dsl .NeverDefault ;
29
-
30
28
import static com .oracle .graal .python .runtime .exception .PythonErrorType .NotImplementedError ;
31
29
import static com .oracle .graal .python .runtime .exception .PythonErrorType .OverflowError ;
32
30
import static com .oracle .graal .python .runtime .exception .PythonErrorType .SystemError ;
59
57
import com .oracle .graal .python .lib .PyNumberIndexNode ;
60
58
import com .oracle .graal .python .lib .PyObjectGetIter ;
61
59
import com .oracle .graal .python .nodes .ErrorMessages ;
60
+ import com .oracle .graal .python .nodes .PGuards ;
62
61
import com .oracle .graal .python .nodes .PNodeWithRaise ;
63
62
import com .oracle .graal .python .nodes .builtins .TupleNodes ;
64
63
import com .oracle .graal .python .nodes .call .special .LookupAndCallUnaryNode ;
75
74
import com .oracle .graal .python .nodes .function .builtins .PythonUnaryClinicBuiltinNode ;
76
75
import com .oracle .graal .python .nodes .function .builtins .PythonVarargsBuiltinNode ;
77
76
import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentClinicProvider ;
77
+ import com .oracle .graal .python .nodes .object .BuiltinClassProfiles .IsBuiltinObjectProfile ;
78
78
import com .oracle .graal .python .nodes .object .GetClassNode ;
79
- import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
80
79
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
81
80
import com .oracle .graal .python .nodes .util .CastToJavaLongLossyNode ;
82
81
import com .oracle .graal .python .nodes .util .NarrowBigIntegerNode ;
86
85
import com .oracle .truffle .api .CompilerDirectives ;
87
86
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
88
87
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
88
+ import com .oracle .truffle .api .dsl .Bind ;
89
89
import com .oracle .truffle .api .dsl .Cached ;
90
90
import com .oracle .truffle .api .dsl .Cached .Shared ;
91
91
import com .oracle .truffle .api .dsl .Fallback ;
92
92
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
93
93
import com .oracle .truffle .api .dsl .ImportStatic ;
94
+ import com .oracle .truffle .api .dsl .NeverDefault ;
94
95
import com .oracle .truffle .api .dsl .NodeFactory ;
95
96
import com .oracle .truffle .api .dsl .Specialization ;
96
97
import com .oracle .truffle .api .dsl .TypeSystemReference ;
97
98
import com .oracle .truffle .api .frame .VirtualFrame ;
99
+ import com .oracle .truffle .api .nodes .Node ;
98
100
import com .oracle .truffle .api .profiles .ConditionProfile ;
101
+ import com .oracle .truffle .api .profiles .InlinedConditionProfile ;
99
102
import com .oracle .truffle .api .profiles .LoopConditionProfile ;
100
103
101
104
@ CoreFunctions (defineModule = "math" )
@@ -838,12 +841,13 @@ public abstract static class FsumNode extends PythonUnaryBuiltinNode {
838
841
839
842
@ Specialization
840
843
double doIt (VirtualFrame frame , Object iterable ,
844
+ @ Bind ("this" ) Node inliningTarget ,
841
845
@ Cached PyObjectGetIter getIter ,
842
846
@ Cached ("create(Next)" ) LookupAndCallUnaryNode callNextNode ,
843
847
@ Cached PyFloatAsDoubleNode asDoubleNode ,
844
- @ Cached IsBuiltinClassProfile stopProfile ) {
848
+ @ Cached IsBuiltinObjectProfile stopProfile ) {
845
849
Object iterator = getIter .execute (frame , iterable );
846
- return fsum (frame , iterator , callNextNode , asDoubleNode , stopProfile );
850
+ return fsum (frame , iterator , callNextNode , asDoubleNode , inliningTarget , stopProfile );
847
851
}
848
852
849
853
/*
@@ -856,7 +860,8 @@ public abstract static class FsumNode extends PythonUnaryBuiltinNode {
856
860
* is little bit faster. The testFSum in test_math.py takes in different implementations:
857
861
* CPython ~0.6s CurrentImpl: ~14.3s Using BigDecimal: ~15.1
858
862
*/
859
- private double fsum (VirtualFrame frame , Object iterator , LookupAndCallUnaryNode next , PyFloatAsDoubleNode asDoubleNode , IsBuiltinClassProfile stopProfile ) {
863
+ private double fsum (VirtualFrame frame , Object iterator , LookupAndCallUnaryNode next ,
864
+ PyFloatAsDoubleNode asDoubleNode , Node inliningTarget , IsBuiltinObjectProfile stopProfile ) {
860
865
double x , y , t , hi , lo = 0 , yr , inf_sum = 0 , special_sum = 0 , sum ;
861
866
double xsave ;
862
867
int i , j , n = 0 , arayLength = 32 ;
@@ -865,7 +870,7 @@ private double fsum(VirtualFrame frame, Object iterator, LookupAndCallUnaryNode
865
870
try {
866
871
x = asDoubleNode .execute (frame , next .executeObject (frame , iterator ));
867
872
} catch (PException e ) {
868
- e .expectStopIteration (stopProfile );
873
+ e .expectStopIteration (inliningTarget , stopProfile );
869
874
break ;
870
875
}
871
876
xsave = x ;
@@ -2313,26 +2318,22 @@ public abstract static class ProdNode extends PythonBuiltinNode {
2313
2318
2314
2319
@ Child private LookupAndCallUnaryNode callNextNode = LookupAndCallUnaryNode .create (SpecialMethodSlot .Next );
2315
2320
@ Child private BinaryOpNode mul = BinaryArithmetic .Mul .create ();
2316
- @ Child private IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile .create ();
2317
2321
2318
2322
@ Specialization
2319
- @ SuppressWarnings ("unused" )
2320
- public Object doGenericNoStart (VirtualFrame frame , Object iterable , PNone start ,
2321
- @ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ) {
2322
- return doGeneric (frame , iterable , 1 , getIter );
2323
- }
2324
-
2325
- @ Specialization (guards = "!isNoValue(start)" )
2326
- public Object doGeneric (VirtualFrame frame , Object iterable , Object start ,
2327
- @ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ) {
2323
+ public Object doGeneric (VirtualFrame frame , Object iterable , Object startIn ,
2324
+ @ Bind ("this" ) Node inliningTarget ,
2325
+ @ Cached IsBuiltinObjectProfile errorProfile ,
2326
+ @ Cached InlinedConditionProfile startIsNoValueProfile ,
2327
+ @ Cached PyObjectGetIter getIter ) {
2328
+ Object start = startIsNoValueProfile .profile (inliningTarget , PGuards .isNoValue (startIn )) ? 1 : startIn ;
2328
2329
Object iterator = getIter .execute (frame , iterable );
2329
2330
Object value = start ;
2330
2331
while (true ) {
2331
2332
Object nextValue ;
2332
2333
try {
2333
2334
nextValue = callNextNode .executeObject (frame , iterator );
2334
2335
} catch (PException e ) {
2335
- e .expectStopIteration (errorProfile );
2336
+ e .expectStopIteration (inliningTarget , errorProfile );
2336
2337
return value ;
2337
2338
}
2338
2339
value = mul .executeObject (frame , value , nextValue );
0 commit comments