[Clang] Add attributes alloc_size and alloc_align to mm_malloc

LLVM optimizes source codes with mm_malloc better, especially due to alignment info.

alloc align https://clang.llvm.org/docs/AttributeReference.html#alloc-align
alloc size https://clang.llvm.org/docs/AttributeReference.html#alloc-size

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D117091
This commit is contained in:
Dávid Bolvanský 2022-02-17 19:58:12 +01:00
parent 027c16bef4
commit 2c91754a13
3 changed files with 22 additions and 3 deletions

View File

@ -28,9 +28,9 @@ extern "C" int posix_memalign(void **__memptr, size_t __alignment, size_t __size
#if !(defined(_WIN32) && defined(_mm_malloc))
static __inline__ void *__attribute__((__always_inline__, __nodebug__,
__malloc__))
_mm_malloc(size_t __size, size_t __align)
{
__malloc__, __alloc_size__(1),
__alloc_align__(2)))
_mm_malloc(size_t __size, size_t __align) {
if (__align == 1) {
return malloc(__size);
}

View File

@ -0,0 +1,7 @@
#if defined(__MINGW32__)
void *__mingw_aligned_malloc(size_t, size_t);
void __mingw_aligned_free(void *);
#elif defined(_WIN32)
void *_aligned_malloc(size_t, size_t);
void _aligned_free(void *);
#endif

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -internal-isystem %S/Inputs/include %s -emit-llvm -O1 -triple x86_64-linux-gnu -o - | FileCheck %s
#include <mm_malloc.h>
_Bool align_test(void) {
// CHECK-LABEL: @align_test(
// CHECK: ret i1 true
void *p = _mm_malloc(1024, 16);
_Bool ret = ((__UINTPTR_TYPE__)p % 16) == 0;
_mm_free(p);
return ret;
}