template<typename SubClass, typename RetTy = void>
class mlir::AffineExprVisitor< SubClass, RetTy >
Base class for AffineExpr visitors/walkers.
AffineExpr visitors are used when you want to perform different actions for different kinds of AffineExprs without having to use lots of casts and a big switch instruction.
To define your own visitor, inherit from this class, specifying your new type for the 'SubClass' template parameter, and "override" visitXXX functions in your class. This class is defined in terms of statically resolved overloading, not virtual functions.
For example, here is a visitor that counts the number of for AffineDimExprs in an AffineExpr.
/// Declare the class. Note that we derive from AffineExprVisitor /// instantiated with our new subclasses_ type.
struct DimExprCounter : public AffineExprVisitor<DimExprCounter> { unsigned numDimExprs; DimExprCounter() : numDimExprs(0) {} void visitDimExpr(AffineDimExpr expr) { ++numDimExprs; } };
And this class would be used like this: DimExprCounter dec; dec.visit(affineExpr); numDimExprs = dec.numDimExprs;
AffineExprVisitor provides visit methods for the following binary affine op expressions: AffineBinaryAddOpExpr, AffineBinaryMulOpExpr, AffineBinaryModOpExpr, AffineBinaryFloorDivOpExpr, AffineBinaryCeilDivOpExpr. Note that default implementations of these methods will call the general AffineBinaryOpExpr method.
In addition, visit methods are provided for the following affine Note that if you don't implement visitXXX for some affine expression type, the visitXXX method for Instruction superclass will be invoked.
Note that this class is specifically designed as a template to avoid virtual function call overhead. Defining and using a AffineExprVisitor is just as efficient as having your own switch instruction over the instruction opcode.