Skip to content

Commit b32735d

Browse files
committed
BuildLibCalls: add allocalign attributes for memalign and aligned_alloc
This gets us close to being able to remove a column from the table in MemoryBuiltins.cpp. Differential Revision: https://reviews.llvm.org/D117923
1 parent d664c4b commit b32735d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ static bool setWillReturn(Function &F) {
222222
return true;
223223
}
224224

225+
static bool setAlignedAllocParam(Function &F, unsigned ArgNo) {
226+
if (F.hasParamAttribute(ArgNo, Attribute::AllocAlign))
227+
return false;
228+
F.addParamAttr(ArgNo, Attribute::AllocAlign);
229+
return true;
230+
}
231+
225232
bool llvm::inferLibFuncAttributes(Module *M, StringRef Name,
226233
const TargetLibraryInfo &TLI) {
227234
Function *F = M->getFunction(Name);
@@ -414,6 +421,8 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
414421
Changed |= setOnlyReadsMemory(F, 0);
415422
return Changed;
416423
case LibFunc_aligned_alloc:
424+
Changed |= setAlignedAllocParam(F, 0);
425+
LLVM_FALLTHROUGH;
417426
case LibFunc_valloc:
418427
case LibFunc_malloc:
419428
case LibFunc_vec_malloc:
@@ -479,6 +488,7 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
479488
Changed |= setOnlyReadsMemory(F, 1);
480489
return Changed;
481490
case LibFunc_memalign:
491+
Changed |= setAlignedAllocParam(F, 0);
482492
Changed |= setOnlyAccessesInaccessibleMemory(F);
483493
Changed |= setRetNoUndef(F);
484494
Changed |= setDoesNotThrow(F);

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ declare x86_fp80 @acoshl(x86_fp80)
219219
; CHECK: declare x86_fp80 @acosl(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
220220
declare x86_fp80 @acosl(x86_fp80)
221221

222-
; CHECK: declare noalias noundef i8* @aligned_alloc(i64 noundef, i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
222+
; CHECK: declare noalias noundef i8* @aligned_alloc(i64 allocalign noundef, i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
223223
declare i8* @aligned_alloc(i64, i64)
224224

225225
; CHECK: declare double @asin(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
@@ -656,7 +656,7 @@ declare i32 @lstat64(i8*, %opaque*)
656656
; CHECK: declare noalias noundef i8* @malloc(i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
657657
declare i8* @malloc(i64)
658658

659-
; CHECK-LINUX: declare noalias noundef i8* @memalign(i64, i64) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]
659+
; CHECK-LINUX: declare noalias noundef i8* @memalign(i64 allocalign, i64) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
660660
declare i8* @memalign(i64, i64)
661661

662662
; CHECK: declare i8* @memccpy(i8* noalias writeonly, i8* noalias nocapture readonly, i32, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_WILLRETURN]]

0 commit comments

Comments
 (0)