[Mlir-commits] [mlir] a6a462f - [MLIR][OpenMP] Add omp.target_triples attribute to the OffloadModuleInterface (#100154)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Aug 2 02:25:45 PDT 2024


Author: Sergio Afonso
Date: 2024-08-02T10:25:41+01:00
New Revision: a6a462f09cce77511de037d9cb61e9fc835d4f4d

URL: https://github.com/llvm/llvm-project/commit/a6a462f09cce77511de037d9cb61e9fc835d4f4d
DIFF: https://github.com/llvm/llvm-project/commit/a6a462f09cce77511de037d9cb61e9fc835d4f4d.diff

LOG: [MLIR][OpenMP] Add omp.target_triples attribute to the OffloadModuleInterface (#100154)

The `OffloadModuleInterface` holds getter/setter methods to access
OpenMP dialect module-level discardable attributes used to hold general
OpenMP compilation information.

This patch adds the `omp.target_triples` attribute, which is intended to
hold the list of offloading target triples linked to the host module in
which it appears. This attribute should be empty when
`omp.is_target_device=true`.

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
index 45d30a41bd29b..2d1de37239c82 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
@@ -351,6 +351,34 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
       (ins "::mlir::omp::ClauseRequires":$clauses), [{}], [{
         $_op->setAttr(mlir::StringAttr::get($_op->getContext(), "omp.requires"),
           mlir::omp::ClauseRequiresAttr::get($_op->getContext(), clauses));
+      }]>,
+    InterfaceMethod<
+      /*description=*/[{
+        Get the omp.target_triples attribute on the operator if it's present and
+        return its value. If it doesn't exist, return an empty array by default.
+      }],
+      /*retTy=*/"::llvm::ArrayRef<::mlir::Attribute>",
+      /*methodName=*/"getTargetTriples",
+      (ins), [{}], [{
+        if (Attribute triplesAttr = $_op->getAttr("omp.target_triples"))
+          if (auto triples = ::llvm::dyn_cast<::mlir::ArrayAttr>(triplesAttr))
+            return triples.getValue();
+        return {};
+      }]>,
+    InterfaceMethod<
+      /*description=*/[{
+        Set the omp.target_triples attribute on the operation.
+      }],
+      /*retTy=*/"void",
+      /*methodName=*/"setTargetTriples",
+      (ins "::llvm::ArrayRef<::std::string>":$targetTriples), [{}], [{
+        auto names = ::llvm::to_vector(::llvm::map_range(
+            targetTriples, [&](::std::string str) -> ::mlir::Attribute {
+              return mlir::StringAttr::get($_op->getContext(), str);
+            }));
+        $_op->setAttr(
+            ::mlir::StringAttr::get($_op->getContext(), "omp.target_triples"),
+            ::mlir::ArrayAttr::get($_op->getContext(), names));
       }]>
   ];
 }


        


More information about the Mlir-commits mailing list