SHA256
1
0
forked from pool/llvm14
llvm14/llvm-lifetime-for-rust.patch

126 lines
5.8 KiB
Diff

From 59b1d748157ddce5f701dfcaa4fae9a553fc9775 Mon Sep 17 00:00:00 2001
From: Simonas Kazlauskas <git@kazlauskas.me>
Date: Sat, 3 Jun 2017 18:55:08 +0300
Subject: [PATCH] [rust] Add knowledge of __rust_{alloc,realloc,dealloc}
---
.../llvm/Analysis/TargetLibraryInfo.def | 13 ++++++++++++
llvm/lib/Analysis/MemoryBuiltins.cpp | 6 +++++-
llvm/lib/Analysis/TargetLibraryInfo.cpp | 20 +++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
index 9c1abef33b288..70a79112ded85 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
@@ -391,6 +391,19 @@ TLI_DEFINE_STRING_INTERNAL("__powf_finite")
/// long double __powl_finite(long double x, long double y);
TLI_DEFINE_ENUM_INTERNAL(powl_finite)
TLI_DEFINE_STRING_INTERNAL("__powl_finite")
+
+TLI_DEFINE_ENUM_INTERNAL(rust_alloc)
+TLI_DEFINE_STRING_INTERNAL("__rust_alloc")
+
+TLI_DEFINE_ENUM_INTERNAL(rust_alloc_zeroed)
+TLI_DEFINE_STRING_INTERNAL("__rust_alloc_zeroed")
+
+TLI_DEFINE_ENUM_INTERNAL(rust_dealloc)
+TLI_DEFINE_STRING_INTERNAL("__rust_dealloc")
+
+TLI_DEFINE_ENUM_INTERNAL(rust_realloc)
+TLI_DEFINE_STRING_INTERNAL("__rust_realloc")
+
/// double __sincospi_stret(double x);
TLI_DEFINE_ENUM_INTERNAL(sincospi_stret)
TLI_DEFINE_STRING_INTERNAL("__sincospi_stret")
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 9e26f292b789a..4b08e6417ebf6 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -111,6 +111,9 @@ static const std::pair<LibFunc, AllocFnsTy> AllocationFnData[] = {
{LibFunc_strdup, {StrDupLike, 1, -1, -1, -1}},
{LibFunc_strndup, {StrDupLike, 2, 1, -1, -1}},
{LibFunc___kmpc_alloc_shared, {MallocLike, 1, 0, -1, -1}},
+ {LibFunc_rust_alloc, {MallocLike, 2, 0, -1, 1}},
+ {LibFunc_rust_alloc_zeroed, {CallocLike, 2, 0, -1, 1}},
+ {LibFunc_rust_realloc, {ReallocLike, 4, 3, -1, 2}},
// TODO: Handle "int posix_memalign(void **, size_t, size_t)"
};
@@ -429,7 +432,8 @@ bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
TLIFn == LibFunc_ZdlPvjSt11align_val_t || // delete(void*, unsigned long, align_val_t)
TLIFn == LibFunc_ZdlPvmSt11align_val_t || // delete(void*, unsigned long, align_val_t)
TLIFn == LibFunc_ZdaPvjSt11align_val_t || // delete[](void*, unsigned int, align_val_t)
- TLIFn == LibFunc_ZdaPvmSt11align_val_t) // delete[](void*, unsigned long, align_val_t)
+ TLIFn == LibFunc_ZdaPvmSt11align_val_t || // delete[](void*, unsigned long, align_val_t)
+ TLIFn == LibFunc_rust_dealloc)
ExpectedNumParams = 3;
else
return false;
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 02923c2c7eb14..22d6a5f04152a 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -1793,6 +1793,26 @@ bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
else
return false;
}
+
+ case LibFunc_rust_alloc:
+ case LibFunc_rust_alloc_zeroed:
+ return (NumParams == 2 && FTy.getReturnType()->isPointerTy() &&
+ FTy.getParamType(0)->isIntegerTy() &&
+ FTy.getParamType(1)->isIntegerTy());
+
+ case LibFunc_rust_dealloc:
+ return (NumParams == 3 && FTy.getReturnType()->isVoidTy() &&
+ FTy.getParamType(0)->isPointerTy() &&
+ FTy.getParamType(1)->isIntegerTy() &&
+ FTy.getParamType(2)->isIntegerTy());
+
+ case LibFunc_rust_realloc:
+ return (NumParams == 4 && FTy.getReturnType()->isPointerTy() &&
+ FTy.getParamType(0)->isPointerTy() &&
+ FTy.getParamType(1)->isIntegerTy() &&
+ FTy.getParamType(2)->isIntegerTy() &&
+ FTy.getParamType(3)->isIntegerTy());
+
case LibFunc::NumLibFuncs:
case LibFunc::NotLibFunc:
break;
diff --git a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
index d21c2c05ff29..807f746b4460 100644
--- a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
+++ b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
@@ -32,13 +32,17 @@
# RUN: FileCheck %s --check-prefix=AVAIL --input-file %t3.txt
# RUN: FileCheck %s --check-prefix=UNAVAIL --input-file %t3.txt
#
-# CHECK: << Total TLI yes SDK no: 0
+# CHECK: << Total TLI yes SDK no: 4
# CHECK: >> Total TLI no SDK yes: 0
# CHECK: == Total TLI yes SDK yes: 235
#
# WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
# WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
-# WRONG_SUMMARY: << Total TLI yes SDK no: 1{{$}}
+# WRONG_DETAIL: << TLI yes SDK no : '__rust_alloc'
+# WRONG_DETAIL: << TLI yes SDK no : '__rust_alloc_zeroed'
+# WRONG_DETAIL: << TLI yes SDK no : '__rust_dealloc'
+# WRONG_DETAIL: << TLI yes SDK no : '__rust_realloc'
+# WRONG_SUMMARY: << Total TLI yes SDK no: 5{{$}}
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
# WRONG_SUMMARY: == Total TLI yes SDK yes: 234
#
@@ -46,8 +50,8 @@
## the exact count first; the two directives should add up to that.
## Yes, this means additions to TLI will fail this test, but the argument
## to -COUNT can't be an expression.
-# AVAIL: TLI knows 468 symbols, 235 available
-# AVAIL-COUNT-235: {{^}} available
+# AVAIL: TLI knows 472 symbols, 239 available
+# AVAIL-COUNT-239: {{^}} available
# AVAIL-NOT: {{^}} available
# UNAVAIL-COUNT-233: not available
# UNAVAIL-NOT: not available