diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def --- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def +++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def @@ -1420,6 +1420,18 @@ /// void *valloc(size_t size); TLI_DEFINE_ENUM_INTERNAL(valloc) TLI_DEFINE_STRING_INTERNAL("valloc") +/// void *vec_calloc(size_t count, size_t size); +TLI_DEFINE_ENUM_INTERNAL(vec_calloc) +TLI_DEFINE_STRING_INTERNAL("vec_calloc") +/// void vec_free(void *ptr); +TLI_DEFINE_ENUM_INTERNAL(vec_free) +TLI_DEFINE_STRING_INTERNAL("vec_free") +/// void *vec_malloc(size_t size); +TLI_DEFINE_ENUM_INTERNAL(vec_malloc) +TLI_DEFINE_STRING_INTERNAL("vec_malloc") +/// void *vec_realloc(void *ptr, size_t size); +TLI_DEFINE_ENUM_INTERNAL(vec_realloc) +TLI_DEFINE_STRING_INTERNAL("vec_realloc") /// int vfprintf(FILE *stream, const char *format, va_list ap); TLI_DEFINE_ENUM_INTERNAL(vfprintf) TLI_DEFINE_STRING_INTERNAL("vfprintf") diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -72,6 +72,7 @@ // know which functions are nounwind, noalias, nocapture parameters, etc. static const std::pair AllocationFnData[] = { {LibFunc_malloc, {MallocLike, 1, 0, -1}}, + {LibFunc_vec_malloc, {MallocLike, 1, 0, -1}}, {LibFunc_valloc, {MallocLike, 1, 0, -1}}, {LibFunc_Znwj, {OpNewLike, 1, 0, -1}}, // new(unsigned int) {LibFunc_ZnwjRKSt9nothrow_t, {MallocLike, 2, 0, -1}}, // new(unsigned int, nothrow) @@ -103,7 +104,9 @@ {LibFunc_msvc_new_array_longlong_nothrow, {MallocLike, 2, 0, -1}}, // new[](unsigned long long, nothrow) {LibFunc_aligned_alloc, {AlignedAllocLike, 2, 1, -1}}, {LibFunc_calloc, {CallocLike, 2, 0, 1}}, + {LibFunc_vec_calloc, {CallocLike, 2, 0, 1}}, {LibFunc_realloc, {ReallocLike, 2, 1, -1}}, + {LibFunc_vec_realloc, {ReallocLike, 2, 1, -1}}, {LibFunc_reallocf, {ReallocLike, 2, 1, -1}}, {LibFunc_strdup, {StrDupLike, 1, -1, -1}}, {LibFunc_strndup, {StrDupLike, 2, 1, -1}} diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -551,6 +551,14 @@ TLI.setUnavailable(LibFunc_nvvm_reflect); } + // These vec_malloc/free routines are only available on AIX. + if (!T.isOSAIX()) { + TLI.setUnavailable(LibFunc_vec_calloc); + TLI.setUnavailable(LibFunc_vec_malloc); + TLI.setUnavailable(LibFunc_vec_realloc); + TLI.setUnavailable(LibFunc_vec_free); + } + TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); } @@ -831,6 +839,7 @@ case LibFunc_system: return (NumParams == 1 && FTy.getParamType(0)->isPointerTy()); case LibFunc_malloc: + case LibFunc_vec_malloc: return (NumParams == 1 && FTy.getReturnType()->isPointerTy()); case LibFunc_memcmp: return (NumParams == 3 && FTy.getReturnType()->isIntegerTy(32) && @@ -885,6 +894,7 @@ return (FTy.getReturnType()->isPointerTy()); case LibFunc_realloc: case LibFunc_reallocf: + case LibFunc_vec_realloc: return (NumParams == 2 && FTy.getReturnType() == PCharTy && FTy.getParamType(0) == FTy.getReturnType() && IsSizeTTy(FTy.getParamType(1))); @@ -912,6 +922,7 @@ case LibFunc_bzero: return (NumParams == 2 && FTy.getParamType(0)->isPointerTy()); case LibFunc_calloc: + case LibFunc_vec_calloc: return (NumParams == 2 && FTy.getReturnType()->isPointerTy()); case LibFunc_atof: @@ -962,6 +973,7 @@ case LibFunc_mkdir: case LibFunc_mktime: case LibFunc_times: + case LibFunc_vec_free: return (NumParams != 0 && FTy.getParamType(0)->isPointerTy()); case LibFunc_fopen: diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -391,6 +391,7 @@ Changed |= setOnlyReadsMemory(F, 0); return Changed; case LibFunc_malloc: + case LibFunc_vec_malloc: Changed |= setOnlyAccessesInaccessibleMemory(F); Changed |= setRetNoUndef(F); Changed |= setDoesNotThrow(F); @@ -473,6 +474,7 @@ Changed |= setDoesNotCapture(F, 0); return Changed; case LibFunc_realloc: + case LibFunc_vec_realloc: Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F); Changed |= setRetNoUndef(F); Changed |= setDoesNotThrow(F); @@ -555,6 +557,7 @@ Changed |= setOnlyWritesMemory(F, 0); return Changed; case LibFunc_calloc: + case LibFunc_vec_calloc: Changed |= setOnlyAccessesInaccessibleMemory(F); Changed |= setRetNoUndef(F); Changed |= setDoesNotThrow(F); @@ -612,6 +615,7 @@ Changed |= setDoesNotCapture(F, 0); return Changed; case LibFunc_free: + case LibFunc_vec_free: Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F); Changed |= setArgsNoUndef(F); Changed |= setDoesNotThrow(F); diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp --- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp +++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp @@ -580,6 +580,12 @@ "declare double @__sinh_finite(double)\n" "declare float @__sinhf_finite(float)\n" "declare x86_fp80 @__sinhl_finite(x86_fp80)\n" + + // These functions are aix vec allocation/free routines + "declare i8* @vec_calloc(i64, i64)\n" + "declare i8* @vec_malloc(i64)\n" + "declare i8* @vec_realloc(i8*, i64)\n" + "declare void @vec_free(i8*)\n" ); for (unsigned FI = 0; FI != LibFunc::NumLibFuncs; ++FI) {