[mlir] Fall back to posix_memalign for aligned_alloc on MacOS

aligned_alloc was added in MacOS 10.15, some users want to support older
versions. The runtime functions makes this easy, so just put in a call
to posix_memalign, which provides the same functionality.
This commit is contained in:
Benjamin Kramer 2022-07-26 11:14:37 +02:00
parent ae222dae56
commit 48a1a993fb

View file

@ -127,6 +127,12 @@ extern "C" void *_mlir_alloc(uint64_t size) { return malloc(size); }
extern "C" void *_mlir_aligned_alloc(uint64_t alignment, uint64_t size) {
#ifdef _WIN32
return _aligned_malloc(size, alignment);
#elif defined(__APPLE__)
// aligned_alloc was added in MacOS 10.15. Fall back to posix_memalign to also
// support older versions.
void *result = nullptr;
(void)::posix_memalign(&result, alignment, size);
return result;
#else
return aligned_alloc(alignment, size);
#endif