this repo has no description

Re-name variables in definite assignment analysis

authored by bernsteinbear.com and committed by

Max Bernstein 20608ba2 6d57ee64

+12 -12
+12 -12
library/compiler/pyassem.py
··· 600 600 num_locals = len(self.varnames) 601 601 Top = 2**num_locals - 1 602 602 # map of block id -> assignment state in lattice 603 - live_out = [Top] * self.block_count 603 + assigned_out = [Top] * self.block_count 604 604 conditionally_assigned = set() 605 605 argcount = ( 606 606 len(self.args) ··· 623 623 def process_one_block(block, modify=False): 624 624 bid = block.bid 625 625 if len(preds[bid]) == 0: 626 - # No preds; all parameters are live-in 627 - currently_alive = ArgsAssigned 626 + # No preds; all parameters are assigned 627 + assigned = ArgsAssigned 628 628 else: 629 - # Meet the live-out sets of all predecessors 630 - currently_alive = meet(live_out[pred] for pred in preds[bid]) 629 + # Meet the assigned sets of all predecessors 630 + assigned = meet(assigned_out[pred] for pred in preds[bid]) 631 631 for instr in block.getInstructions(): 632 632 if modify and instr.opname == "LOAD_FAST": 633 - if currently_alive & (1 << instr.ioparg): 633 + if assigned & (1 << instr.ioparg): 634 634 instr.opname = "LOAD_FAST_REVERSE_UNCHECKED" 635 635 instr.ioparg = reverse_local_idx(instr.ioparg) 636 636 elif instr.ioparg >= argcount: 637 637 # Exclude arguments because they come into the function 638 - # body live. Anything that makes them no longer live 639 - # will have to be DELETE_FAST. 638 + # body assigned. The only thing that can undefine them 639 + # is DELETE_FAST. 640 640 conditionally_assigned.add(instr.oparg) 641 641 elif instr.opname == "STORE_FAST": 642 - currently_alive |= 1 << instr.ioparg 642 + assigned |= 1 << instr.ioparg 643 643 if modify: 644 644 instr.opname = "STORE_FAST_REVERSE" 645 645 instr.ioparg = reverse_local_idx(instr.ioparg) 646 646 elif instr.opname == "DELETE_FAST": 647 - currently_alive &= ~(1 << instr.ioparg) 648 - if currently_alive == live_out[block.bid]: 647 + assigned &= ~(1 << instr.ioparg) 648 + if assigned == assigned_out[bid]: 649 649 return False 650 - live_out[block.bid] = currently_alive 650 + assigned_out[bid] = assigned 651 651 return True 652 652 653 653 changed = True