[mlir] Set top-down traversal for LinalgElementwiseOpFusion
authorTres Popp <tpopp@google.com>
Tue, 10 Aug 2021 11:53:59 +0000 (13:53 +0200)
committerTres Popp <tpopp@google.com>
Mon, 16 Aug 2021 07:26:49 +0000 (09:26 +0200)
The primary pattern for this pass clones many operations from producers
to consumers. Doing this top down prevents duplicated work when a
producer has multiple consumers, if it also is consuming another
linalg.generic.

As an example, a chain of ~2600 generics that are fused into ~70
generics was resulting in 16255 pattern invocations. This took 14
seconds on one machine but takes only 0.3 seconds with top-down
traversal.

Differential Revision: https://reviews.llvm.org/D107818

mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp

index fdca523..43a4105 100644 (file)
@@ -1294,7 +1294,12 @@ struct LinalgElementwiseOpFusionPass
         patterns,
         LinalgElementwiseFusionOptions().setControlFoldingReshapes(
             allowFoldingUnitDimReshapes ? allowFoldingFn : skipUnitDimReshape));
-    (void)applyPatternsAndFoldGreedily(op->getRegions(), std::move(patterns));
+
+    // Use TopDownTraversal for compile time reasons
+    GreedyRewriteConfig grc;
+    grc.useTopDownTraversal = true;
+    (void)applyPatternsAndFoldGreedily(op->getRegions(), std::move(patterns),
+                                       grc);
   }
 };