Skip to content

Commit b69081e

Browse files
authored
Attributes (#69358)
- [Libomptarget] Make the references to 'malloc' and 'free' weak. - [Libomptarget][NFC] Use C++ style attributes instead
1 parent 1e5fe67 commit b69081e

File tree

9 files changed

+36
-42
lines changed

9 files changed

+36
-42
lines changed

openmp/libomptarget/DeviceRTL/include/State.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ inline uint32_t &lookupImpl(uint32_t state::ICVStateTy::*Var,
176176
return TeamState.ICVState.*Var;
177177
}
178178

179-
__attribute__((always_inline, flatten)) inline uint32_t &
179+
[[gnu::always_inline, gnu::flatten]] inline uint32_t &
180180
lookup32(ValueKind Kind, bool IsReadonly, IdentTy *Ident, bool ForceTeamState) {
181181
switch (Kind) {
182182
case state::VK_NThreads:
@@ -218,7 +218,7 @@ lookup32(ValueKind Kind, bool IsReadonly, IdentTy *Ident, bool ForceTeamState) {
218218
__builtin_unreachable();
219219
}
220220

221-
__attribute__((always_inline, flatten)) inline void *&
221+
[[gnu::always_inline, gnu::flatten]] inline void *&
222222
lookupPtr(ValueKind Kind, bool IsReadonly, bool ForceTeamState) {
223223
switch (Kind) {
224224
case state::VK_ParallelRegionFn:
@@ -232,47 +232,45 @@ lookupPtr(ValueKind Kind, bool IsReadonly, bool ForceTeamState) {
232232
/// A class without actual state used to provide a nice interface to lookup and
233233
/// update ICV values we can declare in global scope.
234234
template <typename Ty, ValueKind Kind> struct Value {
235-
__attribute__((flatten, always_inline)) operator Ty() {
235+
[[gnu::flatten, gnu::always_inline]] operator Ty() {
236236
return lookup(/* IsReadonly */ true, /* IdentTy */ nullptr,
237237
/* ForceTeamState */ false);
238238
}
239239

240-
__attribute__((flatten, always_inline)) Value &operator=(const Ty &Other) {
240+
[[gnu::flatten, gnu::always_inline]] Value &operator=(const Ty &Other) {
241241
set(Other, /* IdentTy */ nullptr);
242242
return *this;
243243
}
244244

245-
__attribute__((flatten, always_inline)) Value &operator++() {
245+
[[gnu::flatten, gnu::always_inline]] Value &operator++() {
246246
inc(1, /* IdentTy */ nullptr);
247247
return *this;
248248
}
249249

250-
__attribute__((flatten, always_inline)) Value &operator--() {
250+
[[gnu::flatten, gnu::always_inline]] Value &operator--() {
251251
inc(-1, /* IdentTy */ nullptr);
252252
return *this;
253253
}
254254

255-
__attribute__((flatten, always_inline)) void
255+
[[gnu::flatten, gnu::always_inline]] void
256256
assert_eq(const Ty &V, IdentTy *Ident = nullptr,
257257
bool ForceTeamState = false) {
258258
ASSERT(lookup(/* IsReadonly */ true, Ident, ForceTeamState) == V, nullptr);
259259
}
260260

261261
private:
262-
__attribute__((flatten, always_inline)) Ty &
262+
[[gnu::flatten, gnu::always_inline]] Ty &
263263
lookup(bool IsReadonly, IdentTy *Ident, bool ForceTeamState) {
264264
Ty &t = lookup32(Kind, IsReadonly, Ident, ForceTeamState);
265265
return t;
266266
}
267267

268-
__attribute__((flatten, always_inline)) Ty &inc(int UpdateVal,
269-
IdentTy *Ident) {
268+
[[gnu::flatten, gnu::always_inline]] Ty &inc(int UpdateVal, IdentTy *Ident) {
270269
return (lookup(/* IsReadonly */ false, Ident, /* ForceTeamState */ false) +=
271270
UpdateVal);
272271
}
273272

274-
__attribute__((flatten, always_inline)) Ty &set(Ty UpdateVal,
275-
IdentTy *Ident) {
273+
[[gnu::flatten, gnu::always_inline]] Ty &set(Ty UpdateVal, IdentTy *Ident) {
276274
return (lookup(/* IsReadonly */ false, Ident, /* ForceTeamState */ false) =
277275
UpdateVal);
278276
}
@@ -284,12 +282,12 @@ template <typename Ty, ValueKind Kind> struct Value {
284282
/// a nice interface to lookup and update ICV values
285283
/// we can declare in global scope.
286284
template <typename Ty, ValueKind Kind> struct PtrValue {
287-
__attribute__((flatten, always_inline)) operator Ty() {
285+
[[gnu::flatten, gnu::always_inline]] operator Ty() {
288286
return lookup(/* IsReadonly */ true, /* IdentTy */ nullptr,
289287
/* ForceTeamState */ false);
290288
}
291289

292-
__attribute__((flatten, always_inline)) PtrValue &operator=(const Ty Other) {
290+
[[gnu::flatten, gnu::always_inline]] PtrValue &operator=(const Ty Other) {
293291
set(Other);
294292
return *this;
295293
}

openmp/libomptarget/DeviceRTL/include/Synchronization.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void threads(atomic::OrderingTy Ordering);
115115
/// (hence all threads in the block are "aligned"). Also perform a fence before
116116
/// and after the barrier according to \p Ordering. Note that the
117117
/// fence might be part of the barrier if the target offers this.
118-
__attribute__((noinline)) void threadsAligned(atomic::OrderingTy Ordering);
118+
[[gnu::noinline]] void threadsAligned(atomic::OrderingTy Ordering);
119119

120120
#pragma omp end assumes
121121
///}

openmp/libomptarget/DeviceRTL/include/Utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ template <typename DstTy, typename SrcTy> inline DstTy convertViaPun(SrcTy V) {
8383
}
8484

8585
/// A pointer variable that has by design an `undef` value. Use with care.
86-
__attribute__((loader_uninitialized)) static void *const UndefPtr;
86+
[[clang::loader_uninitialized]] static void *const UndefPtr;
8787

8888
#define OMP_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
8989
#define OMP_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)

openmp/libomptarget/DeviceRTL/src/Configuration.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ using namespace ompx;
2727

2828
// This variable should be visibile to the plugin so we override the default
2929
// hidden visibility.
30-
DeviceEnvironmentTy CONSTANT(__omp_rtl_device_environment)
31-
__attribute__((used, retain, weak, visibility("protected")));
30+
[[gnu::used, gnu::retain, gnu::weak,
31+
gnu::visibility("protected")]] DeviceEnvironmentTy
32+
CONSTANT(__omp_rtl_device_environment);
3233

3334
uint32_t config::getDebugKind() {
3435
return __omp_rtl_debug_kind & __omp_rtl_device_environment.DebugKind;

openmp/libomptarget/DeviceRTL/src/Mapping.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ uint32_t mapping::getNumberOfProcessorElements() {
345345

346346
// TODO: This is a workaround for initialization coming from kernels outside of
347347
// the TU. We will need to solve this more correctly in the future.
348-
int __attribute__((weak)) SHARED(IsSPMDMode);
348+
[[gnu::weak]] int SHARED(IsSPMDMode);
349349

350350
void mapping::init(bool IsSPMD) {
351351
if (mapping::isInitialThreadInLevel0(IsSPMD))
@@ -358,15 +358,15 @@ bool mapping::isGenericMode() { return !isSPMDMode(); }
358358
///}
359359

360360
extern "C" {
361-
__attribute__((noinline)) uint32_t __kmpc_get_hardware_thread_id_in_block() {
361+
[[gnu::noinline]] uint32_t __kmpc_get_hardware_thread_id_in_block() {
362362
return mapping::getThreadIdInBlock();
363363
}
364364

365-
__attribute__((noinline)) uint32_t __kmpc_get_hardware_num_threads_in_block() {
365+
[[gnu::noinline]] uint32_t __kmpc_get_hardware_num_threads_in_block() {
366366
return impl::getNumberOfThreadsInBlock(mapping::DIM_X);
367367
}
368368

369-
__attribute__((noinline)) uint32_t __kmpc_get_warp_size() {
369+
[[gnu::noinline]] uint32_t __kmpc_get_warp_size() {
370370
return impl::getWarpSize();
371371
}
372372
}

openmp/libomptarget/DeviceRTL/src/Parallelism.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ uint32_t determineNumberOfThreads(int32_t NumThreadsClause) {
6868
}
6969

7070
// Invoke an outlined parallel function unwrapping arguments (up to 32).
71-
__attribute__((always_inline)) void invokeMicrotask(int32_t global_tid,
72-
int32_t bound_tid, void *fn,
73-
void **args,
74-
int64_t nargs) {
71+
[[clang::always_inline]] void invokeMicrotask(int32_t global_tid,
72+
int32_t bound_tid, void *fn,
73+
void **args, int64_t nargs) {
7574
switch (nargs) {
7675
#include "generated_microtask_cases.gen"
7776
default:
@@ -84,7 +83,7 @@ __attribute__((always_inline)) void invokeMicrotask(int32_t global_tid,
8483

8584
extern "C" {
8685

87-
__attribute__((always_inline)) void
86+
[[clang::always_inline]] void
8887
__kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
8988
int32_t num_threads, int proc_bind, void *fn,
9089
void *wrapper_fn, void **args, int64_t nargs) {
@@ -262,8 +261,7 @@ __kmpc_parallel_51(IdentTy *ident, int32_t, int32_t if_expr,
262261
__kmpc_end_sharing_variables();
263262
}
264263

265-
__attribute__((noinline)) bool
266-
__kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) {
264+
[[clang::noinline]] bool __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) {
267265
// Work function and arguments for L1 parallel region.
268266
*WorkFn = state::ParallelRegionFn;
269267

@@ -277,7 +275,7 @@ __kmpc_kernel_parallel(ParallelRegionFnTy *WorkFn) {
277275
return ThreadIsActive;
278276
}
279277

280-
__attribute__((noinline)) void __kmpc_kernel_end_parallel() {
278+
[[clang::noinline]] void __kmpc_kernel_end_parallel() {
281279
// In case we have modified an ICV for this thread before a ThreadState was
282280
// created. We drop it now to not contaminate the next parallel region.
283281
ASSERT(!mapping::isSPMDMode(), nullptr);

openmp/libomptarget/DeviceRTL/src/State.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using namespace ompx;
3131
constexpr const uint32_t Alignment = 16;
3232

3333
/// External symbol to access dynamic shared memory.
34-
extern unsigned char DynamicSharedBuffer[] __attribute__((aligned(Alignment)));
34+
[[gnu::aligned(Alignment)]] extern unsigned char DynamicSharedBuffer[];
3535
#pragma omp allocate(DynamicSharedBuffer) allocator(omp_pteam_mem_alloc)
3636

3737
/// The kernel environment passed to the init method by the compiler.
@@ -105,10 +105,8 @@ struct SharedMemorySmartStackTy {
105105
}
106106

107107
/// The actual storage, shared among all warps.
108-
unsigned char Data[state::SharedScratchpadSize]
109-
__attribute__((aligned(Alignment)));
110-
unsigned char Usage[mapping::MaxThreadsPerTeam]
111-
__attribute__((aligned(Alignment)));
108+
[[gnu::aligned(Alignment)]] unsigned char Data[state::SharedScratchpadSize];
109+
[[gnu::aligned(Alignment)]] unsigned char Usage[mapping::MaxThreadsPerTeam];
112110
};
113111

114112
static_assert(state::SharedScratchpadSize / mapping::MaxThreadsPerTeam <= 256,
@@ -423,11 +421,11 @@ int omp_get_initial_device(void) { return -1; }
423421
}
424422

425423
extern "C" {
426-
__attribute__((noinline)) void *__kmpc_alloc_shared(uint64_t Bytes) {
424+
[[clang::noinline]] void *__kmpc_alloc_shared(uint64_t Bytes) {
427425
return memory::allocShared(Bytes, "Frontend alloc shared");
428426
}
429427

430-
__attribute__((noinline)) void __kmpc_free_shared(void *Ptr, uint64_t Bytes) {
428+
[[clang::noinline]] void __kmpc_free_shared(void *Ptr, uint64_t Bytes) {
431429
memory::freeShared(Ptr, Bytes, "Frontend free shared");
432430
}
433431

openmp/libomptarget/DeviceRTL/src/Synchronization.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,12 @@ void __kmpc_barrier(IdentTy *Loc, int32_t TId) {
523523
impl::namedBarrier();
524524
}
525525

526-
__attribute__((noinline)) void __kmpc_barrier_simple_spmd(IdentTy *Loc,
527-
int32_t TId) {
526+
[[clang::noinline]] void __kmpc_barrier_simple_spmd(IdentTy *Loc, int32_t TId) {
528527
synchronize::threadsAligned(atomic::OrderingTy::seq_cst);
529528
}
530529

531-
__attribute__((noinline)) void __kmpc_barrier_simple_generic(IdentTy *Loc,
532-
int32_t TId) {
530+
[[clang::noinline]] void __kmpc_barrier_simple_generic(IdentTy *Loc,
531+
int32_t TId) {
533532
synchronize::threads(atomic::OrderingTy::seq_cst);
534533
}
535534

openmp/libomptarget/DeviceRTL/src/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
using namespace ompx;
2121

22-
extern "C" __attribute__((weak)) int IsSPMDMode;
22+
extern "C" [[gnu::weak]] int IsSPMDMode;
2323

2424
namespace impl {
2525

0 commit comments

Comments
 (0)