[Mlir-commits] [llvm] [mlir] [Flang][OpenMP][OpenMPIRBuilder] Implement module scope declare target use rewrite mechanism (PR #212920)

Sergio Afonso llvmlistbot at llvm.org
Mon Aug 3 07:06:15 PDT 2026


================
@@ -1109,6 +1109,21 @@ class OpenMPIRBuilder {
       std::function<GlobalValue::LinkageTypes()> VariableLinkage,
       Type *LlvmPtrTy, Constant *Addr);
 
+  /// Register a module-scope replacement of a declare target global variable.
+  /// During lowering new globals are generated for certain combinations of
+  /// declare target input, and these new globals require substitution with
+  /// the originals. This replacement occurs during finalization where uses
+  /// of \p Original are rewritten to reference \p Replacement. This is
+  /// predominantly required for Flang where the lowering pattern to LLVM
+  /// prevents immediate use rewrites.
----------------
skatrak wrote:

Nit: I don't think this is a Flang-specific limitation, as it's mostly based on how MLIR translation to LLVM IR is done, from what I can tell. It's something that would be a problem regardless of the frontend.

Also, unless you can foresee a use for this feature when compiling a host module in the future, it might make sense to update the documentation to state that it is only intended for target device modules, to make it clearer.

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


More information about the Mlir-commits mailing list