[flang-commits] [flang] [flang] Changes to map variables in link clause of declare target (PR #83643)

Anchu Rajendran S via flang-commits flang-commits at lists.llvm.org
Mon Mar 4 06:26:08 PST 2024


================
@@ -1120,7 +1120,21 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
         if (auto refType = baseOp.getType().dyn_cast<fir::ReferenceType>())
           eleType = refType.getElementType();
 
-        if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) {
+        // If a variable is specified in declare target link and if device
+        // type is nohost, it needs to be mapped tofrom
+        mlir::ModuleOp mod = converter.getFirOpBuilder().getModule();
+        mlir::Operation *op = mod.lookupSymbol(converter.mangleName(sym));
+        auto declareTargetOp =
+            llvm::dyn_cast_if_present<mlir::omp::DeclareTargetInterface>(op);
+        if (declareTargetOp && declareTargetOp.isDeclareTarget()) {
+          if (declareTargetOp.getDeclareTargetCaptureClause() ==
+                  mlir::omp::DeclareTargetCaptureClause::link &&
+              declareTargetOp.getDeclareTargetDeviceType() !=
----------------
anchu-rajendran wrote:

> And as an aside, if it wouldn't be too much of a bother could you add a runtime test to: https://github.com/llvm/llvm-project/tree/main/openmp/libomptarget/test/offloading/fortran not necessary for me signing off, but it would be excellent to track this behavior with a runtime test as well!

Hi @agozillon ,
Thank you for reviewing my PR. My comment is incorrect. Thanks for noticing and for the suggestion of adding a runtime test. I do agree with it. I will raise a second revision with the changes. 

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


More information about the flang-commits mailing list