FreeTensor
Loading...
Searching...
No Matches
shrink_for.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_SHRINK_FOR_H
2#define FREE_TENSOR_SHRINK_FOR_H
3
8#include <container_utils.h>
9#include <func.h>
10#include <hash.h>
11#include <mutator.h>
12
13namespace freetensor {
14
15class CheckSideEffect : public Visitor {
16 bool hasSideEffect_ = false;
17
18 public:
19 bool hasSideEffect() const { return hasSideEffect_; }
20
21 protected:
22 void visit(const Store &op) override;
23 void visit(const ReduceTo &op) override;
24 void visit(const Intrinsic &op) override;
25};
26
27class ShrinkFor : public CompTransientBounds<SymbolTable<Mutator>> {
29
30 bool unordered_;
31
33 std::vector<Var> iterStack_;
34 std::vector<std::unordered_set<std::string>> namesStack_;
35
36 Stmt subAST_;
37 std::unordered_set<Stmt> subASTAncestors_;
38 bool inSubAST_ = false;
39
40 public:
41 ShrinkFor(bool unordered = false) : unordered_(unordered) {}
42
43 void setSubAST(const Stmt &subAST);
44
45 protected:
46 virtual bool filterLoop(const For &op) { return true; }
47
48 virtual std::unordered_set<std::string>
49 filterNames(const std::unordered_set<std::string> &names) {
50 return names;
51 }
52
53 protected:
54 using BaseClass::visit;
55
56 Stmt visitStmt(const Stmt &stmt) override;
57 Stmt visit(const For &op) override;
58};
59
77Stmt shrinkFor(const Stmt &op, const ID &subAST = ID(), bool doSimplify = true,
78 bool unordered = false);
79inline Stmt shrinkFor(const Stmt &op, const Stmt &subAST,
80 bool doSimplify = true, bool unordered = false) {
81 return shrinkFor(op, subAST.isValid() ? subAST->id() : ID(), doSimplify,
82 unordered);
83}
87
88} // namespace freetensor
89
90#endif // FREE_TENSOR_SHRINK_FOR_H
Definition: shrink_for.h:15
void visit(const Store &op) override
Definition: shrink_for.cc:180
bool hasSideEffect() const
Definition: shrink_for.h:19
Definition: comp_transient_bounds.h:50
BaseClass::StmtRetType visit(const For &op) override
Definition: comp_transient_bounds.h:128
Definition: id.h:18
bool isValid() const
Definition: ref.h:89
Definition: shrink_for.h:27
Stmt visitStmt(const Stmt &stmt) override
Definition: shrink_for.cc:192
void setSubAST(const Stmt &subAST)
Definition: shrink_for.cc:390
virtual std::unordered_set< std::string > filterNames(const std::unordered_set< std::string > &names)
Definition: shrink_for.h:49
ShrinkFor(bool unordered=false)
Definition: shrink_for.h:41
virtual bool filterLoop(const For &op)
Definition: shrink_for.h:46
Stmt visit(const For &op) override
Definition: shrink_for.cc:248
ID id() const
Definition: ast.cc:362
const std::unordered_set< std::string > & names() const override
Definition: symbol_table.h:129
Definition: visitor.h:11
#define DEFINE_PASS_FOR_FUNC(pass)
Definition: func.h:88
Definition: allocator.h:9
std::unordered_map< K, V, Hasher, HashComparator > ASTHashMap
Definition: hash.h:114
Stmt shrinkFor(const Stmt &op, const ID &subAST=ID(), bool doSimplify=true, bool unordered=false)
Definition: shrink_for.cc:396
Ref< StmtNode > Stmt
Definition: ast.h:152