(self)
Map SSA variables to a unified variable. Fill in self._unified_variables.
Map SSA variables to a unified variable. Fill in self._unified_variables.
Map SSA variables to a unified variable . Fill in self . _unified_variables .
def unify_variables(self) -> None:
        """
        Map SSA variables to a unified variable. Fill in self._unified_variables.
        """

        stack_vars: Dict[int,List[SimStackVariable]] = defaultdict(list)
        reg_vars: Set[SimRegisterVariable] = set()

        # unify stack variables based on their locations
        for v in self.get_variables():
            if v in self._variables_to_unified_variables:
                # do not unify twice
                continue
            if isinstance(v, SimStackVariable):
                stack_vars[v.offset].append(v)
            elif isinstance(v, SimRegisterVariable):
                reg_vars.add(v)

        for _, vs in stack_vars.items():
            unified = vs[0].copy()
            for v in vs:
                self.set_unified_variable(v, unified)

        # unify register variables based on phi nodes
        graph = networkx.Graph()
        for v, subvs in self._phi_variables.items():
            if not isinstance(v, SimRegisterVariable):
                continue
            if not self.get_variable_accesses(v):
                # this phi node has never been used - discard it
                continue
            for subv in subvs:
                graph.add_edge(v, subv)

        for nodes in networkx.connected_components(graph):
            if len(nodes) <= 1:
                continue
            nodes = list(nodes)
            unified = nodes[0].copy()
            for v in nodes:
                self.set_unified_variable(v, unified)
            for v in nodes:
                reg_vars.discard(v)

        for v in reg_vars:
            self.set_unified_variable(v, v)
def unify_variables ( self ) -> None : stack_vars : Dict [ int , List [ SimStackVariable ] ] = defaultdict ( list ) reg_vars : Set [ SimRegisterVariable ] = set ( ) # unify stack variables based on their locations for v in self . get_variables ( ) : if v in self . _variables_to_unified_variables : # do not unify twice continue if isinstance ( v , SimStackVariable ) : stack_vars [ v . offset ] . append ( v ) elif isinstance ( v , SimRegisterVariable ) : reg_vars . add ( v ) for _ , vs in stack_vars . items ( ) : unified = vs [ 0 ] . copy ( ) for v in vs : self . set_unified_variable ( v , unified ) # unify register variables based on phi nodes graph = networkx . Graph ( ) for v , subvs in self . _phi_variables . items ( ) : if not isinstance ( v , SimRegisterVariable ) : continue if not self . get_variable_accesses ( v ) : # this phi node has never been used - discard it continue for subv in subvs : graph . add_edge ( v , subv ) for nodes in networkx . connected_components ( graph ) : if len ( nodes ) <= 1 : continue nodes = list ( nodes ) unified = nodes [ 0 ] . copy ( ) for v in nodes : self . set_unified_variable ( v , unified ) for v in nodes : reg_vars . discard ( v ) for v in reg_vars : self . set_unified_variable ( v , v )