FreeTensor
Loading...
Searching...
No Matches
gen_pb_expr.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_GEN_PB_EXPR_H
2#define FREE_TENSOR_GEN_PB_EXPR_H
3
4#include <unordered_map>
5#include <unordered_set>
6
8#include <hash.h>
9#include <math/presburger.h>
10#include <visitor.h>
11
12namespace freetensor {
13
34class GenPBExpr : public Visitor {
35 public:
36 // hash -> presburger name
38
39 private:
40 std::unordered_map<Expr, std::string> results_;
41 std::unordered_map<Expr, int>
42 constants_; // isl detects contant literally, so we need to do constant
43 // folding here
44 std::unordered_map<Expr, VarMap>
45 vars_; // (sub-)expression -> free variables used inside
46 Expr parent_ = nullptr;
47 std::string varSuffix_;
48 ASTHashSet<Expr> noNeedToBeVars_;
49
50 public:
51 GenPBExpr(const std::string &varSuffix = "",
52 const ASTHashSet<Expr> &noNeedToBeVars = {})
53 : varSuffix_(varSuffix), noNeedToBeVars_(noNeedToBeVars) {}
54
55 const std::string &varSuffix() const { return varSuffix_; }
56
57 std::pair<std::string, VarMap> gen(const Expr &op);
58
59 protected:
60 void visitExpr(const Expr &op) override;
61 void visit(const Var &op) override;
62 void visit(const IntConst &op) override;
63 void visit(const BoolConst &op) override;
64 void visit(const Add &op) override;
65 void visit(const Sub &op) override;
66 void visit(const Mul &op) override;
67 void visit(const LAnd &op) override;
68 void visit(const LOr &op) override;
69 void visit(const LNot &op) override;
70 void visit(const LT &op) override;
71 void visit(const LE &op) override;
72 void visit(const GT &op) override;
73 void visit(const GE &op) override;
74 void visit(const EQ &op) override;
75 void visit(const NE &op) override;
76 void visit(const FloorDiv &op) override;
77 void visit(const CeilDiv &op) override;
78 void visit(const Mod &op) override;
79 void visit(const Min &op) override;
80 void visit(const Max &op) override;
81 void visit(const IfExpr &op) override;
82 void visit(const Unbound &op) override;
83};
84
85} // namespace freetensor
86
87#endif // FREE_TENSOR_GEN_PB_EXPR_H
Definition: gen_pb_expr.h:34
const std::string & varSuffix() const
Definition: gen_pb_expr.h:55
void visit(const Var &op) override
Definition: gen_pb_expr.cc:62
ASTHashMap< Expr, std::string > VarMap
Definition: gen_pb_expr.h:37
GenPBExpr(const std::string &varSuffix="", const ASTHashSet< Expr > &noNeedToBeVars={})
Definition: gen_pb_expr.h:51
std::pair< std::string, VarMap > gen(const Expr &op)
Definition: gen_pb_expr.cc:354
void visitExpr(const Expr &op) override
Definition: gen_pb_expr.cc:16
Definition: visitor.h:11
Definition: allocator.h:9
std::unordered_map< K, V, Hasher, HashComparator > ASTHashMap
Definition: hash.h:114
std::unordered_set< K, Hasher, HashComparator > ASTHashSet
Definition: hash.h:117