[Mlir-commits] [mlir] [mlir][gpu] GPUToROCDL: Add C++ argument to populate allowedDialects (PR #157402)
    Pablo Antonio Martinez 
    llvmlistbot at llvm.org
       
    Mon Sep  8 01:03:33 PDT 2025
    
    
  
https://github.com/pabloantoniom created https://github.com/llvm/llvm-project/pull/157402
The `convert-gpu-to-rocdl` pass provides the option `allowed-dialects`, which allows users to control which dialects can be used to populate conversions.
This PR adds a C++ argument to createLowerGpuOpsToROCDLOpsPass, so that this option can also be controlled programatically when creating the pass.
cc: @dhernandez0 
>From c03637be0750aff5b0711a9a3fac2d7b5e13f32a Mon Sep 17 00:00:00 2001
From: Pablo Antonio Martinez <pamartin at amd.com>
Date: Mon, 8 Sep 2025 02:34:00 -0500
Subject: [PATCH] [mlir][gpu] GPUToROCDL: Add C++ argument to populate
 allowedDialects
The `convert-gpu-to-rocdl` pass provides the option `allowed-dialects`,
which allows users to control which dialects can be used to populate
conversions.
This PR adds a C++ argument to createLowerGpuOpsToROCDLOpsPass, so
that this option can also be controlled programatically when creating
the pass.
---
 .../Conversion/GPUToROCDL/GPUToROCDLPass.h    |  6 ++++-
 .../GPUToROCDL/LowerGpuOpsToROCDLOps.cpp      | 23 ++++++++++++-------
 2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h b/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h
index 291b809071ce9..a6099bde2a70e 100644
--- a/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h
+++ b/mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h
@@ -10,6 +10,8 @@
 
 #include "mlir/Conversion/GPUToROCDL/Runtimes.h"
 #include "mlir/Conversion/LLVMCommon/LoweringOptions.h"
+#include "llvm/ADT/DenseSet.h"
+#include <cstddef>
 #include <memory>
 
 namespace mlir {
@@ -50,7 +52,9 @@ createLowerGpuOpsToROCDLOpsPass(
     const std::string &chipset = "gfx900",
     unsigned indexBitwidth = kDeriveIndexBitwidthFromDataLayout,
     bool useBarePtrCallConv = false,
-    gpu::amd::Runtime runtime = gpu::amd::Runtime::Unknown);
+    gpu::amd::Runtime runtime = gpu::amd::Runtime::Unknown,
+    const std::optional<llvm::SmallDenseSet<llvm::StringRef>> &allowedDialects =
+        std::nullopt);
 
 } // namespace mlir
 
diff --git a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
index 807d1f52ee69b..965089df0303e 100644
--- a/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
+++ b/mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp
@@ -288,9 +288,10 @@ struct GPUShuffleOpLowering : public ConvertOpToLLVMPattern<gpu::ShuffleOp> {
 struct LowerGpuOpsToROCDLOpsPass final
     : public impl::ConvertGpuOpsToROCDLOpsBase<LowerGpuOpsToROCDLOpsPass> {
   LowerGpuOpsToROCDLOpsPass() = default;
-  LowerGpuOpsToROCDLOpsPass(const std::string &chipset, unsigned indexBitwidth,
-                            bool useBarePtrCallConv,
-                            gpu::amd::Runtime runtime) {
+  LowerGpuOpsToROCDLOpsPass(
+      const std::string &chipset, unsigned indexBitwidth,
+      bool useBarePtrCallConv, gpu::amd::Runtime runtime,
+      std::optional<llvm::SmallDenseSet<StringRef>> allowedDialects) {
     if (this->chipset.getNumOccurrences() == 0)
       this->chipset = chipset;
     if (this->indexBitwidth.getNumOccurrences() == 0)
@@ -299,6 +300,12 @@ struct LowerGpuOpsToROCDLOpsPass final
       this->useBarePtrCallConv = useBarePtrCallConv;
     if (this->runtime.getNumOccurrences() == 0)
       this->runtime = runtime;
+    if (this->allowedDialects.getNumOccurrences() == 0 &&
+        allowedDialects.has_value()) {
+      for (auto &str : allowedDialects.value()) {
+        this->allowedDialects.push_back(str.str());
+      }
+    }
   }
 
   void getDependentDialects(DialectRegistry ®istry) const override {
@@ -501,10 +508,10 @@ void mlir::populateGpuToROCDLConversionPatterns(
 }
 
 std::unique_ptr<OperationPass<gpu::GPUModuleOp>>
-mlir::createLowerGpuOpsToROCDLOpsPass(const std::string &chipset,
-                                      unsigned indexBitwidth,
-                                      bool useBarePtrCallConv,
-                                      gpu::amd::Runtime runtime) {
+mlir::createLowerGpuOpsToROCDLOpsPass(
+    const std::string &chipset, unsigned indexBitwidth, bool useBarePtrCallConv,
+    gpu::amd::Runtime runtime,
+    const std::optional<llvm::SmallDenseSet<StringRef>> &allowedDialects) {
   return std::make_unique<LowerGpuOpsToROCDLOpsPass>(
-      chipset, indexBitwidth, useBarePtrCallConv, runtime);
+      chipset, indexBitwidth, useBarePtrCallConv, runtime, allowedDialects);
 }
    
    
More information about the Mlir-commits
mailing list