[llvm] 1deea71 - BuildLibCalls: simplify switch statement slightly
Augie Fackler via llvm-commits
llvm-commits at lists.llvm.org
Tue May 3 10:17:40 PDT 2022
Author: Augie Fackler
Date: 2022-05-03T13:17:33-04:00
New Revision: 1deea714b3b4023b2d50f73503ee2782c3b59fe7
URL: https://github.com/llvm/llvm-project/commit/1deea714b3b4023b2d50f73503ee2782c3b59fe7
DIFF: https://github.com/llvm/llvm-project/commit/1deea714b3b4023b2d50f73503ee2782c3b59fe7.diff
LOG: BuildLibCalls: simplify switch statement slightly
Per feedback on D123086 after submit.
Also added a test for vec_malloc et al attribute inference to show it's
doing the right thing.
The new tests exposed a defect, corrected by adding vec_free to the list of
free functions in MemoryBuiltins.cpp, which had been overlooked all the
way back in D94710, over a year ago.
Differential Revision: https://reviews.llvm.org/D124859
Added:
Modified:
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Transforms/Utils/BuildLibCalls.cpp
llvm/test/Transforms/InferFunctionAttrs/annotate.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 151afade1faa5..67793c14c18a4 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -445,6 +445,7 @@ struct FreeFnsTy {
// clang-format off
static const std::pair<LibFunc, FreeFnsTy> FreeFnData[] = {
{LibFunc_free, {1, MallocFamily::Malloc}},
+ {LibFunc_vec_free, {1, MallocFamily::VecMalloc}},
{LibFunc_ZdlPv, {1, MallocFamily::CPPNew}}, // operator delete(void*)
{LibFunc_ZdaPv, {1, MallocFamily::CPPNewArray}}, // operator delete[](void*)
{LibFunc_msvc_delete_ptr32, {1, MallocFamily::MSVCNew}}, // operator delete(void*)
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index 40fd40756ae5e..75dbf7aa2372e 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -442,10 +442,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
LLVM_FALLTHROUGH;
case LibFunc_valloc:
case LibFunc_malloc:
- Changed |= setAllocFamily(F, "malloc");
- LLVM_FALLTHROUGH;
case LibFunc_vec_malloc:
- Changed |= setAllocFamily(F, "vec_malloc");
+ Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_malloc ? "vec_malloc"
+ : "malloc");
Changed |= setAllocSize(F, 0, None);
Changed |= setOnlyAccessesInaccessibleMemory(F);
Changed |= setRetAndArgsNoUndef(F);
@@ -532,10 +531,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
return Changed;
case LibFunc_realloc:
case LibFunc_reallocf:
- Changed |= setAllocFamily(F, "malloc");
- LLVM_FALLTHROUGH;
case LibFunc_vec_realloc:
- Changed |= setAllocFamily(F, "vec_malloc");
+ Changed |= setAllocFamily(
+ F, TheLibFunc == LibFunc_vec_realloc ? "vec_malloc" : "malloc");
Changed |= setAllocatedPointerParam(F, 0);
Changed |= setAllocSize(F, 1, None);
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
@@ -610,10 +608,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
Changed |= setOnlyWritesMemory(F, 0);
return Changed;
case LibFunc_calloc:
- Changed |= setAllocFamily(F, "malloc");
- LLVM_FALLTHROUGH;
case LibFunc_vec_calloc:
- Changed |= setAllocFamily(F, "vec_malloc");
+ Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_calloc ? "vec_malloc"
+ : "malloc");
Changed |= setAllocSize(F, 0, 1);
Changed |= setOnlyAccessesInaccessibleMemory(F);
Changed |= setRetAndArgsNoUndef(F);
@@ -672,10 +669,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
Changed |= setDoesNotCapture(F, 0);
return Changed;
case LibFunc_free:
- Changed |= setAllocFamily(F, "malloc");
- LLVM_FALLTHROUGH;
case LibFunc_vec_free:
- Changed |= setAllocFamily(F, "vec_malloc");
+ Changed |= setAllocFamily(F, TheLibFunc == LibFunc_vec_free ? "vec_malloc"
+ : "malloc");
Changed |= setAllocatedPointerParam(F, 0);
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
Changed |= setArgsNoUndef(F);
diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
index 4b8d944d77637..5b737654bd303 100644
--- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
+++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll
@@ -3,6 +3,7 @@
; RUN: opt < %s -mtriple=x86_64-apple-macosx10.8.0 -inferattrs -S | FileCheck --match-full-lines --check-prefixes=CHECK,CHECK-KNOWN,CHECK-NOLINUX,CHECK-OPEN,CHECK-DARWIN %s
; RUN: opt < %s -mtriple=x86_64-unknown-linux-gnu -inferattrs -S | FileCheck --match-full-lines --check-prefixes=CHECK,CHECK-KNOWN,CHECK-LINUX %s
; RUN: opt < %s -mtriple=nvptx -inferattrs -S | FileCheck --match-full-lines --check-prefixes=CHECK-NOLINUX,CHECK-NVPTX %s
+; RUN: opt < %s -mtriple=powerpc-ibm-aix-xcoff -inferattrs -S | FileCheck --match-full-lines --check-prefixes=CHECK-AIX %s
declare i32 @__nvvm_reflect(i8*)
; CHECK-NVPTX: declare noundef i32 @__nvvm_reflect(i8* noundef) [[NOFREE_NOUNWIND_READNONE:#[0-9]+]]
@@ -292,6 +293,9 @@ declare void @bzero(i8*, i64)
; CHECK: declare noalias noundef i8* @calloc(i64 noundef, i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCSIZE01_FAMILY_MALLOC:#[0-9]+]]
declare i8* @calloc(i64, i64)
+; CHECK-AIX: declare noalias noundef i8* @vec_calloc(i64 noundef, i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCSIZE01_FAMILY_VEC_MALLOC:#[0-9]+]]
+declare i8* @vec_calloc(i64, i64)
+
; CHECK: declare double @cbrt(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
declare double @cbrt(double)
@@ -492,6 +496,9 @@ declare i64 @fread(i8*, i64, i64, %opaque*)
; CHECK: declare void @free(i8* allocptr nocapture noundef) [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_FAMILY_MALLOC:#[0-9]+]]
declare void @free(i8*)
+; CHECK-AIX: declare void @vec_free(i8* allocptr nocapture noundef) [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_FAMILY_VEC_MALLOC:#[0-9]+]]
+declare void @vec_free(i8*)
+
; CHECK: declare double @frexp(double, i32* nocapture) [[NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare double @frexp(double, i32*)
@@ -656,6 +663,9 @@ declare i32 @lstat64(i8*, %opaque*)
; CHECK: declare noalias noundef i8* @malloc(i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCSIZE0_FAMILY_MALLOC:#[0-9]+]]
declare i8* @malloc(i64)
+; CHECK-AIX: declare noalias noundef i8* @vec_malloc(i64 noundef) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCSIZE0_FAMILY_VEC_MALLOC:#[0-9]+]]
+declare i8* @vec_malloc(i64)
+
; CHECK-LINUX: declare noalias noundef i8* @memalign(i64 allocalign, i64) [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
declare i8* @memalign(i64, i64)
@@ -780,6 +790,9 @@ declare i8* @realloc(i8*, i64)
; CHECK: declare noalias noundef i8* @reallocf(i8* allocptr nocapture, i64 noundef) [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCSIZE_FAMILY_MALLOC]]
declare i8* @reallocf(i8*, i64)
+; CHECK-AIX: declare noalias noundef i8* @vec_realloc(i8* allocptr nocapture, i64 noundef) [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCSIZE_FAMILY_VEC_MALLOC:#[0-9]+]]
+declare i8* @vec_realloc(i8*, i64)
+
; CHECK: declare noundef i8* @realpath(i8* nocapture noundef readonly, i8* noundef) [[NOFREE_NOUNWIND]]
declare i8* @realpath(i8*, i8*)
@@ -1080,3 +1093,8 @@ declare void @memset_pattern16(i8*, i8*, i64)
; CHECK-DAG: attributes [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND_WILLRETURN_FAMILY_MALLOC]] = { inaccessiblemem_or_argmemonly mustprogress nofree nounwind willreturn "alloc-family"="malloc" }
; CHECK-NVPTX-DAG: attributes [[NOFREE_NOUNWIND_READNONE]] = { nofree nosync nounwind readnone }
+
+; CHECK-AIX-DAG: attributes [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCSIZE0_FAMILY_VEC_MALLOC]] = { inaccessiblememonly mustprogress nofree nounwind willreturn allocsize(0) "alloc-family"="vec_malloc" }
+; CHECK-AIX-DAG: attributes [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_FAMILY_VEC_MALLOC]] = { inaccessiblemem_or_argmemonly mustprogress nounwind willreturn "alloc-family"="vec_malloc" }
+; CHECK-AIX-DAG: attributes [[INACCESSIBLEMEMORARGMEMONLY_NOUNWIND_WILLRETURN_ALLOCSIZE_FAMILY_VEC_MALLOC]] = { inaccessiblemem_or_argmemonly mustprogress nounwind willreturn allocsize(1) "alloc-family"="vec_malloc" }
+; CHECK-AIX-DAG: attributes [[INACCESSIBLEMEMONLY_NOFREE_NOUNWIND_WILLRETURN_ALLOCSIZE01_FAMILY_VEC_MALLOC]] = { inaccessiblememonly mustprogress nofree nounwind willreturn allocsize(0,1) "alloc-family"="vec_malloc" }
More information about the llvm-commits
mailing list