1 | #include "taichi/ir/ir.h" |
---|---|
2 | #include "taichi/ir/statements.h" |
3 | #include "taichi/ir/transforms.h" |
4 | #include "taichi/ir/visitors.h" |
5 | #include "taichi/system/profiler.h" |
6 | |
7 | namespace taichi::lang { |
8 | |
9 | namespace { |
10 | |
11 | // Remove all the assume in range statements. |
12 | // These statements are useless after make_block_local. |
13 | // Their existence harms IR optimization quality. |
14 | |
15 | class RemoveRangeAssumption : public BasicStmtVisitor { |
16 | public: |
17 | using BasicStmtVisitor::visit; |
18 | DelayedIRModifier modifier; |
19 | |
20 | void visit(RangeAssumptionStmt *stmt) override { |
21 | stmt->replace_usages_with(stmt->input); |
22 | modifier.erase(stmt); |
23 | } |
24 | |
25 | static bool run(IRNode *node) { |
26 | RemoveRangeAssumption pass; |
27 | node->accept(&pass); |
28 | return pass.modifier.modify_ir(); |
29 | } |
30 | }; |
31 | |
32 | } // namespace |
33 | |
34 | namespace irpass { |
35 | |
36 | bool remove_range_assumption(IRNode *root) { |
37 | TI_AUTO_PROF; |
38 | return RemoveRangeAssumption::run(root); |
39 | } |
40 | |
41 | } // namespace irpass |
42 | |
43 | } // namespace taichi::lang |
44 |