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

Commit 7f235a5

Browse files
nagisaalexcrichton
authored andcommitted
Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent a8805ac commit 7f235a5

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
352352
/// long double __powl_finite(long double x, long double y);
353353
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
354354
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
355+
356+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
357+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
358+
359+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
360+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
361+
362+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
363+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
364+
355365
/// double __sincospi_stret(double x);
356366
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
357367
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

lib/Analysis/MemoryBuiltins.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
105105
{LibFunc_realloc, {ReallocLike, 2, 1, -1}},
106106
{LibFunc_reallocf, {ReallocLike, 2, 1, -1}},
107107
{LibFunc_strdup, {StrDupLike, 1, -1, -1}},
108-
{LibFunc_strndup, {StrDupLike, 2, 1, -1}}
108+
{LibFunc_strndup, {StrDupLike, 2, 1, -1}},
109+
110+
{LibFunc_rust_alloc, {MallocLike, 2, 0, -1}},
111+
{LibFunc_rust_realloc, {ReallocLike, 4, 3, -1}},
109112
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
110113
};
111114

@@ -399,7 +402,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
399402
TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
400403
ExpectedNumParams = 2;
401404
else if (TLIFn == LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t || // delete(void*, align_val_t, nothrow)
402-
TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t) // delete[](void*, align_val_t, nothrow)
405+
TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t || // delete[](void*, align_val_t, nothrow)
406+
TLIFn == LibFunc_rust_dealloc)
403407
ExpectedNumParams = 3;
404408
else
405409
return nullptr;

lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
13821382
else
13831383
return false;
13841384
}
1385+
1386+
case LibFunc_rust_alloc:
1387+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1388+
FTy.getParamType(0)->isIntegerTy() &&
1389+
FTy.getParamType(1)->isIntegerTy() &&
1390+
FTy.getParamType(2)->isPointerTy());
1391+
1392+
case LibFunc_rust_dealloc:
1393+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1394+
FTy.getParamType(0)->isPointerTy() &&
1395+
FTy.getParamType(1)->isIntegerTy() &&
1396+
FTy.getParamType(2)->isIntegerTy());
1397+
1398+
case LibFunc_rust_realloc:
1399+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1400+
FTy.getParamType(0)->isPointerTy() &&
1401+
FTy.getParamType(1)->isIntegerTy() &&
1402+
FTy.getParamType(2)->isIntegerTy() &&
1403+
FTy.getParamType(3)->isIntegerTy() &&
1404+
FTy.getParamType(4)->isIntegerTy() &&
1405+
FTy.getParamType(5)->isPointerTy());
1406+
13851407
case LibFunc::NumLibFuncs:
13861408
break;
13871409
}

0 commit comments

Comments
 (0)