[flang-commits] [flang] [flang][openmp] Support importing module declare target globals (PR #213930)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Mon Aug 10 04:38:55 PDT 2026


================
@@ -7180,3 +7111,38 @@ void Fortran::lower::materializeOpenMPDeclareMappers(
 // Walk scopes and materialize omp.declare_reduction ops for user-defined
 // operator reductions imported from modules (deleted: replaced by lazy,
 // clause-driven materialization).
+
+void Fortran::lower::attachOpenMPDeclareTargetAttributes(
+    lower::AbstractConverter &converter, const lower::pft::Variable &var) {
+  auto module = converter.getModuleOp();
+
+  mlir::Operation *globalOp =
+      module.lookupSymbol(converter.mangleName(var.getSymbol()));
+
+  auto ultimateSymbol = var.getSymbol().GetUltimate();
+
+  if (globalOp && ultimateSymbol.IsFromModFile()) {
+    auto declareTargetOp =
+        llvm::dyn_cast<mlir::omp::DeclareTargetInterface>(globalOp);
----------------
skatrak wrote:

This is accessed unconditionally below, so use `cast<>` instead. I would also add an `assert(var.isGlobal())` at the beginning of this function, since passing anything else would be an illegal use of this function.

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


More information about the flang-commits mailing list