forked from pfalcon/ScratchABlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_i_preserveds.py
51 lines (39 loc) · 1.56 KB
/
script_i_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):
# script_i_prepare was run before this
analyze_reach_defs(cfg)
# Need to do before DCE and even before insert_initial_regs
collect_reach_exit(cfg)
collect_reach_exit_maybe(cfg)
# analyze_live_vars uses modifieds, so if preserveds is available, we need
# to update modifieds for possible update in reach_exit, otherwise we'll
# have positive feedback in propagation and bad flip-flop effect for preserveds
# value.
if "preserveds" in cfg.props:
modifieds = cfg.props["reach_exit"] - cfg.props["preserveds"]
progdb.update_cfg_prop(cfg, "modifieds", modifieds)
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)
modifieds = cfg.props["reach_exit"] - cfg.props["preserveds"]
progdb.update_cfg_prop(cfg, "modifieds", modifieds)
#
# 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)