1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[Analysis] Support AIX vec_malloc routines

This is to support the memory routines vec_malloc, vec_calloc, vec_realloc, and vec_free. These routines manage memory that is 16-byte aligned. And they are only available on AIX.

Differential Revision: https://reviews.llvm.org/D94710
This commit is contained in:
Shimin Cui 2021-01-22 15:59:29 -05:00 committed by Roland Froese
parent 1688e34dba
commit 50ae94abae
5 changed files with 37 additions and 0 deletions

View File

@ -1420,6 +1420,18 @@ TLI_DEFINE_STRING_INTERNAL("utimes")
/// 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")

View File

@ -72,6 +72,7 @@ struct AllocFnsTy {
// know which functions are nounwind, noalias, nocapture parameters, etc.
static const std::pair<LibFunc, AllocFnsTy> 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 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
{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}}

View File

@ -551,6 +551,14 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
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 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
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 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
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 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
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 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
case LibFunc_mkdir:
case LibFunc_mktime:
case LibFunc_times:
case LibFunc_vec_free:
return (NumParams != 0 && FTy.getParamType(0)->isPointerTy());
case LibFunc_fopen:

View File

@ -391,6 +391,7 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
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 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
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 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
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 @@ bool llvm::inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI) {
Changed |= setDoesNotCapture(F, 0);
return Changed;
case LibFunc_free:
case LibFunc_vec_free:
Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
Changed |= setArgsNoUndef(F);
Changed |= setDoesNotThrow(F);

View File

@ -580,6 +580,12 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
"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) {