FreeTensor
Loading...
Searching...
No Matches
check_not_modified.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_CHECK_NOT_MODIFIED
2#define FREE_TENSOR_CHECK_NOT_MODIFIED
3
4#include <optional>
5#include <unordered_map>
6#include <unordered_set>
7
9#include <mutator.h>
10#include <visitor.h>
11
12namespace freetensor {
13
14enum class CheckNotModifiedSide : int { Before, After };
15
16class CheckNameToDefMapping : public SymbolTable<Visitor> {
18
19 ID pos_;
20 const std::unordered_set<std::string> &names_;
21 std::unordered_map<std::string, ID> name2def_;
22
23 public:
25 const std::unordered_set<std::string> &names)
26 : pos_(pos), names_(names) {}
27
28 const std::unordered_map<std::string, ID> &name2def() const {
29 return name2def_;
30 }
31
32 protected:
33 void visitStmt(const Stmt &stmt) override;
34};
35
38
39 ID pos_;
40 const std::unordered_set<std::string> &reads_;
41 std::unordered_map<std::string, ID> read2scope_;
42
43 public:
45 const ID &pos, const std::unordered_set<std::string> &reads)
46 : pos_(pos), reads_(reads) {}
47
48 const auto &read2scope() const { return read2scope_; }
49
50 protected:
51 void visitStmt(const Stmt &stmt) override;
52};
53
54class InsertTmpEval : public Mutator {
55 Expr s0Expr_, s1Expr_;
56 ID s0_, s1_, s0Eval_, s1Eval_;
57 CheckNotModifiedSide s0Side_, s1Side_;
58
59 public:
60 InsertTmpEval(const Expr &s0Expr, const Expr &s1Expr,
61 CheckNotModifiedSide s0Side, const ID &s0,
62 CheckNotModifiedSide s1Side, const ID &s1)
63 : s0Expr_(s0Expr), s1Expr_(s1Expr), s0_(s0), s1_(s1), s0Side_(s0Side),
64 s1Side_(s1Side) {}
65
66 const ID &s0Eval() const { return s0Eval_; }
67 const ID &s1Eval() const { return s1Eval_; }
68
69 protected:
70 Stmt visitStmt(const Stmt &op) override;
71};
72
80std::optional<bool>
81checkNotModifiedFastPreCheck(const Stmt &op, const Expr &expr,
82 CheckNotModifiedSide s0Side, const ID &s0,
83 CheckNotModifiedSide s1Side, const ID &s1);
84std::optional<bool>
85checkNotModifiedFastPreCheck(const Stmt &op, const Expr &s0Expr,
86 const Expr &s1Expr, CheckNotModifiedSide s0Side,
87 const ID &s0, CheckNotModifiedSide s1Side,
88 const ID &s1);
105bool checkNotModified(const Stmt &op, const Expr &expr,
106 CheckNotModifiedSide s0Side, const ID &s0,
107 CheckNotModifiedSide s1Side, const ID &s1);
108
120bool checkNotModified(const Stmt &op, const Expr &s0Expr, const Expr &s1Expr,
121 CheckNotModifiedSide s0Side, const ID &s0,
122 CheckNotModifiedSide s1Side, const ID &s1);
123
124} // namespace freetensor
125
126#endif // FREE_TENSOR_CHECK_NOT_MODIFIED
Definition: check_not_modified.h:16
const std::unordered_map< std::string, ID > & name2def() const
Definition: check_not_modified.h:28
void visitStmt(const Stmt &stmt) override
Definition: check_not_modified.cc:20
CheckNameToDefMapping(const ID &pos, const std::unordered_set< std::string > &names)
Definition: check_not_modified.h:24
Definition: check_not_modified.h:36
const auto & read2scope() const
Definition: check_not_modified.h:48
void visitStmt(const Stmt &stmt) override
Definition: check_not_modified.cc:41
CheckReadToParallelScopeMapping(const ID &pos, const std::unordered_set< std::string > &reads)
Definition: check_not_modified.h:44
Definition: id.h:18
Definition: check_not_modified.h:54
Stmt visitStmt(const Stmt &op) override
Definition: check_not_modified.cc:76
InsertTmpEval(const Expr &s0Expr, const Expr &s1Expr, CheckNotModifiedSide s0Side, const ID &s0, CheckNotModifiedSide s1Side, const ID &s1)
Definition: check_not_modified.h:60
const ID & s1Eval() const
Definition: check_not_modified.h:67
const ID & s0Eval() const
Definition: check_not_modified.h:66
Definition: mutator.h:11
Definition: symbol_table.h:122
const std::unordered_set< std::string > & names() const override
Definition: symbol_table.h:129
Definition: allocator.h:9
std::optional< bool > checkNotModifiedFastPreCheck(const Stmt &op, const Expr &expr, CheckNotModifiedSide s0Side, const ID &s0, CheckNotModifiedSide s1Side, const ID &s1)
Definition: check_not_modified.cc:125
bool checkNotModified(const Stmt &op, const Expr &expr, CheckNotModifiedSide s0Side, const ID &s0, CheckNotModifiedSide s1Side, const ID &s1)
Definition: check_not_modified.cc:223
Ref< StmtNode > Stmt
Definition: ast.h:152
CheckNotModifiedSide
Definition: check_not_modified.h:14
Ref< ExprNode > Expr
Definition: ast.h:184