[mlir][PDLL] Allow (and ignore) `-D` tablegen macros. (#124166)
[llvm-project.git] / libc / src / stdlib / gpu / aligned_alloc.cpp
blobcd2c7e55128fe02062d1185af3e8179f4ff06e8d
1 //===-- GPU Implementation of aligned_alloc -------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/stdlib/aligned_alloc.h"
11 #include "src/__support/GPU/allocator.h"
12 #include "src/__support/common.h"
13 #include "src/__support/macros/config.h"
15 namespace LIBC_NAMESPACE_DECL {
17 LLVM_LIBC_FUNCTION(void *, aligned_alloc, (size_t alignment, size_t size)) {
18 if ((alignment & -alignment) != alignment)
19 return nullptr;
21 void *ptr = gpu::allocate(size);
22 if ((reinterpret_cast<uintptr_t>(ptr) & (alignment - 1)) != 0) {
23 gpu::deallocate(ptr);
24 return nullptr;
26 return ptr;
29 } // namespace LIBC_NAMESPACE_DECL