1919
2020from copy import deepcopy
2121
22- from decompiler .util .decoration import DecoratedCFG
22+ from decompiler .util .decoration import DecoratedCFG , DecoratedGraph
2323
2424
2525class SreedharOutOfSsa :
@@ -108,7 +108,7 @@ def _gen_new_name(self, x: Variable):
108108 t = x .name + (str (x .ssa_label ) if x .ssa_label else "" )
109109 c = self ._new_name_map .get (t , 0 ) + 1
110110 self ._new_name_map [t ] = c
111- return t + "'" * c
111+ return t + "\ ' " * c
112112
113113 def _insert_before_branch (self , instrs , instr ):
114114 for i in range (len (instrs )- 1 , - 1 , - 1 ):
@@ -145,7 +145,7 @@ def _add_interference_edges(self, var, vars):
145145 def _insert_copy (self , x , instr : Phi ):
146146 is_req = x in instr .requirements
147147 orig_block = self ._get_orig_block (instr , x )
148- x_new = expressions .Variable (self ._gen_new_name (x ), x .type )
148+ x_new = expressions .Variable (self ._gen_new_name (x ), x .type , ssa_label = 1 )
149149 copy_instr = Assignment (x_new , x ) if is_req else Assignment (x , x_new )
150150 live_set = self ._live_out [orig_block ] if is_req else self ._live_in [orig_block ]
151151 block_instrs = orig_block .instructions
@@ -155,7 +155,6 @@ def _insert_copy(self, x, instr: Phi):
155155 instr .substitute (x , x_new )
156156 self ._live_out [orig_block ].add (x_new )
157157 self ._prune_dead_out (x , orig_block )
158- self ._add_interference_edges (x , self ._live_out [orig_block ])
159158 else :
160159 self ._insert_after_phis (block_instrs , copy_instr )
161160 instr .rename_destination (x , x_new )
@@ -210,11 +209,10 @@ def _resolve_unresolved_neighbors(self, candidates, unresolved):
210209 if unresolved [x ].issubset (resolved ):
211210 candidates .discard (x )
212211
213- def _prune_singleton_phi_classes (self ):
214- self ._phi_congruence_class = {
215- k : v for k , v in self ._phi_congruence_class .items ()
216- if not (isinstance (v , set ) and len (v ) == 1 )
217- }
212+ def _nullify_singleton_phi_classes (self ):
213+ for k , v in self ._phi_congruence_class .items ():
214+ if isinstance (v , set ) and len (v ) == 1 :
215+ self ._phi_congruence_class [k ] = set ()
218216
219217 def _eliminate_phi_resource_interference (self ):
220218 self ._init_phi_congruence_classes ()
@@ -239,10 +237,7 @@ def _eliminate_phi_resource_interference(self):
239237 # Note phi_resources has changed due to _insert_copy
240238 self ._merge_phi_congruence_classes (instr .destination , * instr .requirements )
241239
242- #DecoratedCFG.print_ascii(self.cfg)
243- ##print('-'*100)
244-
245- self ._prune_singleton_phi_classes ()
240+ self ._nullify_singleton_phi_classes ()
246241
247242
248243 def _handle_Relations (self ):
@@ -256,7 +251,6 @@ def _handle_Relations(self):
256251 self ._merge_phi_congruence_classes (instr .value ,instr .destination )
257252
258253 def _remove_unnecessary_copies (self ):
259- #self._interference_graph = InterferenceGraph(self.cfg)
260254 self ._handle_Relations ()
261255 for bb in self .cfg :
262256 for inst in bb :
@@ -337,5 +331,5 @@ def _leave_CSSA(self):
337331
338332 def perform (self ):
339333 self ._eliminate_phi_resource_interference () #Step 1: Translation to CSSA
340- self ._remove_unnecessary_copies () #Step 2 : Eliminate redundant copies
334+ self ._remove_unnecessary_copies () #Step 3 : Eliminate redundant copies
341335 self ._leave_CSSA () #Step 3: Eliminate phi instructions and use phi-congruence-property
0 commit comments