Skip to content

Commit eacff08

Browse files
nagisacuviper
authored andcommitted
Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent 125fcca commit eacff08

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
@@ -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")

llvm/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;

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
14021402
else
14031403
return false;
14041404
}
1405+
1406+
case LibFunc_rust_alloc:
1407+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1408+
FTy.getParamType(0)->isIntegerTy() &&
1409+
FTy.getParamType(1)->isIntegerTy() &&
1410+
FTy.getParamType(2)->isPointerTy());
1411+
1412+
case LibFunc_rust_dealloc:
1413+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1414+
FTy.getParamType(0)->isPointerTy() &&
1415+
FTy.getParamType(1)->isIntegerTy() &&
1416+
FTy.getParamType(2)->isIntegerTy());
1417+
1418+
case LibFunc_rust_realloc:
1419+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1420+
FTy.getParamType(0)->isPointerTy() &&
1421+
FTy.getParamType(1)->isIntegerTy() &&
1422+
FTy.getParamType(2)->isIntegerTy() &&
1423+
FTy.getParamType(3)->isIntegerTy() &&
1424+
FTy.getParamType(4)->isIntegerTy() &&
1425+
FTy.getParamType(5)->isPointerTy());
1426+
14051427
case LibFunc::NumLibFuncs:
14061428
break;
14071429
}

0 commit comments

Comments
 (0)