FreeTensor
Loading...
Searching...
No Matches
analyze_linear.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_ANALYZE_LINEAR_H
2#define FREE_TENSOR_ANALYZE_LINEAR_H
3
4#include <optional>
5#include <unordered_map>
6#include <unordered_set>
7
8#include <hash.h>
9#include <math/linear.h>
10#include <visitor.h>
11
12namespace freetensor {
13
14class AnalyzeLinear : public Visitor {
15 std::unordered_map<AST, LinearExpr<int64_t>> result_;
16
17 public:
18 const std::unordered_map<AST, LinearExpr<int64_t>> &result() const {
19 return result_;
20 }
21
22 protected:
23 void visitExpr(const Expr &op) override;
24
25 void visit(const IntConst &op) override;
26 void visit(const Add &op) override;
27 void visit(const Sub &op) override;
28 void visit(const Mul &op) override;
29 // Note that for integer (floored) div, k * a / d !== (k / d) * a, so we are
30 // not handling Div here
31};
32
37LinearExpr<int64_t> linear(const Expr &expr);
38
42std::optional<std::pair<LinearExpr<int64_t>, ASTNodeType>>
43linearComp(const Expr &expr);
44
45} // namespace freetensor
46
47#endif // FREE_TENSOR_ANALYZE_LINEAR_H
Definition: analyze_linear.h:14
const std::unordered_map< AST, LinearExpr< int64_t > > & result() const
Definition: analyze_linear.h:18
void visitExpr(const Expr &op) override
Definition: analyze_linear.cc:5
void visit(const IntConst &op) override
Definition: analyze_linear.cc:14
Definition: visitor.h:11
Definition: allocator.h:9
Ref< ExprNode > Expr
Definition: ast.h:184
LinearExpr< int64_t > linear(const Expr &expr)
Definition: analyze_linear.cc:49
std::optional< std::pair< LinearExpr< int64_t >, ASTNodeType > > linearComp(const Expr &expr)
Definition: analyze_linear.cc:56
ASTNodeType
Definition: ast.h:20