Skip to content

Commit f234a4d

Browse files
nagisacuviper
authored andcommitted
[rust] Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent b4f352c commit f234a4d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

+10
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
385385
/// long double __powl_finite(long double x, long double y);
386386
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
387387
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
388+
389+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
390+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
391+
392+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
393+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
394+
395+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
396+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
397+
388398
/// double __sincospi_stret(double x);
389399
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
390400
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

llvm/lib/Analysis/MemoryBuiltins.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
109109
{LibFunc_vec_realloc, {ReallocLike, 2, 1, -1}},
110110
{LibFunc_reallocf, {ReallocLike, 2, 1, -1}},
111111
{LibFunc_strdup, {StrDupLike, 1, -1, -1}},
112-
{LibFunc_strndup, {StrDupLike, 2, 1, -1}}
112+
{LibFunc_strndup, {StrDupLike, 2, 1, -1}},
113+
114+
{LibFunc_rust_alloc, {MallocLike, 2, 0, -1}},
115+
{LibFunc_rust_realloc, {ReallocLike, 4, 3, -1}},
113116
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
114117
};
115118

@@ -462,7 +465,8 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
462465
TLIFn == LibFunc_ZdlPvjSt11align_val_t || // delete(void*, unsigned long, align_val_t)
463466
TLIFn == LibFunc_ZdlPvmSt11align_val_t || // delete(void*, unsigned long, align_val_t)
464467
TLIFn == LibFunc_ZdaPvjSt11align_val_t || // delete[](void*, unsigned int, align_val_t)
465-
TLIFn == LibFunc_ZdaPvmSt11align_val_t) // delete[](void*, unsigned long, align_val_t)
468+
TLIFn == LibFunc_ZdaPvmSt11align_val_t || // delete[](void*, unsigned long, align_val_t)
469+
TLIFn == LibFunc_rust_dealloc)
466470
ExpectedNumParams = 3;
467471
else
468472
return false;

llvm/lib/Analysis/TargetLibraryInfo.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
15131513
else
15141514
return false;
15151515
}
1516+
1517+
case LibFunc_rust_alloc:
1518+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1519+
FTy.getParamType(0)->isIntegerTy() &&
1520+
FTy.getParamType(1)->isIntegerTy() &&
1521+
FTy.getParamType(2)->isPointerTy());
1522+
1523+
case LibFunc_rust_dealloc:
1524+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1525+
FTy.getParamType(0)->isPointerTy() &&
1526+
FTy.getParamType(1)->isIntegerTy() &&
1527+
FTy.getParamType(2)->isIntegerTy());
1528+
1529+
case LibFunc_rust_realloc:
1530+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1531+
FTy.getParamType(0)->isPointerTy() &&
1532+
FTy.getParamType(1)->isIntegerTy() &&
1533+
FTy.getParamType(2)->isIntegerTy() &&
1534+
FTy.getParamType(3)->isIntegerTy() &&
1535+
FTy.getParamType(4)->isIntegerTy() &&
1536+
FTy.getParamType(5)->isPointerTy());
1537+
15161538
case LibFunc::NumLibFuncs:
15171539
case LibFunc::NotLibFunc:
15181540
break;

0 commit comments

Comments
 (0)