[Mlir-commits] [mlir] [mlir][affine] remove divide zero check when simplifer affineMap (#64622) (PR #68519)

Jakub Kuderski llvmlistbot at llvm.org
Mon Oct 30 07:57:32 PDT 2023


================
@@ -65,8 +66,80 @@ namespace mlir {
 /// just as efficient as having your own switch instruction over the instruction
 /// opcode.
 
+template <typename SubClass, typename RetTy>
+class AffineExprVisitorBase {
+public:
+  // Function to visit an AffineExpr.
+  RetTy visit(AffineExpr expr) {
+    static_assert(std::is_base_of<AffineExprVisitorBase, SubClass>::value,
+                  "Must instantiate with a derived type of AffineExprVisitor");
+    switch (expr.getKind()) {
+    case AffineExprKind::Add: {
+      auto binOpExpr = expr.cast<AffineBinaryOpExpr>();
+      return static_cast<SubClass *>(this)->visitAddExpr(binOpExpr);
----------------
kuhar wrote:

nit: consider hoisting `static_cast<SubClass *>(this)` to a local variable, since it repeats in every single `case`  body

https://github.com/llvm/llvm-project/pull/68519


More information about the Mlir-commits mailing list