#pragma once #include "nnet/Visitor/StrideVisitor.h" #include "nnet/visitor.h" namespace nnet { // Simplify a index expression tree class SimplifyExprVisitor : public Functor stride)> { private: SubexprSride subexprStride; int constant; PtrMap strides; // [var]=strides map, int, RefValueLess>> divStrides, modStrides; // 3*(i%8): []=3 // For divde and modulo with expr as dividend: 3*((i+1)%8): []=3 map, int, RefAddrLess>> divExprStrides, modExprStrides; public: SimplifyExprVisitor() : Functor(0) {} void visit_(const BinaryOp &c, optional stride) override; void visit_(const Var &c, optional stride) override; void visit_(const Constant &c, optional stride) override; PtrMap getStrides(const Expr &expr); // TODO [refactor]: move this to SimplifyFormulaMutator as a member func // this class should be get coefficients in a expr Expr simplify(const Expr &expr); int getConstant(const Expr &expr); pair, int> getStridesConstant(const Expr &expr); optional getExprRange(const Expr &expr, const RangeOp &rangeOp); PtrMap getStrides() { return strides; } const auto &getDivStrides() { return divStrides; } const auto &getModStrides() { return modStrides; } }; } // namespace nnet