github/workflows/pycopy-test: Upgrade Pycopy to 3.6.1.
[ScratchABlock.git] / script_i_preserveds.py
blob040894be82c54104db7dfdcfd3cabe27b0a6bf3d
1 from xform import *
2 from dataflow import *
4 def apply(cfg):
5 # script_i_prepare was run before this
7 analyze_reach_defs(cfg)
8 # Need to do before DCE and even before insert_initial_regs
9 collect_reach_exit(cfg)
10 collect_reach_exit_maybe(cfg)
12 # analyze_live_vars uses modifieds, so if preserveds is available, we need
13 # to update modifieds for possible update in reach_exit, otherwise we'll
14 # have positive feedback in propagation and bad flip-flop effect for preserveds
15 # value.
16 if "preserveds" in cfg.props:
17 modifieds = cfg.props["reach_exit"] - cfg.props["preserveds"]
18 progdb.update_cfg_prop(cfg, "modifieds", modifieds)
20 analyze_live_vars(cfg)
21 insert_initial_regs(cfg)
23 analyze_reach_defs(cfg)
25 #const_propagation(cfg)
26 #copy_propagation(cfg)
27 #mem_propagation(cfg)
28 # May infinite-loop without $sp_0, etc.
29 expr_propagation(cfg)
31 # To rewrite stack vars, we need to propagate $sp_0, hence all the above
32 foreach_inst(cfg, rewrite_stack_vars, rewrite_to=REG)
34 # Now need to do second propagation phase, of stack vars
35 analyze_reach_defs(cfg)
36 expr_propagation(cfg)
38 # Analyze and record preserved registers
39 collect_preserveds(cfg)
41 modifieds = cfg.props["reach_exit"] - cfg.props["preserveds"]
42 progdb.update_cfg_prop(cfg, "modifieds", modifieds)
45 # Argument estimation part
48 # Reanalyze live vars for DCE
49 analyze_live_vars(cfg)
50 # Eliminate any preservation assignments, and thus liveness of preserved regs
51 foreach_bblock(cfg, dead_code_elimination)