[all-commits] [llvm/llvm-project] a805dd: [Flang][OpenMP][OpenMPIRBuilder] Implement module ...

agozillon via All-commits all-commits at lists.llvm.org
Mon Aug 3 16:19:29 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a805dd6fc5285fe2fdc911e38a12fe704e40fece
      https://github.com/llvm/llvm-project/commit/a805dd6fc5285fe2fdc911e38a12fe704e40fece
  Author: agozillon <Andrew.Gozillon at amd.com>
  Date:   2026-08-04 (Tue, 04 Aug 2026)

  Changed paths:
    M llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
    M llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
    M llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
    M mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
    A mlir/test/Target/LLVMIR/omptarget-declare-target-module-rewrite-device.mlir

  Log Message:
  -----------
  [Flang][OpenMP][OpenMPIRBuilder] Implement module scope declare target use rewrite mechanism (#212920)

During lowering of declare target'd variables we generate new global
variables for device that replace the use of the pre-existing global
variable. In Flang we currently rewrite this for each target region, but
that's not enough to cover indirect use cases inside of declare target
functions which can be imported into the module and utilised inside of a
target region. This PR tries to extend the scope of the rewriting to the
module than a per target region rewrite.

It does so by creating a mechanism where we can register globals for
replacement which will trigger on finalization of the OMPIRBuilder. This
is required as due to the ordering of lowering for MLIR, where we
generate the replacement global at the beginning of the module before
any uses have been generated, effectively meaning we cannot replace the
uses at that point. So, we defer the replacement to the OMPIRBuilder as
there is no deferral mechanism directly in the OpenMP MLIR lowering.

The alternative might be to rebind the global maps in ModuleTranslation
(which requires extending ModuleTranslation a bit and might not be
looked apon as a great alteration from the MLIR community) so that the
old global points to the new one, but in practice this doesn't work
particularly well for declare target link/usm variables as they
neccesitate a load and the act of rebinding the global doesn't indicate
to the lowering that the load is required. So, the OMPIRBuilder method
allows us more flexibility to make this (and other) required
alterations.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list