Skip to content

Commit b1f55f7

Browse files
nagisanikic
authored andcommitted
[rust] Add knowledge of __rust_{alloc,realloc,dealloc}
1 parent 2372179 commit b1f55f7

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

+10
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,16 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
391391
/// long double __powl_finite(long double x, long double y);
392392
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
393393
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
394+
395+
TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
396+
TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
397+
398+
TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
399+
TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
400+
401+
TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
402+
TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
403+
394404
/// double __sincospi_stret(double x);
395405
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
396406
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")

llvm/lib/Analysis/MemoryBuiltins.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
111111
{LibFunc_reallocf, {ReallocLike, 2, 1, -1}},
112112
{LibFunc_strdup, {StrDupLike, 1, -1, -1}},
113113
{LibFunc_strndup, {StrDupLike, 2, 1, -1}},
114-
{LibFunc___kmpc_alloc_shared, {MallocLike, 1, 0, -1}}
114+
{LibFunc___kmpc_alloc_shared, {MallocLike, 1, 0, -1}},
115+
116+
{LibFunc_rust_alloc, {MallocLike, 2, 0, -1}},
117+
{LibFunc_rust_realloc, {ReallocLike, 4, 3, -1}},
115118
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
116119
};
117120

@@ -464,7 +467,8 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
464467
TLIFn == LibFunc_ZdlPvjSt11align_val_t || // delete(void*, unsigned long, align_val_t)
465468
TLIFn == LibFunc_ZdlPvmSt11align_val_t || // delete(void*, unsigned long, align_val_t)
466469
TLIFn == LibFunc_ZdaPvjSt11align_val_t || // delete[](void*, unsigned int, align_val_t)
467-
TLIFn == LibFunc_ZdaPvmSt11align_val_t) // delete[](void*, unsigned long, align_val_t)
470+
TLIFn == LibFunc_ZdaPvmSt11align_val_t || // delete[](void*, unsigned long, align_val_t)
471+
TLIFn == LibFunc_rust_dealloc)
468472
ExpectedNumParams = 3;
469473
else
470474
return false;

llvm/lib/Analysis/TargetLibraryInfo.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,25 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
15911591
else
15921592
return false;
15931593
}
1594+
1595+
case LibFunc_rust_alloc:
1596+
return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
1597+
FTy.getParamType(0)->isIntegerTy() &&
1598+
FTy.getParamType(1)->isIntegerTy());
1599+
1600+
case LibFunc_rust_dealloc:
1601+
return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
1602+
FTy.getParamType(0)->isPointerTy() &&
1603+
FTy.getParamType(1)->isIntegerTy() &&
1604+
FTy.getParamType(2)->isIntegerTy());
1605+
1606+
case LibFunc_rust_realloc:
1607+
return (NumParams == 4 && FTy.getReturnType()->isPointerTy() &&
1608+
FTy.getParamType(0)->isPointerTy() &&
1609+
FTy.getParamType(1)->isIntegerTy() &&
1610+
FTy.getParamType(2)->isIntegerTy() &&
1611+
FTy.getParamType(3)->isIntegerTy());
1612+
15941613
case LibFunc::NumLibFuncs:
15951614
case LibFunc::NotLibFunc:
15961615
break;

0 commit comments

Comments
 (0)