Skip to content

Commit 9d14227

Browse files
committed
Use specialization replacement to avoid perf-warn
1 parent c36f08c commit 9d14227

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallBinaryNode.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
5151
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
5252
import com.oracle.graal.python.nodes.object.GetClassNode;
53+
import com.oracle.graal.python.runtime.PythonOptions;
5354
import com.oracle.graal.python.util.Supplier;
5455
import com.oracle.truffle.api.CompilerDirectives;
5556
import com.oracle.truffle.api.dsl.Cached;
@@ -73,6 +74,7 @@
7374
// Although it would produce correct results, the special handling of long to double comparison
7475
// is slower than converting int->double, which is always correct.
7576
@ReportPolymorphism
77+
@ImportStatic(PythonOptions.class)
7678
public abstract class LookupAndCallBinaryNode extends Node {
7779

7880
public abstract static class NotImplementedHandler extends PNodeWithContext {
@@ -283,51 +285,51 @@ boolean callBoolean(VirtualFrame frame, long left, long right,
283285
// int, double
284286

285287
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
286-
boolean callBoolean(VirtualFrame frame, int left, double right,
288+
static boolean callBoolean(VirtualFrame frame, int left, double right,
287289
@Cached("getBuiltin(right)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
288290
return function.executeBool(frame, left, right);
289291
}
290292

291293
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
292-
boolean callBoolean(VirtualFrame frame, double left, int right,
294+
static boolean callBoolean(VirtualFrame frame, double left, int right,
293295
@Cached("getBuiltin(left)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
294296
return function.executeBool(frame, left, right);
295297
}
296298

297299
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
298-
double callDouble(VirtualFrame frame, int left, double right,
300+
static double callDouble(VirtualFrame frame, int left, double right,
299301
@Cached("getBuiltin(right)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
300302
return function.executeDouble(frame, left, right);
301303
}
302304

303305
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
304-
double callDouble(VirtualFrame frame, double left, int right,
306+
static double callDouble(VirtualFrame frame, double left, int right,
305307
@Cached("getBuiltin(left)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
306308
return function.executeDouble(frame, left, right);
307309
}
308310

309311
// long, double
310312

311313
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
312-
boolean callBoolean(VirtualFrame frame, long left, double right,
314+
static boolean callBoolean(VirtualFrame frame, long left, double right,
313315
@Cached("getBuiltin(right)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
314316
return function.executeBool(frame, left, right);
315317
}
316318

317319
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
318-
boolean callBoolean(VirtualFrame frame, double left, long right,
320+
static boolean callBoolean(VirtualFrame frame, double left, long right,
319321
@Cached("getBuiltin(left)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
320322
return function.executeBool(frame, left, right);
321323
}
322324

323325
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
324-
double callDouble(VirtualFrame frame, long left, double right,
326+
static double callDouble(VirtualFrame frame, long left, double right,
325327
@Cached("getBuiltin(right)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
326328
return function.executeDouble(frame, left, right);
327329
}
328330

329331
@Specialization(guards = "function != null", rewriteOn = UnexpectedResultException.class)
330-
double callDouble(VirtualFrame frame, double left, long right,
332+
static double callDouble(VirtualFrame frame, double left, long right,
331333
@Cached("getBuiltin(left)") PythonBinaryBuiltinNode function) throws UnexpectedResultException {
332334
return function.executeDouble(frame, left, right);
333335
}
@@ -356,7 +358,7 @@ boolean callBoolean(VirtualFrame frame, double left, double right,
356358

357359
// Object, Object
358360

359-
@Specialization(guards = {"!isReversible()"}, limit = "2")
361+
@Specialization(guards = {"!isReversible()"}, limit = "5")
360362
Object callObject(VirtualFrame frame, Object left, Object right,
361363
@CachedLibrary("left") PythonObjectLibrary libLeft,
362364
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr) {
@@ -373,8 +375,15 @@ Object callObject(VirtualFrame frame, Object left, Object right,
373375
return ensureDispatch().executeObject(frame, leftCallable, leftValue, right);
374376
}
375377

376-
@Specialization(guards = {"isReversible()"}, limit = "4")
377-
Object callObject(VirtualFrame frame, Object left, Object right,
378+
@Specialization(guards = {"!isReversible()"}, replaces = "callObject")
379+
Object callObjectUncached(VirtualFrame frame, Object left, Object right,
380+
@CachedLibrary(limit = "1") PythonObjectLibrary libLeft,
381+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr) {
382+
return callObject(frame, left, right, libLeft, getattr);
383+
}
384+
385+
@Specialization(guards = {"isReversible()"}, limit = "5")
386+
Object callObjectR(VirtualFrame frame, Object left, Object right,
378387
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
379388
@Cached("create(rname, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
380389
@CachedLibrary("left") PythonObjectLibrary libLeft,
@@ -424,6 +433,18 @@ Object callObject(VirtualFrame frame, Object left, Object right,
424433
return result;
425434
}
426435

436+
@Specialization(guards = {"isReversible()"}, replaces = "callObjectR")
437+
Object callObjectRUncached(VirtualFrame frame, Object left, Object right,
438+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
439+
@Cached("create(rname, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
440+
@CachedLibrary(limit = "1") PythonObjectLibrary libLeft,
441+
@CachedLibrary(limit = "1") PythonObjectLibrary libRight,
442+
@Cached("create()") TypeNodes.IsSameTypeNode isSameTypeNode,
443+
@Cached("create()") IsSubtypeNode isSubtype,
444+
@Cached("createBinaryProfile()") ConditionProfile notImplementedBranch) {
445+
return callObjectR(frame, left, right, getattr, getattrR, libLeft, libRight, isSameTypeNode, isSubtype, notImplementedBranch);
446+
}
447+
427448
private Object runErrorHandler(Object left, Object right) {
428449
if (handler == null) {
429450
CompilerDirectives.transferToInterpreterAndInvalidate();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallUnaryNode.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
4848
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
4949
import com.oracle.graal.python.nodes.object.GetClassNode;
50+
import com.oracle.graal.python.runtime.PythonOptions;
5051
import com.oracle.graal.python.util.Supplier;
5152
import com.oracle.truffle.api.CompilerDirectives;
5253
import com.oracle.truffle.api.dsl.Cached;
@@ -61,6 +62,7 @@
6162
import com.oracle.truffle.api.profiles.ConditionProfile;
6263

6364
@ReportPolymorphism
65+
@ImportStatic(PythonOptions.class)
6466
public abstract class LookupAndCallUnaryNode extends Node {
6567

6668
public abstract static class NoAttributeHandler extends PNodeWithContext {
@@ -214,7 +216,7 @@ static Object callObject(VirtualFrame frame, PNone receiver,
214216

215217
// Object
216218

217-
@Specialization
219+
@Specialization(limit = "5")
218220
Object callObject(VirtualFrame frame, Object receiver,
219221
@CachedLibrary("receiver") PythonObjectLibrary lib,
220222
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
@@ -234,6 +236,14 @@ Object callObject(VirtualFrame frame, Object receiver,
234236
}
235237
}
236238

239+
@Specialization(replaces = "callObject")
240+
Object callObjectUncached(VirtualFrame frame, Object receiver,
241+
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
242+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
243+
@Cached("create()") CallUnaryMethodNode dispatchNode) {
244+
return callObject(frame, receiver, lib, getattr, dispatchNode);
245+
}
246+
237247
@GenerateUncached
238248
public abstract static class LookupAndCallUnaryDynamicNode extends PNodeWithContext {
239249

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/GetIteratorExpressionNode.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import com.oracle.graal.python.nodes.control.GetIteratorExpressionNodeGen.IsIteratorObjectNodeGen;
6161
import com.oracle.graal.python.nodes.expression.ExpressionNode;
6262
import com.oracle.graal.python.nodes.expression.UnaryOpNode;
63+
import com.oracle.graal.python.runtime.PythonOptions;
6364
import com.oracle.graal.python.runtime.exception.PException;
6465
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
6566
import com.oracle.truffle.api.dsl.Cached;
@@ -102,7 +103,7 @@ static Object doGeneric(Object value,
102103
@CachedLibrary(limit = "3") PythonObjectLibrary methodLib,
103104
@Cached IsIteratorObjectNode isIteratorObjectNode,
104105
@Cached PythonObjectFactory factory,
105-
@Cached.Shared("raiseNode") @Cached PRaiseNode raiseNode) {
106+
@Cached PRaiseNode raiseNode) {
106107
// NOTE: it's fine to pass 'null' frame since the caller must already take care of the
107108
// global state
108109
return GetIteratorNode.doGeneric(null, value, getattributeProfile, plib, methodLib, isIteratorObjectNode, factory,
@@ -111,7 +112,7 @@ static Object doGeneric(Object value,
111112

112113
@Specialization
113114
static PythonObject doNone(PNone none,
114-
@Cached.Shared("raiseNode") @Cached PRaiseNode raiseNode) {
115+
@Cached PRaiseNode raiseNode) {
115116
return GetIteratorNode.doNone(none, raiseNode);
116117
}
117118

@@ -124,7 +125,7 @@ public static GetIteratorWithoutFrameNode getUncached() {
124125
}
125126
}
126127

127-
@ImportStatic(PGuards.class)
128+
@ImportStatic({PGuards.class, PythonOptions.class})
128129
public abstract static class GetIteratorNode extends Node {
129130
public abstract Object executeWith(VirtualFrame frame, Object value);
130131

@@ -133,14 +134,14 @@ static PythonObject doPZip(PZip value) {
133134
return value;
134135
}
135136

136-
@Specialization(guards = {"!isNoValue(value)"}, limit = "4")
137+
@Specialization(guards = {"!isNoValue(value)"}, limit = "5")
137138
static Object doGeneric(VirtualFrame frame, Object value,
138139
@Cached("createIdentityProfile()") ValueProfile iterMethodProfile,
139140
@CachedLibrary("value") PythonObjectLibrary plib,
140141
@CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
141142
@Cached IsIteratorObjectNode isIteratorObjectNode,
142143
@Cached PythonObjectFactory factory,
143-
@Cached.Shared("raiseNode") @Cached PRaiseNode raiseNode) {
144+
@Cached PRaiseNode raiseNode) {
144145
Object v = plib.getDelegatedValue(value);
145146
Object iterMethod = iterMethodProfile.profile(plib.lookupAttributeOnType(value, __ITER__));
146147
if (iterMethod != PNone.NONE) {
@@ -160,6 +161,17 @@ static Object doGeneric(VirtualFrame frame, Object value,
160161
throw notIterable(raiseNode, v);
161162
}
162163

164+
@Specialization(guards = {"!isNoValue(value)"}, replaces = "doGeneric")
165+
static Object doGenericUncached(VirtualFrame frame, Object value,
166+
@Cached("createIdentityProfile()") ValueProfile iterMethodProfile,
167+
@CachedLibrary(limit = "2") PythonObjectLibrary plib,
168+
@CachedLibrary(limit = "2") PythonObjectLibrary methodLib,
169+
@Cached IsIteratorObjectNode isIteratorObjectNode,
170+
@Cached PythonObjectFactory factory,
171+
@Cached PRaiseNode raiseNode) {
172+
return doGeneric(frame, value, iterMethodProfile, plib, methodLib, isIteratorObjectNode, factory, raiseNode);
173+
}
174+
163175
@Specialization
164176
static PythonObject doNone(PNone none,
165177
@Cached PRaiseNode raiseNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ private static final class EngineOptionValues implements OptionValues {
385385
}
386386
}
387387

388+
@Override
388389
public OptionDescriptors getDescriptors() {
389390
throw new UnsupportedOperationException();
390391
}
@@ -403,6 +404,7 @@ public int hashCode() {
403404
return engineOptions.hashCode();
404405
}
405406

407+
@Override
406408
@SuppressWarnings("unchecked")
407409
public <T> T get(OptionKey<T> optionKey) {
408410
if (engineOptions.containsKey(optionKey)) {
@@ -412,10 +414,12 @@ public <T> T get(OptionKey<T> optionKey) {
412414
}
413415
}
414416

417+
@Override
415418
public boolean hasBeenSet(OptionKey<?> optionKey) {
416419
return engineOptions.containsKey(optionKey);
417420
}
418421

422+
@Override
419423
@SuppressWarnings("deprecation")
420424
public <T> void set(OptionKey<T> optionKey, T value) {
421425
throw new UnsupportedOperationException();

0 commit comments

Comments
 (0)