Skip to content

Commit b11adab

Browse files
nagisaalexcrichton
authored andcommitted
Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent cb1a5a7 commit b11adab

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
355355
/// long double __powl_finite(long double x, long double y);
356356
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
357357
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
358+
359+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
360+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
361+
362+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
363+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
364+
365+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
366+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
367+
358368
/// double __sincospi_stret(double x);
359369
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
360370
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

llvm/lib/Analysis/MemoryBuiltins.cpp

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

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

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
14801480
else
14811481
return false;
14821482
}
1483+
1484+
case LibFunc_rust_alloc:
1485+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1486+
FTy.getParamType(0)->isIntegerTy() &&
1487+
FTy.getParamType(1)->isIntegerTy() &&
1488+
FTy.getParamType(2)->isPointerTy());
1489+
1490+
case LibFunc_rust_dealloc:
1491+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1492+
FTy.getParamType(0)->isPointerTy() &&
1493+
FTy.getParamType(1)->isIntegerTy() &&
1494+
FTy.getParamType(2)->isIntegerTy());
1495+
1496+
case LibFunc_rust_realloc:
1497+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1498+
FTy.getParamType(0)->isPointerTy() &&
1499+
FTy.getParamType(1)->isIntegerTy() &&
1500+
FTy.getParamType(2)->isIntegerTy() &&
1501+
FTy.getParamType(3)->isIntegerTy() &&
1502+
FTy.getParamType(4)->isIntegerTy() &&
1503+
FTy.getParamType(5)->isPointerTy());
1504+
14831505
case LibFunc::NumLibFuncs:
14841506
break;
14851507
}

0 commit comments

Comments
 (0)