FreeTensor
Loading...
Searching...
No Matches
Namespaces | Macros | Functions | Variables
const_fold.cc File Reference
#include <math/utils.h>
#include <pass/const_fold.h>
Include dependency graph for const_fold.cc:

Namespaces

namespace  freetensor
 

Macros

#define BINARY_OP(OPNAME, OP)
 
#define BINARY_OP_F(OPNAME, OP_F)
 
#define UNARY_OP(OPNAME, OP)
 

Functions

 freetensor::BINARY_OP_F (Min, [](auto &&lhs, auto &&rhs) { typedef decltype(lhs+rhs) V;return std::min< V >(lhs, rhs);}) BINARY_OP_F(Max
 

Variables

auto && freetensor::lhs
 
auto auto && freetensor::rhs
 

Macro Definition Documentation

◆ BINARY_OP

#define BINARY_OP (   OPNAME,
  OP 
)
Value:
struct op_f_##OPNAME { \
template <typename T, typename U> \
requires requires(T l, U r) { l OP r; } \
auto operator()(const T &l, const U &r) { \
return l OP r; \
} \
template <typename T, typename U> \
auto operator()(const T &l, const U &r) -> decltype(l) { \
ERROR("Invalid operator " #OPNAME " on given types"); \
} \
}; \
Expr ConstFold::visit(const OPNAME &op) { \
return visitBinary( \
op, [](auto l, auto r) { return op_f_##OPNAME()(l, r); }, \
[](auto l, auto r) { return make##OPNAME(l, r); }); \
}
Ref< ExprNode > Expr
Definition: ast.h:184

◆ BINARY_OP_F

#define BINARY_OP_F (   OPNAME,
  OP_F 
)
Value:
struct op_f_##OPNAME { \
template <typename T, typename U> \
requires requires(T l, U r) { (OP_F)(l, r); } \
auto operator()(const T &l, const U &r) { \
return (OP_F)(l, r); \
} \
template <typename T, typename U> \
auto operator()(const T &l, const U &r) -> decltype(l) { \
ERROR("Invalid operator " #OPNAME " on given types"); \
} \
}; \
Expr ConstFold::visit(const OPNAME &op) { \
return visitBinary( \
op, [](auto l, auto r) { return op_f_##OPNAME()(l, r); }, \
[](auto l, auto r) { return make##OPNAME(l, r); }); \
}

◆ UNARY_OP

#define UNARY_OP (   OPNAME,
  OP 
)
Value:
struct op_f_##OPNAME { \
template <typename T> \
requires requires(T t) { OP(t); } \
auto operator()(const T &t) { \
return OP(t); \
} \
template <typename T> auto operator()(const T &t) -> decltype(t) { \
ERROR("Invalid operator " #OPNAME " on given types"); \
} \
}; \
Expr ConstFold::visit(const OPNAME &op) { \
return visitUnary( \
op, [](auto x) { return op_f_##OPNAME()(x); }, \
[](auto x) { return make##OPNAME(x); }); \
}