1 | #include "taichi/ir/analysis.h" |
---|---|
2 | #include "taichi/ir/control_flow_graph.h" |
3 | #include "taichi/ir/ir.h" |
4 | #include "taichi/ir/statements.h" |
5 | #include "taichi/ir/transforms.h" |
6 | |
7 | #include <queue> |
8 | #include <unordered_map> |
9 | |
10 | namespace taichi::lang { |
11 | |
12 | namespace irpass { |
13 | |
14 | bool determine_ad_stack_size(IRNode *root, const CompileConfig &config) { |
15 | if (irpass::analysis::gather_statements(root, [&](Stmt *s) { |
16 | if (auto ad_stack = s->cast<AdStackAllocaStmt>()) { |
17 | return ad_stack->max_size == 0; // adaptive |
18 | } |
19 | return false; |
20 | }).empty()) { |
21 | return false; // no AD-stacks with adaptive size |
22 | } |
23 | auto cfg = analysis::build_cfg(root); |
24 | cfg->simplify_graph(); |
25 | cfg->determine_ad_stack_size(config.default_ad_stack_size); |
26 | return true; |
27 | } |
28 | |
29 | } // namespace irpass |
30 | |
31 | } // namespace taichi::lang |
32 |