[Mlir-commits] [mlir] [mlir][spirv] Implement vector type legalization for function signatures (PR #98337)

Lei Zhang llvmlistbot at llvm.org
Sat Jul 13 09:07:27 PDT 2024


================
@@ -37,20 +37,37 @@ using namespace mlir;
 namespace {
 
 /// A pass to perform the SPIR-V conversion.
-struct ConvertToSPIRVPass final
-    : impl::ConvertToSPIRVPassBase<ConvertToSPIRVPass> {
+struct ConvertToSPIRVPass
+    : public impl::ConvertToSPIRVPassBase<ConvertToSPIRVPass> {
+  using ConvertToSPIRVPassBase::ConvertToSPIRVPassBase;
 
   void runOnOperation() override {
     MLIRContext *context = &getContext();
     Operation *op = getOperation();
 
+    if (runSignatureConversion) {
+      // Unroll vectors in function signatures to native vector size.
+      {
+        RewritePatternSet patterns(context);
+        populateFuncOpVectorRewritePatterns(patterns);
+        populateReturnOpVectorRewritePatterns(patterns);
+        GreedyRewriteConfig config;
+        config.strictMode = GreedyRewriteStrictness::ExistingOps;
+        if (failed(
+                applyPatternsAndFoldGreedily(op, std::move(patterns), config)))
+          return signalPassFailure();
+      }
+      return;
----------------
antiagainst wrote:

I think we can have a dedicated `--test-convert-to-spirv-patterns` pass or whatever to test all sorts of patterns you'd like to test in isolation. In the test pass you can have many options, like [`TestLinalgTransforms.cpp`](https://github.com/llvm/llvm-project/blob/main/mlir/test/lib/Dialect/Linalg/TestLinalgTransforms.cpp). This keeps the main pass introduced here less cluttered and more targeted end-to-end so more clean, given I think we are sort of aiming for this pass to be directly consumed by downstream users eventually. WDYT?

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


More information about the Mlir-commits mailing list