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

Commit 013f2ec

Browse files
nagisaalexcrichton
authored andcommitted
Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent 1187443 commit 013f2ec

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

include/llvm/Analysis/TargetLibraryInfo.def

+10
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
316316
/// long double __powl_finite(long double x, long double y);
317317
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
318318
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
319+
320+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
321+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
322+
323+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
324+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
325+
326+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
327+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
328+
319329
/// double __sincospi_stret(double x);
320330
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
321331
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

lib/Analysis/MemoryBuiltins.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
9393
{LibFunc_realloc, {ReallocLike, 2, 1, -1}},
9494
{LibFunc_reallocf, {ReallocLike, 2, 1, -1}},
9595
{LibFunc_strdup, {StrDupLike, 1, -1, -1}},
96-
{LibFunc_strndup, {StrDupLike, 2, 1, -1}}
96+
{LibFunc_strndup, {StrDupLike, 2, 1, -1}},
97+
98+
{LibFunc_rust_alloc, {MallocLike, 3, 0, -1}},
99+
{LibFunc_rust_realloc, {ReallocLike, 6, 3, -1}},
97100
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
98101
};
99102

@@ -386,6 +389,8 @@ const CallInst *llvm::isFreeCall(const Value *I, const TargetLibraryInfo *TLI) {
386389
TLIFn == LibFunc_msvc_delete_array_ptr32_nothrow || // delete[](void*, nothrow)
387390
TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
388391
ExpectedNumParams = 2;
392+
else if (TLIFn == LibFunc_rust_dealloc)
393+
ExpectedNumParams = 3;
389394
else
390395
return nullptr;
391396

lib/Analysis/TargetLibraryInfo.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
12891289
else
12901290
return false;
12911291
}
1292+
1293+
case LibFunc_rust_alloc:
1294+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1295+
FTy.getParamType(0)->isIntegerTy() &&
1296+
FTy.getParamType(1)->isIntegerTy() &&
1297+
FTy.getParamType(2)->isPointerTy());
1298+
1299+
case LibFunc_rust_dealloc:
1300+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1301+
FTy.getParamType(0)->isPointerTy() &&
1302+
FTy.getParamType(1)->isIntegerTy() &&
1303+
FTy.getParamType(2)->isIntegerTy());
1304+
1305+
case LibFunc_rust_realloc:
1306+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1307+
FTy.getParamType(0)->isPointerTy() &&
1308+
FTy.getParamType(1)->isIntegerTy() &&
1309+
FTy.getParamType(2)->isIntegerTy() &&
1310+
FTy.getParamType(3)->isIntegerTy() &&
1311+
FTy.getParamType(4)->isIntegerTy() &&
1312+
FTy.getParamType(5)->isPointerTy());
1313+
12921314
case LibFunc::NumLibFuncs:
12931315
break;
12941316
}

0 commit comments

Comments
 (0)