[llvm] [openmp][nfc] Use builtin align instead of handcoding utils (PR #131918)
Jon Chesterfield via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 18 14:15:44 PDT 2025
https://github.com/JonChesterfield created https://github.com/llvm/llvm-project/pull/131918
Noticed while extracting the smartstack as a test case
>From 8683428e294f2c782eafd6d516568addbf73ac3c Mon Sep 17 00:00:00 2001
From: Jon Chesterfield <jonathanchesterfield at gmail.com>
Date: Tue, 18 Mar 2025 21:14:34 +0000
Subject: [PATCH] [openmp][nfc] Use builtin align instead of handcoding utils
---
offload/DeviceRTL/src/State.cpp | 8 ++++----
offload/include/Shared/Utils.h | 11 +----------
.../plugins-nextgen/common/src/PluginInterface.cpp | 2 +-
3 files changed, 6 insertions(+), 15 deletions(-)
diff --git a/offload/DeviceRTL/src/State.cpp b/offload/DeviceRTL/src/State.cpp
index cbe9735145340..62b03e7bba720 100644
--- a/offload/DeviceRTL/src/State.cpp
+++ b/offload/DeviceRTL/src/State.cpp
@@ -89,8 +89,8 @@ struct SharedMemorySmartStackTy {
/// Compute the size of the storage space reserved for a thread.
uint32_t computeThreadStorageTotal() {
uint32_t NumLanesInBlock = mapping::getNumberOfThreadsInBlock();
- return utils::alignDown((state::SharedScratchpadSize / NumLanesInBlock),
- allocator::ALIGNMENT);
+ return __builtin_align_down(state::SharedScratchpadSize / NumLanesInBlock,
+ allocator::ALIGNMENT);
}
/// Return the top address of the warp data stack, that is the first address
@@ -121,7 +121,7 @@ void *SharedMemorySmartStackTy::push(uint64_t Bytes) {
// First align the number of requested bytes.
/// FIXME: The stack shouldn't require worst-case padding. Alignment needs to
/// be passed in as an argument and the stack rewritten to support it.
- uint64_t AlignedBytes = utils::alignPtr(Bytes, allocator::ALIGNMENT);
+ uint64_t AlignedBytes = __builtin_align_up(Bytes, allocator::ALIGNMENT);
uint32_t StorageTotal = computeThreadStorageTotal();
@@ -149,7 +149,7 @@ void *SharedMemorySmartStackTy::push(uint64_t Bytes) {
}
void SharedMemorySmartStackTy::pop(void *Ptr, uint64_t Bytes) {
- uint64_t AlignedBytes = utils::alignPtr(Bytes, allocator::ALIGNMENT);
+ uint64_t AlignedBytes = __builtin_align_up(Bytes, allocator::ALIGNMENT);
if (utils::isSharedMemPtr(Ptr)) {
int TId = mapping::getThreadIdInBlock();
Usage[TId] -= AlignedBytes;
diff --git a/offload/include/Shared/Utils.h b/offload/include/Shared/Utils.h
index 523e6bc505b81..e3d7b002e1b44 100644
--- a/offload/include/Shared/Utils.h
+++ b/offload/include/Shared/Utils.h
@@ -30,18 +30,9 @@ template <typename Ty1, typename Ty2> Ty1 *advancePtr(Ty1 *Ptr, Ty2 Offset) {
return (Ty1 *)(const_cast<char *>((const char *)(Ptr)) + Offset);
}
-/// Return \p V aligned "upwards" according to \p Align.
-template <typename Ty1, typename Ty2> inline Ty1 alignPtr(Ty1 V, Ty2 Align) {
- return reinterpret_cast<Ty1>(((uintptr_t(V) + Align - 1) / Align) * Align);
-}
-/// Return \p V aligned "downwards" according to \p Align.
-template <typename Ty1, typename Ty2> inline Ty1 alignDown(Ty1 V, Ty2 Align) {
- return V - V % Align;
-}
-
/// Round up \p V to a \p Boundary.
template <typename Ty> inline Ty roundUp(Ty V, Ty Boundary) {
- return alignPtr(V, Boundary);
+ return __builtin_align_up(V, Boundary);
}
/// Return the first bit set in \p V.
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp
index 4d2ebcbc7be8e..67c8c900ac66f 100644
--- a/offload/plugins-nextgen/common/src/PluginInterface.cpp
+++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp
@@ -78,7 +78,7 @@ struct RecordReplayTy {
Device->allocate(1024, /*HstPtr=*/nullptr, TARGET_ALLOC_DEFAULT);
Device->free(Addr);
// Align Address to MaxMemoryAllocation
- Addr = (void *)utils::alignPtr((Addr), MaxMemoryAllocation);
+ Addr = __builtin_align_up(Addr, MaxMemoryAllocation);
return Addr;
}
More information about the llvm-commits
mailing list