|
72 | 72 | import com.oracle.graal.python.builtins.objects.asyncio.PAsyncGenWrappedValue; |
73 | 73 | import com.oracle.graal.python.builtins.objects.cell.PCell; |
74 | 74 | import com.oracle.graal.python.builtins.objects.code.PCode; |
| 75 | +import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage; |
75 | 76 | import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage; |
76 | 77 | import com.oracle.graal.python.builtins.objects.common.HashingStorage; |
77 | 78 | import com.oracle.graal.python.builtins.objects.common.HashingStorageNodes.HashingStorageSetItem; |
|
151 | 152 | import com.oracle.graal.python.lib.PyObjectFunctionStr; |
152 | 153 | import com.oracle.graal.python.lib.PyObjectGetAttr; |
153 | 154 | import com.oracle.graal.python.lib.PyObjectGetItem; |
| 155 | +import com.oracle.graal.python.lib.PyObjectGetItem.PyObjectGetItemOrNull; |
154 | 156 | import com.oracle.graal.python.lib.PyObjectGetIter; |
155 | 157 | import com.oracle.graal.python.lib.PyObjectGetMethod; |
156 | 158 | import com.oracle.graal.python.lib.PyObjectHashNode; |
|
178 | 180 | import com.oracle.graal.python.nodes.argument.keywords.NonMappingException; |
179 | 181 | import com.oracle.graal.python.nodes.argument.keywords.SameDictKeyException; |
180 | 182 | import com.oracle.graal.python.nodes.attributes.GetFixedAttributeNode; |
| 183 | +import com.oracle.graal.python.nodes.attributes.ReadAttributeFromPythonObjectNode; |
181 | 184 | import com.oracle.graal.python.nodes.builtins.ListNodes; |
182 | 185 | import com.oracle.graal.python.nodes.bytecode.CopyDictWithoutKeysNode; |
183 | 186 | import com.oracle.graal.python.nodes.bytecode.GetAIterNode; |
|
211 | 214 | import com.oracle.graal.python.nodes.frame.ReadBuiltinNode; |
212 | 215 | import com.oracle.graal.python.nodes.frame.ReadFromLocalsNode; |
213 | 216 | import com.oracle.graal.python.nodes.frame.ReadGlobalOrBuiltinNode; |
214 | | -import com.oracle.graal.python.nodes.frame.ReadNameNode; |
215 | 217 | import com.oracle.graal.python.nodes.frame.WriteGlobalNode; |
216 | 218 | import com.oracle.graal.python.nodes.frame.WriteNameNode; |
217 | 219 | import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile; |
|
259 | 261 | import com.oracle.truffle.api.bytecode.ContinuationRootNode; |
260 | 262 | import com.oracle.truffle.api.bytecode.EpilogExceptional; |
261 | 263 | import com.oracle.truffle.api.bytecode.EpilogReturn; |
| 264 | +import com.oracle.truffle.api.bytecode.ForceQuickening; |
262 | 265 | import com.oracle.truffle.api.bytecode.GenerateBytecode; |
263 | 266 | import com.oracle.truffle.api.bytecode.Instruction; |
264 | 267 | import com.oracle.truffle.api.bytecode.Instrumentation; |
|
349 | 352 | @OperationProxy(SetupAnnotationsNode.class) |
350 | 353 | @OperationProxy(GetAIterNode.class) |
351 | 354 | @OperationProxy(GetANextNode.class) |
| 355 | +@OperationProxy(value = ReadGlobalOrBuiltinNode.class, name = "ReadGlobal") |
352 | 356 | @OperationProxy(value = CopyDictWithoutKeysNode.class, name = "CopyDictWithoutKeys") |
353 | 357 | @OperationProxy(value = PyObjectIsTrueNode.class, name = "Yes") |
354 | 358 | @OperationProxy(value = PyObjectIsNotTrueNode.class, name = "Not") |
@@ -1223,13 +1227,42 @@ public static void perform(VirtualFrame frame, TruffleString name, Object value, |
1223 | 1227 | } |
1224 | 1228 | } |
1225 | 1229 |
|
1226 | | - @Operation(storeBytecodeIndex = true) |
| 1230 | + @Operation(storeBytecodeIndex = false) |
1227 | 1231 | @ConstantOperand(type = TruffleString.class) |
| 1232 | + @ImportStatic(PGuards.class) |
1228 | 1233 | public static final class ReadName { |
1229 | | - @Specialization |
1230 | | - public static Object perform(VirtualFrame frame, TruffleString name, |
1231 | | - @Cached ReadNameNode readNode) { |
1232 | | - return readNode.execute(frame, name); |
| 1234 | + static Object readFromLocalsFastPath(VirtualFrame frame, TruffleString attributeId, ReadAttributeFromPythonObjectNode readNode) { |
| 1235 | + Object specialArgument = PArguments.getSpecialArgument(frame); |
| 1236 | + if (specialArgument instanceof PDict dict && dict.getDictStorage() instanceof DynamicObjectStorage s) { |
| 1237 | + return readNode.execute(s.getStore(), attributeId, PNone.NO_VALUE); |
| 1238 | + } |
| 1239 | + return PNone.NO_VALUE; |
| 1240 | + } |
| 1241 | + |
| 1242 | + @ForceQuickening |
| 1243 | + @Specialization(guards = "!isNoValue(result)", limit = "1") |
| 1244 | + public static Object doLocalFastPath(VirtualFrame frame, TruffleString name, |
| 1245 | + @Cached ReadAttributeFromPythonObjectNode readAttrNode, |
| 1246 | + @Bind("readFromLocalsFastPath(frame, name, readAttrNode)") Object result) { |
| 1247 | + return result; |
| 1248 | + } |
| 1249 | + |
| 1250 | + @StoreBytecodeIndex |
| 1251 | + @Specialization(replaces = "doLocalFastPath") |
| 1252 | + public static Object doFull(VirtualFrame frame, TruffleString name, |
| 1253 | + @Bind Node inliningTarget, |
| 1254 | + @Cached PyObjectGetItemOrNull getLocal, |
| 1255 | + @Cached ReadGlobalOrBuiltinNode readGlobalOrBuiltinNode, |
| 1256 | + @Cached InlinedConditionProfile hasLocalsProfile) { |
| 1257 | + Object locals = PArguments.getSpecialArgument(frame); |
| 1258 | + Object result = null; |
| 1259 | + if (hasLocalsProfile.profile(inliningTarget, locals != null)) { |
| 1260 | + result = getLocal.execute(frame, inliningTarget, locals, name); |
| 1261 | + } |
| 1262 | + if (result == null) { |
| 1263 | + return readGlobalOrBuiltinNode.execute(frame, name); |
| 1264 | + } |
| 1265 | + return result; |
1233 | 1266 | } |
1234 | 1267 | } |
1235 | 1268 |
|
@@ -1640,16 +1673,6 @@ public static void doWithFrame(VirtualFrame frame, Object primary, Object index, |
1640 | 1673 | } |
1641 | 1674 | } |
1642 | 1675 |
|
1643 | | - @Operation(storeBytecodeIndex = true) |
1644 | | - @ConstantOperand(type = TruffleString.class) |
1645 | | - public static final class ReadGlobal { |
1646 | | - @Specialization |
1647 | | - public static Object perform(VirtualFrame frame, TruffleString name, |
1648 | | - @Cached ReadGlobalOrBuiltinNode readNode) { |
1649 | | - return readNode.execute(frame, name); |
1650 | | - } |
1651 | | - } |
1652 | | - |
1653 | 1676 | @Operation(storeBytecodeIndex = true) |
1654 | 1677 | @ConstantOperand(type = TruffleString.class) |
1655 | 1678 | public static final class WriteGlobal { |
@@ -2676,7 +2699,7 @@ public static Object doLoadCell(VirtualFrame frame, TruffleString name, Object d |
2676 | 2699 | value = getItemNode.execute(frame, inliningTarget, dict, name); |
2677 | 2700 | } catch (PException e) { |
2678 | 2701 | e.expect(inliningTarget, KeyError, errorProfile); |
2679 | | - value = readGlobal.read(frame, PArguments.getGlobals(frame), name); |
| 2702 | + value = readGlobal.execute(frame, name); |
2680 | 2703 | } |
2681 | 2704 | return value; |
2682 | 2705 | } |
|
0 commit comments