166
166
import com .oracle .graal .python .lib .PyEvalGetGlobals ;
167
167
import com .oracle .graal .python .lib .PyEvalGetLocals ;
168
168
import com .oracle .graal .python .lib .PyMappingCheckNode ;
169
+ import com .oracle .graal .python .lib .PyNumberAddNode ;
169
170
import com .oracle .graal .python .lib .PyNumberAsSizeNode ;
170
171
import com .oracle .graal .python .lib .PyNumberIndexNode ;
171
172
import com .oracle .graal .python .lib .PyObjectAsciiNode ;
213
214
import com .oracle .graal .python .nodes .call .special .LookupSpecialMethodSlotNode ;
214
215
import com .oracle .graal .python .nodes .classes .IsSubtypeNode ;
215
216
import com .oracle .graal .python .nodes .expression .BinaryArithmetic ;
216
- import com .oracle .graal .python .nodes .expression .BinaryArithmetic .AddNode ;
217
217
import com .oracle .graal .python .nodes .expression .BinaryComparisonNode ;
218
218
import com .oracle .graal .python .nodes .expression .BinaryOpNode ;
219
219
import com .oracle .graal .python .nodes .expression .CoerceToBooleanNode ;
@@ -2183,25 +2183,26 @@ Object ternary(VirtualFrame frame, Object x, Object y, Object z,
2183
2183
public abstract static class SumFunctionNode extends PythonBuiltinNode {
2184
2184
2185
2185
@ Child private LookupAndCallUnaryNode next = LookupAndCallUnaryNode .create (SpecialMethodSlot .Next );
2186
- @ Child private AddNode add = AddNode .create ();
2187
2186
2188
- @ Specialization (rewriteOn = UnexpectedResultException .class )
2187
+ @ Specialization (guards = "isNoValue(start)" , rewriteOn = UnexpectedResultException .class )
2189
2188
int sumIntNone (VirtualFrame frame , Object arg1 , @ SuppressWarnings ("unused" ) PNone start ,
2190
2189
@ Bind ("this" ) Node inliningTarget ,
2190
+ @ Shared @ Cached PyNumberAddNode addNode ,
2191
2191
@ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
2192
2192
@ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ) throws UnexpectedResultException {
2193
- return sumIntInternal (frame , inliningTarget , arg1 , 0 , getIter , errorProfile );
2193
+ return sumIntInternal (frame , inliningTarget , arg1 , 0 , addNode , getIter , errorProfile );
2194
2194
}
2195
2195
2196
2196
@ Specialization (rewriteOn = UnexpectedResultException .class )
2197
2197
int sumIntInt (VirtualFrame frame , Object arg1 , int start ,
2198
2198
@ Bind ("this" ) Node inliningTarget ,
2199
+ @ Shared @ Cached PyNumberAddNode addNode ,
2199
2200
@ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
2200
2201
@ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ) throws UnexpectedResultException {
2201
- return sumIntInternal (frame , inliningTarget , arg1 , start , getIter , errorProfile );
2202
+ return sumIntInternal (frame , inliningTarget , arg1 , start , addNode , getIter , errorProfile );
2202
2203
}
2203
2204
2204
- private int sumIntInternal (VirtualFrame frame , Node inliningTarget , Object arg1 , int start , PyObjectGetIter getIter ,
2205
+ private int sumIntInternal (VirtualFrame frame , Node inliningTarget , Object arg1 , int start , PyNumberAddNode add , PyObjectGetIter getIter ,
2205
2206
IsBuiltinObjectProfile errorProfile ) throws UnexpectedResultException {
2206
2207
Object iterator = getIter .execute (frame , inliningTarget , arg1 );
2207
2208
int value = start ;
@@ -2213,30 +2214,31 @@ private int sumIntInternal(VirtualFrame frame, Node inliningTarget, Object arg1,
2213
2214
e .expectStopIteration (inliningTarget , errorProfile );
2214
2215
return value ;
2215
2216
} catch (UnexpectedResultException e ) {
2216
- Object newValue = add .executeObject (frame , value , e .getResult ());
2217
- throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , newValue , errorProfile ));
2217
+ Object newValue = add .execute (frame , inliningTarget , value , e .getResult ());
2218
+ throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , newValue , add , errorProfile ));
2218
2219
}
2219
2220
try {
2220
- value = add .executeInt (frame , value , nextValue );
2221
+ value = add .executeInt (frame , inliningTarget , value , nextValue );
2221
2222
} catch (UnexpectedResultException e ) {
2222
- throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , e .getResult (), errorProfile ));
2223
+ throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , e .getResult (), add , errorProfile ));
2223
2224
}
2224
2225
}
2225
2226
}
2226
2227
2227
2228
@ Specialization (rewriteOn = UnexpectedResultException .class )
2228
2229
double sumDoubleDouble (VirtualFrame frame , Object arg1 , double start ,
2229
2230
@ Bind ("this" ) Node inliningTarget ,
2231
+ @ Shared @ Cached PyNumberAddNode addNode ,
2230
2232
@ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
2231
2233
// dummy inline profile, so it can be @Shared, to optimize generated code:
2232
2234
@ SuppressWarnings ("unused" ) @ Shared @ Cached InlinedConditionProfile hasStart ,
2233
2235
@ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ,
2234
2236
// dummy raiseNode, so it can be @Shared, to optimize generated code:
2235
2237
@ SuppressWarnings ("unused" ) @ Shared @ Cached PRaiseNode .Lazy raiseNode ) throws UnexpectedResultException {
2236
- return sumDoubleInternal (frame , inliningTarget , arg1 , start , getIter , errorProfile );
2238
+ return sumDoubleInternal (frame , inliningTarget , arg1 , start , addNode , getIter , errorProfile );
2237
2239
}
2238
2240
2239
- private double sumDoubleInternal (VirtualFrame frame , Node inliningTarget , Object arg1 , double start , PyObjectGetIter getIter ,
2241
+ private double sumDoubleInternal (VirtualFrame frame , Node inliningTarget , Object arg1 , double start , PyNumberAddNode add , PyObjectGetIter getIter ,
2240
2242
IsBuiltinObjectProfile errorProfile ) throws UnexpectedResultException {
2241
2243
Object iterator = getIter .execute (frame , inliningTarget , arg1 );
2242
2244
double value = start ;
@@ -2248,20 +2250,21 @@ private double sumDoubleInternal(VirtualFrame frame, Node inliningTarget, Object
2248
2250
e .expectStopIteration (inliningTarget , errorProfile );
2249
2251
return value ;
2250
2252
} catch (UnexpectedResultException e ) {
2251
- Object newValue = add .executeObject (frame , value , e .getResult ());
2252
- throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , newValue , errorProfile ));
2253
+ Object newValue = add .execute (frame , inliningTarget , value , e .getResult ());
2254
+ throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , newValue , add , errorProfile ));
2253
2255
}
2254
2256
try {
2255
- value = add .executeDouble (frame , value , nextValue );
2257
+ value = add .executeDouble (frame , inliningTarget , value , nextValue );
2256
2258
} catch (UnexpectedResultException e ) {
2257
- throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , e .getResult (), errorProfile ));
2259
+ throw new UnexpectedResultException (iterateGeneric (frame , inliningTarget , iterator , e .getResult (), add , errorProfile ));
2258
2260
}
2259
2261
}
2260
2262
}
2261
2263
2262
2264
@ Specialization (replaces = {"sumIntNone" , "sumIntInt" , "sumDoubleDouble" })
2263
2265
Object sum (VirtualFrame frame , Object arg1 , Object start ,
2264
2266
@ Bind ("this" ) Node inliningTarget ,
2267
+ @ Shared @ Cached PyNumberAddNode addNode ,
2265
2268
@ Shared @ Cached IsBuiltinObjectProfile errorProfile ,
2266
2269
@ Shared ("getIter" ) @ Cached PyObjectGetIter getIter ,
2267
2270
@ Shared @ Cached InlinedConditionProfile hasStart ,
@@ -2274,10 +2277,10 @@ Object sum(VirtualFrame frame, Object arg1, Object start,
2274
2277
throw raiseNode .get (inliningTarget ).raise (TypeError , ErrorMessages .CANT_SUM_BYTEARRAY );
2275
2278
}
2276
2279
Object iterator = getIter .execute (frame , inliningTarget , arg1 );
2277
- return iterateGeneric (frame , inliningTarget , iterator , hasStart .profile (inliningTarget , start != NO_VALUE ) ? start : 0 , errorProfile );
2280
+ return iterateGeneric (frame , inliningTarget , iterator , hasStart .profile (inliningTarget , start != NO_VALUE ) ? start : 0 , addNode , errorProfile );
2278
2281
}
2279
2282
2280
- private Object iterateGeneric (VirtualFrame frame , Node inliningTarget , Object iterator , Object start , IsBuiltinObjectProfile errorProfile ) {
2283
+ private Object iterateGeneric (VirtualFrame frame , Node inliningTarget , Object iterator , Object start , PyNumberAddNode add , IsBuiltinObjectProfile errorProfile ) {
2281
2284
Object value = start ;
2282
2285
while (true ) {
2283
2286
Object nextValue ;
@@ -2287,7 +2290,7 @@ private Object iterateGeneric(VirtualFrame frame, Node inliningTarget, Object it
2287
2290
e .expectStopIteration (inliningTarget , errorProfile );
2288
2291
return value ;
2289
2292
}
2290
- value = add .executeObject (frame , value , nextValue );
2293
+ value = add .execute (frame , inliningTarget , value , nextValue );
2291
2294
}
2292
2295
}
2293
2296
}
0 commit comments