[Mlir-commits] [mlir] [mlir][gpu] GPUToROCDL: Add C++ argument to populate allowedDialects (PR #157402)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Sep 8 01:04:06 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Pablo Antonio Martinez (pabloantoniom)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/157402.diff
2 Files Affected:
- (modified) mlir/include/mlir/Conversion/GPUToROCDL/GPUToROCDLPass.h (+5-1)
- (modified) mlir/lib/Conversion/GPUToROCDL/LowerGpuOpsToROCDLOps.cpp (+15-8)
``````````diff
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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/157402
More information about the Mlir-commits
mailing list