1 | #include "taichi/ir/ir.h" |
---|---|
2 | #include "taichi/ir/control_flow_graph.h" |
3 | #include "taichi/ir/transforms.h" |
4 | #include "taichi/ir/analysis.h" |
5 | #include "taichi/system/profiler.h" |
6 | |
7 | namespace taichi::lang { |
8 | |
9 | namespace irpass { |
10 | bool cfg_optimization( |
11 | IRNode *root, |
12 | bool after_lower_access, |
13 | bool autodiff_enabled, |
14 | bool real_matrix_enabled, |
15 | const std::optional<ControlFlowGraph::LiveVarAnalysisConfig> |
16 | &lva_config_opt) { |
17 | TI_AUTO_PROF; |
18 | auto cfg = analysis::build_cfg(root); |
19 | bool result_modified = false; |
20 | if (!real_matrix_enabled) { |
21 | cfg->simplify_graph(); |
22 | if (cfg->store_to_load_forwarding(after_lower_access, autodiff_enabled)) |
23 | result_modified = true; |
24 | if (cfg->dead_store_elimination(after_lower_access, lva_config_opt)) |
25 | result_modified = true; |
26 | } |
27 | // TODO: implement cfg->dead_instruction_elimination() |
28 | die(root); // remove unused allocas |
29 | return result_modified; |
30 | } |
31 | } // namespace irpass |
32 | |
33 | } // namespace taichi::lang |
34 |