Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Add knowledge of __rust_{alloc,realloc,dealloc}
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa authored and alexcrichton committed Jan 26, 2018
1 parent 1187443 commit 013f2ec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
/// long double __powl_finite(long double x, long double y);
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
TLI_DEFINE_STRING_INTERNAL("__powl_finite")

TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")

TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")

TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")

/// double __sincospi_stret(double x);
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")
Expand Down
7 changes: 6 additions & 1 deletion lib/Analysis/MemoryBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
{LibFunc_realloc, {ReallocLike, 2, 1, -1}},
{LibFunc_reallocf, {ReallocLike, 2, 1, -1}},
{LibFunc_strdup, {StrDupLike, 1, -1, -1}},
{LibFunc_strndup, {StrDupLike, 2, 1, -1}}
{LibFunc_strndup, {StrDupLike, 2, 1, -1}},

{LibFunc_rust_alloc, {MallocLike, 3, 0, -1}},
{LibFunc_rust_realloc, {ReallocLike, 6, 3, -1}},
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
};

Expand Down Expand Up @@ -386,6 +389,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
TLIFn == LibFunc_msvc_delete_array_ptr32_nothrow || // delete[](void*, nothrow)
TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
ExpectedNumParams = 2;
else if (TLIFn == LibFunc_rust_dealloc)
ExpectedNumParams = 3;
else
return nullptr;

Expand Down
22 changes: 22 additions & 0 deletions lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
else
return false;
}

case LibFunc_rust_alloc:
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
FTy.getParamType(0)->isIntegerTy() &&
FTy.getParamType(1)->isIntegerTy() &&
FTy.getParamType(2)->isPointerTy());

case LibFunc_rust_dealloc:
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
FTy.getParamType(0)->isPointerTy() &&
FTy.getParamType(1)->isIntegerTy() &&
FTy.getParamType(2)->isIntegerTy());

case LibFunc_rust_realloc:
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
FTy.getParamType(0)->isPointerTy() &&
FTy.getParamType(1)->isIntegerTy() &&
FTy.getParamType(2)->isIntegerTy() &&
FTy.getParamType(3)->isIntegerTy() &&
FTy.getParamType(4)->isIntegerTy() &&
FTy.getParamType(5)->isPointerTy());

case LibFunc::NumLibFuncs:
break;
}
Expand Down

0 comments on commit 013f2ec

Please sign in to comment.