Skip to content

Commit fc710ed

Browse files
nagisanikic
authored andcommitted
Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent 06746ca commit fc710ed

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
@@ -364,6 +364,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
364364
/// long double __powl_finite(long double x, long double y);
365365
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
366366
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
367+
368+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
369+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
370+
371+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
372+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
373+
374+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
375+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
376+
367377
/// double __sincospi_stret(double x);
368378
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
369379
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

@@ -439,7 +442,8 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
439442
TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow) // delete[](void*, nothrow)
440443
ExpectedNumParams = 2;
441444
else if (TLIFn == LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t || // delete(void*, align_val_t, nothrow)
442-
TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t) // delete[](void*, align_val_t, nothrow)
445+
TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t || // delete[](void*, align_val_t, nothrow)
446+
TLIFn == LibFunc_rust_dealloc)
443447
ExpectedNumParams = 3;
444448
else
445449
return false;

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,28 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
14661466
else
14671467
return false;
14681468
}
1469+
1470+
case LibFunc_rust_alloc:
1471+
return (NumParams == 3 && FTy.getReturnType()->isPointerTy() &&
1472+
FTy.getParamType(0)->isIntegerTy() &&
1473+
FTy.getParamType(1)->isIntegerTy() &&
1474+
FTy.getParamType(2)->isPointerTy());
1475+
1476+
case LibFunc_rust_dealloc:
1477+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1478+
FTy.getParamType(0)->isPointerTy() &&
1479+
FTy.getParamType(1)->isIntegerTy() &&
1480+
FTy.getParamType(2)->isIntegerTy());
1481+
1482+
case LibFunc_rust_realloc:
1483+
return (NumParams == 6 && FTy.getReturnType()->isPointerTy() &&
1484+
FTy.getParamType(0)->isPointerTy() &&
1485+
FTy.getParamType(1)->isIntegerTy() &&
1486+
FTy.getParamType(2)->isIntegerTy() &&
1487+
FTy.getParamType(3)->isIntegerTy() &&
1488+
FTy.getParamType(4)->isIntegerTy() &&
1489+
FTy.getParamType(5)->isPointerTy());
1490+
14691491
case LibFunc::NumLibFuncs:
14701492
case LibFunc::NotLibFunc:
14711493
break;

0 commit comments

Comments
 (0)