-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathscript_preserveds.py
51 lines (38 loc) · 1.38 KB
/
script_preserveds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from xform import *
from dataflow import *
def apply(cfg):
# Various algos below don't work with no explicit entry in CFG
cfg_preheader(cfg)
# Also don't work with >1 entries
remove_unreachable_entries(cfg)
# Also don't work unless there's a single exit
cfg_single_exit(cfg)
foreach_inst(cfg, sub_const_to_add)
# Need to do before DCE and even before insert_initial_regs
collect_reach_exit(cfg)
analyze_live_vars(cfg)
insert_initial_regs(cfg)
analyze_reach_defs(cfg)
#const_propagation(cfg)
#copy_propagation(cfg)
#mem_propagation(cfg)
# May infinite-loop without $sp_0, etc.
expr_propagation(cfg)
# To rewrite stack vars, we need to propagate $sp_0, hence all the above
foreach_inst(cfg, rewrite_stack_vars, rewrite_to=REG)
# Now need to do second propagation phase, of stack vars
analyze_reach_defs(cfg)
expr_propagation(cfg)
# Analyze and record preserved registers
collect_preserveds(cfg)
cfg.props["modifieds"] = cfg.props["reach_exit"] - cfg.props["preserveds"]
#
# Argument estimation part
#
# Reanalyze live vars for DCE
analyze_live_vars(cfg)
# Eliminate any preservation assignments, and thus liveness of preserved regs
foreach_bblock(cfg, dead_code_elimination)
# Reanalyze live vars for argument estimation
analyze_live_vars(cfg)
estimate_params(cfg)