Skip to content

Commit a1f7955

Browse files
nagisanikic
authored andcommitted
Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent 05b900b commit a1f7955

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
@@ -382,6 +382,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
382382
/// long double __powl_finite(long double x, long double y);
383383
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
384384
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
385+
386+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
387+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
388+
389+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
390+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
391+
392+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
393+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
394+
385395
/// double __sincospi_stret(double x);
386396
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
387397
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
@@ -1498,6 +1498,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
14981498
else
14991499
return false;
15001500
}
1501+
1502+
case LibFunc_rust_alloc:
1503+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1504+
FTy.getParamType(0)->isIntegerTy() &&
1505+
FTy.getParamType(1)->isIntegerTy() &&
1506+
FTy.getParamType(2)->isPointerTy());
1507+
1508+
case LibFunc_rust_dealloc:
1509+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1510+
FTy.getParamType(0)->isPointerTy() &&
1511+
FTy.getParamType(1)->isIntegerTy() &&
1512+
FTy.getParamType(2)->isIntegerTy());
1513+
1514+
case LibFunc_rust_realloc:
1515+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1516+
FTy.getParamType(0)->isPointerTy() &&
1517+
FTy.getParamType(1)->isIntegerTy() &&
1518+
FTy.getParamType(2)->isIntegerTy() &&
1519+
FTy.getParamType(3)->isIntegerTy() &&
1520+
FTy.getParamType(4)->isIntegerTy() &&
1521+
FTy.getParamType(5)->isPointerTy());
1522+
15011523
case LibFunc::NumLibFuncs:
15021524
case LibFunc::NotLibFunc:
15031525
break;

0 commit comments

Comments
 (0)