diff options
author | Joseph Huber <huberjn@outlook.com> | 2024-02-21 11:33:32 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-21 11:33:32 -0600 |
commit | cc374d8056990a4c6df44173ad7ef59474ba498b (patch) | |
tree | d24104558975f9980f63b59ba6fd8114f26a9de4 /mlir | |
parent | 58f45d909d2a1565128846e423b480808736f214 (diff) | |
download | llvm-cc374d8056990a4c6df44173ad7ef59474ba498b.zip llvm-cc374d8056990a4c6df44173ad7ef59474ba498b.tar.gz llvm-cc374d8056990a4c6df44173ad7ef59474ba498b.tar.bz2 |
[OpenMP] Remove `register_requires` global constructor (#80460)
Summary:
Currently, OpenMP handles the `omp requires` clause by emitting a global
constructor into the runtime for every translation unit that requires
it. However, this is not a great solution because it prevents us from
having a defined order in which the runtime is accessed and used.
This patch changes the approach to no longer use global constructors,
but to instead group the flag with the other offloading entires that we
already handle. This has the effect of still registering each flag per
requires TU, but now we have a single constructor that handles
everything.
This function removes support for the old `__tgt_register_requires` and
replaces it with a warning message. We just had a recent release, and
the OpenMP policy for the past four releases since we switched to LLVM
is that we do not provide strict backwards compatibility between major
LLVM releases now that the library is versioned. This means that a user
will need to recompile if they have an old binary that relied on
`register_requires` having the old behavior. It is important that we
actively deprecate this, as otherwise it would not solve the problem of
having no defined init and shutdown order for `libomptarget`. The
problem of `libomptarget` not having a define init and shutdown order
cascades into a lot of other issues so I have a strong incentive to be
rid of it.
It is worth noting that the current `__tgt_offload_entry` only has space
for a 32-bit integer here. I am planning to overhaul these at some point
as well.
Diffstat (limited to 'mlir')
-rw-r--r-- | mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 23 | ||||
-rw-r--r-- | mlir/test/Target/LLVMIR/openmp-llvm.mlir | 6 |
2 files changed, 1 insertions, 28 deletions
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp index 78a2ad7..6e53d80 100644 --- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp @@ -2768,27 +2768,6 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute, return success(); } -/// Converts the module-level set of OpenMP requires clauses into LLVM IR using -/// OpenMPIRBuilder. -static LogicalResult -convertRequiresAttr(Operation &op, omp::ClauseRequiresAttr requiresAttr, - LLVM::ModuleTranslation &moduleTranslation) { - auto *ompBuilder = moduleTranslation.getOpenMPBuilder(); - - // No need to read requiresAttr here, because it has already been done in - // translateModuleToLLVMIR(). There, flags are stored in the - // OpenMPIRBuilderConfig object, available to the OpenMPIRBuilder. - auto *regFn = - ompBuilder->createRegisterRequires(ompBuilder->createPlatformSpecificName( - {"omp_offloading", "requires_reg"})); - - // Add registration function as global constructor - if (regFn) - llvm::appendToGlobalCtors(ompBuilder->M, regFn, /* Priority = */ 0); - - return success(); -} - namespace { /// Implementation of the dialect interface that converts operations belonging @@ -2891,7 +2870,7 @@ LogicalResult OpenMPDialectLLVMIRTranslationInterface::amendOperation( bitEnumContainsAll(flags, Requires::unified_shared_memory)); config.setHasRequiresDynamicAllocators( bitEnumContainsAll(flags, Requires::dynamic_allocators)); - return convertRequiresAttr(*op, requiresAttr, moduleTranslation); + return success(); } return failure(); }) diff --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir b/mlir/test/Target/LLVMIR/openmp-llvm.mlir index 036367b..39a1e03 100644 --- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir +++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir @@ -2744,10 +2744,4 @@ llvm.func @omp_task_if(%boolexpr: i1) { // ----- -// Check that OpenMP requires flags are registered by a global constructor. -// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] -// CHECK-SAME: [{ i32, ptr, ptr } { i32 0, ptr @[[REG_FN:.*]], ptr null }] -// CHECK: define {{.*}} @[[REG_FN]]({{.*}}) -// CHECK-NOT: } -// CHECK: call void @__tgt_register_requires(i64 10) module attributes {omp.requires = #omp<clause_requires reverse_offload|unified_shared_memory>} {} |