Skip to content

Commit 3e96ca7

Browse files
nagisacuviper
authored andcommitted
Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent 492a81f commit 3e96ca7

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
@@ -376,6 +376,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
376376
/// long double __powl_finite(long double x, long double y);
377377
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
378378
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
379+
380+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
381+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
382+
383+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
384+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
385+
386+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
387+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
388+
379389
/// double __sincospi_stret(double x);
380390
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
381391
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

llvm/lib/Analysis/MemoryBuiltins.cpp

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

@@ -460,7 +463,8 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
460463
TLIFn == LibFunc_ZdlPvjSt11align_val_t || // delete(void*, unsigned long, align_val_t)
461464
TLIFn == LibFunc_ZdlPvmSt11align_val_t || // delete(void*, unsigned long, align_val_t)
462465
TLIFn == LibFunc_ZdaPvjSt11align_val_t || // delete[](void*, unsigned int, align_val_t)
463-
TLIFn == LibFunc_ZdaPvmSt11align_val_t) // delete[](void*, unsigned long, align_val_t)
466+
TLIFn == LibFunc_ZdaPvmSt11align_val_t || // delete[](void*, unsigned long, align_val_t)
467+
TLIFn == LibFunc_rust_dealloc)
464468
ExpectedNumParams = 3;
465469
else
466470
return false;

llvm/lib/Analysis/TargetLibraryInfo.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
14891489
else
14901490
return false;
14911491
}
1492+
1493+
case LibFunc_rust_alloc:
1494+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1495+
FTy.getParamType(0)->isIntegerTy() &&
1496+
FTy.getParamType(1)->isIntegerTy() &&
1497+
FTy.getParamType(2)->isPointerTy());
1498+
1499+
case LibFunc_rust_dealloc:
1500+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1501+
FTy.getParamType(0)->isPointerTy() &&
1502+
FTy.getParamType(1)->isIntegerTy() &&
1503+
FTy.getParamType(2)->isIntegerTy());
1504+
1505+
case LibFunc_rust_realloc:
1506+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1507+
FTy.getParamType(0)->isPointerTy() &&
1508+
FTy.getParamType(1)->isIntegerTy() &&
1509+
FTy.getParamType(2)->isIntegerTy() &&
1510+
FTy.getParamType(3)->isIntegerTy() &&
1511+
FTy.getParamType(4)->isIntegerTy() &&
1512+
FTy.getParamType(5)->isPointerTy());
1513+
14921514
case LibFunc::NumLibFuncs:
14931515
case LibFunc::NotLibFunc:
14941516
break;

0 commit comments

Comments
 (0)