Skip to content

Commit 5b2ba78

Browse files
committed
Use cached specializations for NbNumbers calls
1 parent 3feb308 commit 5b2ba78

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

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

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,27 @@ protected abstract static class PyNumberAddNode extends LookupAndCallNbNumbersBi
9090
super(handlerFactory);
9191
}
9292

93-
@Specialization
93+
@Specialization(guards = {"left.getClass() == cachedLeftClass", "right.getClass() == cachedRightClass"}, limit = "5")
94+
Object addC(VirtualFrame frame, Object left, Object right,
95+
@Bind("this") Node node,
96+
@SuppressWarnings("unused") @Cached("left.getClass()") Class<?> cachedLeftClass,
97+
@SuppressWarnings("unused") @Cached("right.getClass()") Class<?> cachedRightClass,
98+
@Cached InlinedGetClassNode getClassNode,
99+
@Cached("create(Add)") LookupSpecialMethodSlotNode getattr,
100+
@Cached GetMethodsFlagsNode getMethodsFlagsNode,
101+
@Cached InlinedGetClassNode getlClassNode,
102+
@Cached InlinedGetClassNode getrClassNode,
103+
@Cached InlinedConditionProfile p1,
104+
@Cached InlinedConditionProfile p2,
105+
@Cached InlinedConditionProfile p3,
106+
@Cached BinaryOp1Node binaryOp1Node,
107+
@Cached Slot1BINFULLNode slot1BINFULLNode) {
108+
return add(frame, left, right, node, getClassNode, getattr, getMethodsFlagsNode,
109+
getlClassNode, getrClassNode, p1, p2, p3,
110+
binaryOp1Node, slot1BINFULLNode);
111+
}
112+
113+
@Specialization(replaces = "addC")
94114
Object add(VirtualFrame frame, Object left, Object right,
95115
@Bind("this") Node node,
96116
@Cached InlinedGetClassNode getClassNode,
@@ -145,7 +165,26 @@ protected abstract static class PyNumberMultiplyNode extends LookupAndCallNbNumb
145165
super(handlerFactory);
146166
}
147167

148-
@Specialization
168+
@Specialization(guards = {"left.getClass() == cachedLeftClass", "right.getClass() == cachedRightClass"}, limit = "5")
169+
Object mulC(VirtualFrame frame, Object left, Object right,
170+
@Bind("this") Node node,
171+
@SuppressWarnings("unused") @Cached("left.getClass()") Class<?> cachedLeftClass,
172+
@SuppressWarnings("unused") @Cached("right.getClass()") Class<?> cachedRightClass,
173+
@Cached InlinedGetClassNode getClassNode,
174+
@Cached("create(Mul)") LookupSpecialMethodSlotNode getattr,
175+
@Cached GetMethodsFlagsNode getMethodsFlagsNode,
176+
@Cached InlinedGetClassNode getlClassNode,
177+
@Cached InlinedGetClassNode getrClassNode,
178+
@Cached InlinedConditionProfile p1,
179+
@Cached InlinedConditionProfile p2,
180+
@Cached InlinedConditionProfile p3,
181+
@Cached BinaryOp1Node binaryOp1Node,
182+
@Cached Slot1BINFULLNode slot1BINFULLNode) {
183+
return mul(frame, left, right, node, getClassNode, getattr, getMethodsFlagsNode, getlClassNode,
184+
getrClassNode, p1, p2, p3, binaryOp1Node, slot1BINFULLNode);
185+
}
186+
187+
@Specialization(replaces = "mulC")
149188
Object mul(VirtualFrame frame, Object left, Object right,
150189
@Bind("this") Node node,
151190
@Cached InlinedGetClassNode getClassNode,
@@ -209,7 +248,23 @@ protected abstract static class BinaryOpNode extends LookupAndCallNbNumbersBinar
209248
this.rslot = rslot;
210249
}
211250

212-
@Specialization
251+
@Specialization(guards = {"left.getClass() == cachedLeftClass", "right.getClass() == cachedRightClass"}, limit = "5")
252+
Object binaryOpC(VirtualFrame frame, Object left, Object right,
253+
@Bind("this") Node node,
254+
@SuppressWarnings("unused") @Cached("left.getClass()") Class<?> cachedLeftClass,
255+
@SuppressWarnings("unused") @Cached("right.getClass()") Class<?> cachedRightClass,
256+
@Cached GetMethodsFlagsNode getMethodsFlagsNode,
257+
@Cached InlinedGetClassNode getlClassNode,
258+
@Cached InlinedGetClassNode getrClassNode,
259+
@Cached InlinedConditionProfile p1,
260+
@Cached InlinedConditionProfile p2,
261+
@Cached BinaryOp1Node binaryOp1Node,
262+
@Cached Slot1BINFULLNode slot1BINFULLNode) {
263+
return binaryOp(frame, left, right, node, getMethodsFlagsNode, getlClassNode, getrClassNode, p1, p2,
264+
binaryOp1Node, slot1BINFULLNode);
265+
}
266+
267+
@Specialization(replaces = "binaryOpC")
213268
Object binaryOp(VirtualFrame frame, Object left, Object right,
214269
@Bind("this") Node node,
215270
@Cached GetMethodsFlagsNode getMethodsFlagsNode,

0 commit comments

Comments
 (0)