Skip to content

Commit deb0f3c

Browse files
[openmp][nfc] Use builtin align in the devicertl (llvm#131918)
Noticed while extracting the smartstack as a test case
1 parent 70bf5e5 commit deb0f3c

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

offload/DeviceRTL/src/State.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ struct SharedMemorySmartStackTy {
8989
/// Compute the size of the storage space reserved for a thread.
9090
uint32_t computeThreadStorageTotal() {
9191
uint32_t NumLanesInBlock = mapping::getNumberOfThreadsInBlock();
92-
return utils::alignDown((state::SharedScratchpadSize / NumLanesInBlock),
93-
allocator::ALIGNMENT);
92+
return __builtin_align_down(state::SharedScratchpadSize / NumLanesInBlock,
93+
allocator::ALIGNMENT);
9494
}
9595

9696
/// Return the top address of the warp data stack, that is the first address
@@ -121,7 +121,7 @@ void *SharedMemorySmartStackTy::push(uint64_t Bytes) {
121121
// First align the number of requested bytes.
122122
/// FIXME: The stack shouldn't require worst-case padding. Alignment needs to
123123
/// be passed in as an argument and the stack rewritten to support it.
124-
uint64_t AlignedBytes = utils::alignPtr(Bytes, allocator::ALIGNMENT);
124+
uint64_t AlignedBytes = __builtin_align_up(Bytes, allocator::ALIGNMENT);
125125

126126
uint32_t StorageTotal = computeThreadStorageTotal();
127127

@@ -149,7 +149,7 @@ void *SharedMemorySmartStackTy::push(uint64_t Bytes) {
149149
}
150150

151151
void SharedMemorySmartStackTy::pop(void *Ptr, uint64_t Bytes) {
152-
uint64_t AlignedBytes = utils::alignPtr(Bytes, allocator::ALIGNMENT);
152+
uint64_t AlignedBytes = __builtin_align_up(Bytes, allocator::ALIGNMENT);
153153
if (utils::isSharedMemPtr(Ptr)) {
154154
int TId = mapping::getThreadIdInBlock();
155155
Usage[TId] -= AlignedBytes;

offload/include/Shared/Utils.h

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ template <typename Ty1, typename Ty2> Ty1 *advancePtr(Ty1 *Ptr, Ty2 Offset) {
3434
template <typename Ty1, typename Ty2> inline Ty1 alignPtr(Ty1 V, Ty2 Align) {
3535
return reinterpret_cast<Ty1>(((uintptr_t(V) + Align - 1) / Align) * Align);
3636
}
37-
/// Return \p V aligned "downwards" according to \p Align.
38-
template <typename Ty1, typename Ty2> inline Ty1 alignDown(Ty1 V, Ty2 Align) {
39-
return V - V % Align;
40-
}
4137

4238
/// Round up \p V to a \p Boundary.
4339
template <typename Ty> inline Ty roundUp(Ty V, Ty Boundary) {

0 commit comments

Comments
 (0)