@@ -900,10 +900,9 @@ def propagate(self, ssa, head, max_expr_depth=None):
900
900
for dst , src in out .iteritems ():
901
901
if dst .is_mem ():
902
902
write_mem = True
903
- if dst != mem_dst and mem_dst in dst :
904
- dst = dst .replace_expr ({mem_dst :mem_src })
905
- if mem_dst in src :
906
- src = src .replace_expr ({mem_dst :mem_src })
903
+ ptr = dst .ptr .replace_expr ({mem_dst :mem_src })
904
+ dst = ExprMem (ptr , dst .size )
905
+ src = src .replace_expr ({mem_dst :mem_src })
907
906
out_new [dst ] = src
908
907
if out != out_new :
909
908
assignblk_modified = True
@@ -990,15 +989,15 @@ def check_expr_below_stack(ir_arch_a, expr):
990
989
return True
991
990
992
991
993
- def retrieve_stack_accesses (ir_arch_a , ssa ):
992
+ def retrieve_stack_accesses (ir_arch_a , ircfg ):
994
993
"""
995
994
Walk the ssa graph and find stack based variables.
996
995
Return a dictionary linking stack base address to its size/name
997
996
@ir_arch_a: ira instance
998
- @ssa: SSADiGraph instance
997
+ @ircfg: IRCFG instance
999
998
"""
1000
999
stack_vars = set ()
1001
- for block in ssa . graph .blocks .itervalues ():
1000
+ for block in ircfg .blocks .itervalues ():
1002
1001
for assignblk in block :
1003
1002
for dst , src in assignblk .iteritems ():
1004
1003
stack_vars .update (get_stack_accesses (ir_arch_a , dst ))
@@ -1064,18 +1063,23 @@ def replace_mem_stack_vars(expr, base_to_info):
1064
1063
return expr .visit (lambda expr :fix_stack_vars (expr , base_to_info ))
1065
1064
1066
1065
1067
- def replace_stack_vars (ir_arch_a , ssa ):
1066
+ def replace_stack_vars (ir_arch_a , ircfg ):
1068
1067
"""
1069
1068
Try to replace stack based memory accesses by variables.
1069
+
1070
+ Hypothesis: the input ircfg must have all it's accesses to stack explicitly
1071
+ done through the stack register, ie every aliases on those variables is
1072
+ resolved.
1073
+
1070
1074
WARNING: may fail
1071
1075
1072
1076
@ir_arch_a: ira instance
1073
- @ssa: SSADiGraph instance
1077
+ @ircfg: IRCFG instance
1074
1078
"""
1075
1079
1076
- base_to_info = retrieve_stack_accesses (ir_arch_a , ssa )
1080
+ base_to_info = retrieve_stack_accesses (ir_arch_a , ircfg )
1077
1081
modified = False
1078
- for block in ssa . graph .blocks .itervalues ():
1082
+ for block in ircfg .blocks .itervalues ():
1079
1083
assignblks = []
1080
1084
for assignblk in block :
1081
1085
out = {}
@@ -1090,7 +1094,7 @@ def replace_stack_vars(ir_arch_a, ssa):
1090
1094
out = AssignBlock (out , assignblk .instr )
1091
1095
assignblks .append (out )
1092
1096
new_block = IRBlock (block .loc_key , assignblks )
1093
- ssa . graph .blocks [block .loc_key ] = new_block
1097
+ ircfg .blocks [block .loc_key ] = new_block
1094
1098
return modified
1095
1099
1096
1100
0 commit comments