[llvm] [OFFLOAD] Remove weak from __kmpc_* calls and gather them in one header (PR #164613)
Alex Duran via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 23 02:23:26 PDT 2025
https://github.com/adurang updated https://github.com/llvm/llvm-project/pull/164613
>From bc919ba3176ada3e85a65868efeb31bca936886d Mon Sep 17 00:00:00 2001
From: Alex Duran <alejandro.duran at intel.com>
Date: Wed, 22 Oct 2025 14:03:23 +0200
Subject: [PATCH 1/3] [OFFLOAD] Remove weak from __kmpc_* calls and gather them
in one header
---
offload/include/OffloadPolicy.h | 1 -
offload/include/OpenMP/InternalTypes.h | 30 +++++++++++++++++-----
offload/libomptarget/OpenMP/API.cpp | 23 -----------------
offload/libomptarget/OpenMP/InteropAPI.cpp | 8 ------
4 files changed, 24 insertions(+), 38 deletions(-)
diff --git a/offload/include/OffloadPolicy.h b/offload/include/OffloadPolicy.h
index 800fefb224326..6656e2dd9b595 100644
--- a/offload/include/OffloadPolicy.h
+++ b/offload/include/OffloadPolicy.h
@@ -22,7 +22,6 @@ enum kmp_target_offload_kind_t {
tgt_mandatory = 2
};
-extern "C" int __kmpc_get_target_offload(void) __attribute__((weak));
class OffloadPolicy {
diff --git a/offload/include/OpenMP/InternalTypes.h b/offload/include/OpenMP/InternalTypes.h
index bd84c38fb2011..ce339f3f5358b 100644
--- a/offload/include/OpenMP/InternalTypes.h
+++ b/offload/include/OpenMP/InternalTypes.h
@@ -70,10 +70,28 @@ typedef struct kmp_task {
int32_t part_id;
} kmp_task_t;
-int32_t __kmpc_global_thread_num(void *) __attribute__((weak));
-bool __kmpc_omp_has_task_team(int32_t gtid) __attribute__((weak));
-void **__kmpc_omp_get_target_async_handle_ptr(int32_t gtid)
- __attribute__((weak));
+// Implemented in libomp, they are called from within __tgt_* functions.
+int32_t __kmpc_global_thread_num(void *);
+bool __kmpc_omp_has_task_team(int32_t gtid);
+void **__kmpc_omp_get_target_async_handle_ptr(int32_t gtid);
+int __kmpc_get_target_offload(void);
+int __kmpc_get_target_offload(void);
+kmp_task_t *__kmpc_omp_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
+ size_t sizeof_kmp_task_t,
+ size_t sizeof_shareds,
+ kmp_routine_entry_t task_entry);
+kmp_task_t *
+__kmpc_omp_target_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
+ size_t sizeof_kmp_task_t, size_t sizeof_shareds,
+ kmp_routine_entry_t task_entry, int64_t device_id);
+int32_t __kmpc_omp_task_with_deps(ident_t *loc_ref, int32_t gtid,
+ kmp_task_t *new_task, int32_t ndeps,
+ kmp_depend_info_t *dep_list,
+ int32_t ndeps_noalias,
+ kmp_depend_info_t *noalias_dep_list);
+void __kmpc_omp_wait_deps(ident_t *loc_ref, int32_t gtid, int32_t ndeps,
+ kmp_depend_info_t *dep_list, int32_t ndeps_noalias,
+ kmp_depend_info_t *noalias_dep_list);
/**
* The argument set that is passed from asynchronous memory copy to block
@@ -120,7 +138,7 @@ struct TargetMemcpyArgsTy {
: Dst(Dst), Src(Src), DstDevice(DstDevice), SrcDevice(SrcDevice),
IsRectMemcpy(false), Length(Length), DstOffset(DstOffset),
SrcOffset(SrcOffset), ElementSize(0), NumDims(0), Volume(0),
- DstOffsets(0), SrcOffsets(0), DstDimensions(0), SrcDimensions(0){};
+ DstOffsets(0), SrcOffsets(0), DstDimensions(0), SrcDimensions(0) {};
/**
* Constructor for rectangle dimensional copy
@@ -134,7 +152,7 @@ struct TargetMemcpyArgsTy {
IsRectMemcpy(true), Length(0), DstOffset(0), SrcOffset(0),
ElementSize(ElementSize), NumDims(NumDims), Volume(Volume),
DstOffsets(DstOffsets), SrcOffsets(SrcOffsets),
- DstDimensions(DstDimensions), SrcDimensions(SrcDimensions){};
+ DstDimensions(DstDimensions), SrcDimensions(SrcDimensions) {};
};
struct TargetMemsetArgsTy {
diff --git a/offload/libomptarget/OpenMP/API.cpp b/offload/libomptarget/OpenMP/API.cpp
index b0f0573833713..941d2a7d74c50 100644
--- a/offload/libomptarget/OpenMP/API.cpp
+++ b/offload/libomptarget/OpenMP/API.cpp
@@ -48,29 +48,6 @@ void *targetLockExplicit(void *HostPtr, size_t Size, int DeviceNum,
const char *Name);
void targetUnlockExplicit(void *HostPtr, int DeviceNum, const char *Name);
-// Implemented in libomp, they are called from within __tgt_* functions.
-extern "C" {
-int __kmpc_get_target_offload(void) __attribute__((weak));
-kmp_task_t *__kmpc_omp_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
- size_t sizeof_kmp_task_t,
- size_t sizeof_shareds,
- kmp_routine_entry_t task_entry)
- __attribute__((weak));
-
-kmp_task_t *
-__kmpc_omp_target_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
- size_t sizeof_kmp_task_t, size_t sizeof_shareds,
- kmp_routine_entry_t task_entry, int64_t device_id)
- __attribute__((weak));
-
-int32_t __kmpc_omp_task_with_deps(ident_t *loc_ref, int32_t gtid,
- kmp_task_t *new_task, int32_t ndeps,
- kmp_depend_info_t *dep_list,
- int32_t ndeps_noalias,
- kmp_depend_info_t *noalias_dep_list)
- __attribute__((weak));
-}
-
EXTERN int omp_get_num_devices(void) {
TIMESCOPE();
OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0)));
diff --git a/offload/libomptarget/OpenMP/InteropAPI.cpp b/offload/libomptarget/OpenMP/InteropAPI.cpp
index d6ef17c06355c..b307011445170 100644
--- a/offload/libomptarget/OpenMP/InteropAPI.cpp
+++ b/offload/libomptarget/OpenMP/InteropAPI.cpp
@@ -18,14 +18,6 @@
#include <cstdlib>
#include <cstring>
-extern "C" {
-
-void __kmpc_omp_wait_deps(ident_t *loc_ref, int32_t gtid, int32_t ndeps,
- kmp_depend_info_t *dep_list, int32_t ndeps_noalias,
- kmp_depend_info_t *noalias_dep_list);
-
-} // extern "C"
-
namespace {
omp_interop_rc_t getPropertyErrorType(omp_interop_property_t Property) {
switch (Property) {
>From b6f1be43473010ff0eed9d1fe108fec65e064f37 Mon Sep 17 00:00:00 2001
From: Alex Duran <alejandro.duran at intel.com>
Date: Wed, 22 Oct 2025 14:50:11 +0200
Subject: [PATCH 2/3] remove empty line
---
offload/include/OffloadPolicy.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/offload/include/OffloadPolicy.h b/offload/include/OffloadPolicy.h
index 6656e2dd9b595..9bbd1fffb3798 100644
--- a/offload/include/OffloadPolicy.h
+++ b/offload/include/OffloadPolicy.h
@@ -22,7 +22,6 @@ enum kmp_target_offload_kind_t {
tgt_mandatory = 2
};
-
class OffloadPolicy {
OffloadPolicy(PluginManager &PM) {
>From 3d51e4336060d25ad50e754cb6d899df075ab6ad Mon Sep 17 00:00:00 2001
From: Alex Duran <alejandro.duran at intel.com>
Date: Thu, 23 Oct 2025 11:19:16 +0200
Subject: [PATCH 3/3] remove duplicate and another weak
---
offload/include/OpenMP/InternalTypes.h | 1 -
offload/include/OpenMP/omp.h | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/offload/include/OpenMP/InternalTypes.h b/offload/include/OpenMP/InternalTypes.h
index ce339f3f5358b..da6da8fb2270a 100644
--- a/offload/include/OpenMP/InternalTypes.h
+++ b/offload/include/OpenMP/InternalTypes.h
@@ -75,7 +75,6 @@ int32_t __kmpc_global_thread_num(void *);
bool __kmpc_omp_has_task_team(int32_t gtid);
void **__kmpc_omp_get_target_async_handle_ptr(int32_t gtid);
int __kmpc_get_target_offload(void);
-int __kmpc_get_target_offload(void);
kmp_task_t *__kmpc_omp_task_alloc(ident_t *loc_ref, int32_t gtid, int32_t flags,
size_t sizeof_kmp_task_t,
size_t sizeof_shareds,
diff --git a/offload/include/OpenMP/omp.h b/offload/include/OpenMP/omp.h
index 49d9f1fa75c20..768ca46a9bed0 100644
--- a/offload/include/OpenMP/omp.h
+++ b/offload/include/OpenMP/omp.h
@@ -40,7 +40,7 @@ typedef void *omp_depend_t;
/// API declarations
///{
-int omp_get_default_device(void) __attribute__((weak));
+int omp_get_default_device(void);
///}
More information about the llvm-commits
mailing list