File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -211,6 +211,21 @@ def visitBinOp(self, node: ast.BinOp) -> ast.expr:
211
211
class PyroFlowGraph (PyFlowGraph38 ):
212
212
opcode = opcodepyro .opcode
213
213
214
+ def optimizeStoreUnderscore (self ):
215
+ for block in self .getBlocksInOrder ():
216
+ for instr in block .getInstructions ():
217
+ if (
218
+ instr .opname == "LOAD_FAST" or instr .opname == "DELETE_FAST"
219
+ ) and instr .oparg == "_" :
220
+ return
221
+ # We never read from or delete _, so we can replace all stores to it
222
+ # with POP_TOP.
223
+ for block in self .getBlocksInOrder ():
224
+ for instr in block .getInstructions ():
225
+ if instr .opname == "STORE_FAST" and instr .oparg == "_" :
226
+ instr .opname = "POP_TOP"
227
+ instr .oparg = None
228
+
214
229
def optimizeLoadFast (self ):
215
230
blocks = self .getBlocksInOrder ()
216
231
preds = tuple (set () for i in range (self .block_count ))
@@ -297,6 +312,7 @@ def process_one_block(block, modify=False):
297
312
self .entry .insts = deletes + self .entry .insts
298
313
299
314
def getCode (self ):
315
+ self .optimizeStoreUnderscore ()
300
316
self .optimizeLoadFast ()
301
317
return super ().getCode ()
302
318
You can’t perform that action at this time.
0 commit comments