Skip to content

Add __size_returning_new variant detection to TLI. #101564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.def
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,32 @@ TLI_DEFINE_ENUM_INTERNAL(ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t)
TLI_DEFINE_STRING_INTERNAL("_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t")
TLI_DEFINE_SIG_INTERNAL(Ptr, Long, Long, Ptr, Bool)

/// The following are variants of operator new which return the actual size
/// reserved by the allocator proposed in P0901R5 (Size feedback in operator new).
/// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0901r5.html
/// They are implemented by tcmalloc, see source at
/// https://github.com/google/tcmalloc/blob/master/tcmalloc/malloc_extension.h

/// __sized_ptr_t __size_returning_new(size_t size)
TLI_DEFINE_ENUM_INTERNAL(size_returning_new)
TLI_DEFINE_STRING_INTERNAL("__size_returning_new")
TLI_DEFINE_SIG_INTERNAL(Struct, Long)

/// __sized_ptr_t __size_returning_new_hot_cold(size_t, __hot_cold_t)
TLI_DEFINE_ENUM_INTERNAL(size_returning_new_hot_cold)
TLI_DEFINE_STRING_INTERNAL("__size_returning_new_hot_cold")
TLI_DEFINE_SIG_INTERNAL(Struct, Long, Bool)

/// __sized_ptr_t __size_returning_new_aligned(size_t, std::align_val_t)
TLI_DEFINE_ENUM_INTERNAL(size_returning_new_aligned)
TLI_DEFINE_STRING_INTERNAL("__size_returning_new_aligned")
TLI_DEFINE_SIG_INTERNAL(Struct, Long, Long)

/// __sized_ptr_t __size_returning_new_aligned(size_t, std::align_val_t, __hot_cold_t)
TLI_DEFINE_ENUM_INTERNAL(size_returning_new_aligned_hot_cold)
TLI_DEFINE_STRING_INTERNAL("__size_returning_new_aligned_hot_cold")
TLI_DEFINE_SIG_INTERNAL(Struct, Long, Long, Bool)

/// double __acos_finite(double x);
TLI_DEFINE_ENUM_INTERNAL(acos_finite)
TLI_DEFINE_STRING_INTERNAL("__acos_finite")
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_Znam12__hot_cold_t);
TLI.setUnavailable(LibFunc_ZnamSt11align_val_t12__hot_cold_t);
TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
TLI.setUnavailable(LibFunc_size_returning_new);
TLI.setUnavailable(LibFunc_size_returning_new_hot_cold);
TLI.setUnavailable(LibFunc_size_returning_new_aligned);
TLI.setUnavailable(LibFunc_size_returning_new_aligned_hot_cold);
} else {
// Not MSVC, assume it's Itanium.
TLI.setUnavailable(LibFunc_msvc_new_int);
Expand Down
11 changes: 6 additions & 5 deletions llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,24 @@
# 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: 8
# CHECK: << Total TLI yes SDK no: 12
# CHECK: >> Total TLI no SDK yes: 0
# CHECK: == Total TLI yes SDK yes: 248
#
# 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_DETAIL-COUNT-8: << TLI yes SDK no : {{.*}}__hot_cold_t
# WRONG_SUMMARY: << Total TLI yes SDK no: 9{{$}}
# WRONG_DETAIL-COUNT-8: << TLI yes SDK no : '_Zn{{.*}}__hot_cold_t
# WRONG_DETAIL-COUNT-4: << TLI yes SDK no : '__size_returning_new{{.*}}
# WRONG_SUMMARY: << Total TLI yes SDK no: 13{{$}}
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
# WRONG_SUMMARY: == Total TLI yes SDK yes: 247
#
## The -COUNT suffix doesn't care if there are too many matches, so check
## 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 489 symbols, 256 available
# AVAIL-COUNT-256: {{^}} available
# AVAIL: TLI knows 493 symbols, 260 available
# AVAIL-COUNT-260: {{^}} available
# AVAIL-NOT: {{^}} available
# UNAVAIL-COUNT-233: not available
# UNAVAIL-NOT: not available
Expand Down
4 changes: 4 additions & 0 deletions llvm/unittests/Analysis/TargetLibraryInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
"declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, %struct*)\n"
"declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, "
"%struct*, i8)\n"
"declare %struct @__size_returning_new(i64)\n"
"declare %struct @__size_returning_new_hot_cold(i64, i8)\n"
"declare %struct @__size_returning_new_aligned(i64, i64)\n"
"declare %struct @__size_returning_new_aligned_hot_cold(i64, i64, i8)\n"

"declare void @\"??3@YAXPEAX@Z\"(i8*)\n"
"declare void @\"??3@YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n"
Expand Down
Loading