[Mlir-commits] [mlir] [OpenACC][NFC] Move device type precedence helper to dialect utils (PR #232910)

Moazin K. llvmlistbot at llvm.org
Fri Oct 16 13:02:13 PDT 2026


https://github.com/moazin updated https://github.com/llvm/llvm-project/pull/232910

>From 2b80cdc242897de669699cb37844f82e533c55ba Mon Sep 17 00:00:00 2001
From: Moazin Khatti <mkhatti at nvidia.com>
Date: Tue, 13 Oct 2026 14:24:38 -0700
Subject: [PATCH] [OpenACC][NFC] Move device type precedence helper to dialect
 utils

Move device type precedence helper to dialect utils. The helper can
be used by any pass or helper that wants to determine which clause
should apply to a given device.

Assisted-by: Codex
---
 .../mlir/Conversion/OpenACCToLLVM/ACCToLLVMUtils.h     |  7 +------
 mlir/include/mlir/Dialect/OpenACC/OpenACC.h            |  7 +++++++
 mlir/lib/Conversion/OpenACCToLLVM/ACCToLLVMUtils.cpp   | 10 ----------
 mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp                | 10 ++++++++++
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/mlir/include/mlir/Conversion/OpenACCToLLVM/ACCToLLVMUtils.h b/mlir/include/mlir/Conversion/OpenACCToLLVM/ACCToLLVMUtils.h
index 05c2e656cc4d9..7b0d24b2086e4 100644
--- a/mlir/include/mlir/Conversion/OpenACCToLLVM/ACCToLLVMUtils.h
+++ b/mlir/include/mlir/Conversion/OpenACCToLLVM/ACCToLLVMUtils.h
@@ -10,6 +10,7 @@
 #define MLIR_CONVERSION_OPENACCTOLLVM_ACCTOLLVMUTILS_H
 
 #include "mlir/Dialect/OpenACC/Analysis/OpenACCSupport.h"
+#include "mlir/Dialect/OpenACC/OpenACC.h"
 #include "mlir/Dialect/OpenACC/OpenACCRuntimeUtils.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/BuiltinOps.h"
@@ -146,12 +147,6 @@ emitValueSelectedByIfCond(Location loc, Value ifCond, RewriterBase &rewriter,
 void spliceConstructRegion(Operation *op, Region &region,
                            RewriterBase &rewriter);
 
-/// The clauses of a construct can be given once per device type. Of the values
-/// that reach a given device type, the ones naming it are the most specific,
-/// then the ones naming every device type, then the ones given before any
-/// device_type clause.
-SmallVector<DeviceType, 3> getDeviceTypesByPrecedence(DeviceType deviceType);
-
 namespace detail {
 /// The constructs carrying a `device_type` clause hold their async and wait
 /// clauses per device type. The others, such as `acc.enter_data` or
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h
index 1bc670b33d4fd..3cfa8457759de 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACC.h
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACC.h
@@ -33,6 +33,7 @@
 #include "mlir/Interfaces/LoopLikeInterface.h"
 #include "mlir/Interfaces/SideEffectInterfaces.h"
 #include "mlir/Interfaces/ViewLikeInterface.h"
+#include "llvm/ADT/SmallVector.h"
 #include <variant>
 
 #define GET_TYPEDEF_CLASSES
@@ -139,6 +140,12 @@ mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp);
 /// associated with the async clauses without an async-value.
 mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp);
 
+/// The clauses of a construct can be given once per device type. Of the values
+/// that reach a given device type, the ones naming it are the most specific,
+/// then the ones naming every device type, then the ones given before any
+/// device_type clause.
+SmallVector<DeviceType, 3> getDeviceTypesByPrecedence(DeviceType deviceType);
+
 /// Used to obtain the `name` from an acc operation.
 std::optional<llvm::StringRef> getVarName(mlir::Operation *accOp);
 
diff --git a/mlir/lib/Conversion/OpenACCToLLVM/ACCToLLVMUtils.cpp b/mlir/lib/Conversion/OpenACCToLLVM/ACCToLLVMUtils.cpp
index bae03699c5f73..cb8236366a6f0 100644
--- a/mlir/lib/Conversion/OpenACCToLLVM/ACCToLLVMUtils.cpp
+++ b/mlir/lib/Conversion/OpenACCToLLVM/ACCToLLVMUtils.cpp
@@ -322,16 +322,6 @@ FailureOr<Value> acc::emitGetDevicePtrCall(Operation *clauseOp, Value hostPtr,
   return call->getResult();
 }
 
-SmallVector<DeviceType, 3>
-acc::getDeviceTypesByPrecedence(DeviceType deviceType) {
-  SmallVector<DeviceType, 3> deviceTypes;
-  if (deviceType != DeviceType::None && deviceType != DeviceType::Star)
-    deviceTypes.push_back(deviceType);
-  deviceTypes.push_back(DeviceType::Star);
-  deviceTypes.push_back(DeviceType::None);
-  return deviceTypes;
-}
-
 LogicalResult acc::emitGuardedByIfCond(Location loc, Value ifCond,
                                        RewriterBase &rewriter,
                                        function_ref<LogicalResult()> emitFn) {
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index 23fcb74f9f4f4..4f0aec22a00b2 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -5497,6 +5497,16 @@ mlir::ArrayAttr mlir::acc::getAsyncOnly(mlir::Operation *accDataClauseOp) {
       .Default([&](mlir::Operation *) { return mlir::ArrayAttr{}; });
 }
 
+SmallVector<DeviceType, 3>
+acc::getDeviceTypesByPrecedence(DeviceType deviceType) {
+  SmallVector<DeviceType, 3> deviceTypes;
+  if (deviceType != DeviceType::None && deviceType != DeviceType::Star)
+    deviceTypes.push_back(deviceType);
+  deviceTypes.push_back(DeviceType::Star);
+  deviceTypes.push_back(DeviceType::None);
+  return deviceTypes;
+}
+
 std::optional<llvm::StringRef> mlir::acc::getVarName(mlir::Operation *accOp) {
   auto name{
       llvm::TypeSwitch<mlir::Operation *, std::optional<llvm::StringRef>>(accOp)



More information about the Mlir-commits mailing list