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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Oct 16 12:56:35 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Moazin K. (moazin)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/232910.diff


4 Files Affected:

- (modified) mlir/include/mlir/Conversion/OpenACCToLLVM/ACCToLLVMUtils.h (+1-6) 
- (modified) mlir/include/mlir/Dialect/OpenACC/OpenACC.h (+7) 
- (modified) mlir/lib/Conversion/OpenACCToLLVM/ACCToLLVMUtils.cpp (-10) 
- (modified) mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp (+10) 


``````````diff
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)

``````````

</details>


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


More information about the Mlir-commits mailing list