[flang-commits] [flang] [flang][OpenMP] Organize `genOMP` functions in OpenMP.cpp, NFC (PR #86309)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Mon Mar 25 05:01:30 PDT 2024


================
@@ -1672,88 +1644,177 @@ static void createSimdWsloop(
                endClauseList, loc);
 }
 
+static void
+markDeclareTarget(mlir::Operation *op,
+                  Fortran::lower::AbstractConverter &converter,
+                  mlir::omp::DeclareTargetCaptureClause captureClause,
+                  mlir::omp::DeclareTargetDeviceType deviceType) {
+  // TODO: Add support for program local variables with declare target applied
+  auto declareTargetOp = llvm::dyn_cast<mlir::omp::DeclareTargetInterface>(op);
+  if (!declareTargetOp)
+    fir::emitFatalError(
+        converter.getCurrentLocation(),
+        "Attempt to apply declare target on unsupported operation");
+
+  // The function or global already has a declare target applied to it, very
+  // likely through implicit capture (usage in another declare target
+  // function/subroutine). It should be marked as any if it has been assigned
+  // both host and nohost, else we skip, as there is no change
+  if (declareTargetOp.isDeclareTarget()) {
+    if (declareTargetOp.getDeclareTargetDeviceType() != deviceType)
+      declareTargetOp.setDeclareTarget(mlir::omp::DeclareTargetDeviceType::any,
+                                       captureClause);
+    return;
+  }
+
+  declareTargetOp.setDeclareTarget(deviceType, captureClause);
+}
+
+// OpenMPDeclarativeConstruct visitors --------------------------------
----------------
skatrak wrote:

Nit: Elsewhere in this file the format for comments defining different groups of functions is as follows:
```c++
//===----------------------------------------------------------------------===//
// File section name
//===----------------------------------------------------------------------===//
```
I think it's worth modifying this and the "OpenMPConstruct visitors" instance below to use the same formatting.

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


More information about the flang-commits mailing list