FreeTensor
Loading...
Searching...
No Matches
float_simplify.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_FLOAT_SIMPLIFY_H
2#define FREE_TENSOR_FLOAT_SIMPLIFY_H
3
4#include <functional>
5#include <unordered_map>
6#include <unordered_set>
7
9#include <func.h>
10#include <mutator.h>
11#include <pass/const_fold.h>
12
13namespace freetensor {
14
15class FloatSimplify : public SymbolTable<ConstFold> {
17
18 template <class T> bool equals(const Expr &op, T &&val) const {
19 if (op->nodeType() == ASTNodeType::IntConst &&
20 op.as<IntConstNode>()->val_ == val) {
21 return true;
22 }
23 if (op->nodeType() == ASTNodeType::FloatConst &&
24 op.as<FloatConstNode>()->val_ == val) {
25 return true;
26 }
27 return false;
28 }
29
30 Expr normalizeRealMulDiv(const Expr &op);
31
32 protected:
33 using BaseClass::visit;
34 Expr visitExpr(const Expr &expr) override;
35 Expr visit(const Add &op) override;
36 Expr visit(const Sub &op) override;
37 Expr visit(const Mul &op) override;
38 Expr visit(const RealDiv &op) override;
39 Expr visit(const Min &op) override;
40 Expr visit(const Max &op) override;
41 Expr visit(const Sqrt &op) override;
42 Expr visit(const Square &op) override;
43 Expr visit(const Abs &op) override;
44 // TODO: Cancel Exp against Ln
45};
46
52Stmt floatSimplify(const Stmt &op);
53
55
56} // namespace freetensor
57
58#endif // FREE_TENSOR_FLOAT_SIMPLIFY_H
virtual ASTNodeType nodeType() const =0
Definition: expr.h:110
double val_
Definition: expr.h:112
Definition: float_simplify.h:15
Expr visit(const Add &op) override
Definition: float_simplify.cc:168
Expr visitExpr(const Expr &expr) override
Definition: float_simplify.cc:131
Definition: expr.h:93
int64_t val_
Definition: expr.h:95
Ref< U > as() const
Definition: ref.h:83
Definition: symbol_table.h:122
BaseClass::StmtRetType visit(const VarDef &op) override
Definition: symbol_table.h:167
#define DEFINE_PASS_FOR_FUNC(pass)
Definition: func.h:88
Definition: allocator.h:9
Stmt floatSimplify(const Stmt &op)
Definition: float_simplify.cc:492