Skip to content

Commit 874890c

Browse files
authored
Add __size_returning_new variant detection to TLI. (#101564)
Add support to detect __size_returning_new variants defined inproposal P0901R5 to extend to operator new, see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0901r5.html for details. This PR matches the declarations exported by tcmalloc in https://github.com/google/tcmalloc/blob/f2516691d01051defc558679f37720bba88d9862/tcmalloc/malloc_extension.h#L707-L711
1 parent 8dfa651 commit 874890c

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,32 @@ TLI_DEFINE_ENUM_INTERNAL(ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t)
356356
TLI_DEFINE_STRING_INTERNAL("_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t")
357357
TLI_DEFINE_SIG_INTERNAL(Ptr, Long, Long, Ptr, Bool)
358358

359+
/// The following are variants of operator new which return the actual size
360+
/// reserved by the allocator proposed in P0901R5 (Size feedback in operator new).
361+
/// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0901r5.html
362+
/// They are implemented by tcmalloc, see source at
363+
/// https://github.com/google/tcmalloc/blob/master/tcmalloc/malloc_extension.h
364+
365+
/// __sized_ptr_t __size_returning_new(size_t size)
366+
TLI_DEFINE_ENUM_INTERNAL(size_returning_new)
367+
TLI_DEFINE_STRING_INTERNAL("__size_returning_new")
368+
TLI_DEFINE_SIG_INTERNAL(Struct, Long)
369+
370+
/// __sized_ptr_t __size_returning_new_hot_cold(size_t, __hot_cold_t)
371+
TLI_DEFINE_ENUM_INTERNAL(size_returning_new_hot_cold)
372+
TLI_DEFINE_STRING_INTERNAL("__size_returning_new_hot_cold")
373+
TLI_DEFINE_SIG_INTERNAL(Struct, Long, Bool)
374+
375+
/// __sized_ptr_t __size_returning_new_aligned(size_t, std::align_val_t)
376+
TLI_DEFINE_ENUM_INTERNAL(size_returning_new_aligned)
377+
TLI_DEFINE_STRING_INTERNAL("__size_returning_new_aligned")
378+
TLI_DEFINE_SIG_INTERNAL(Struct, Long, Long)
379+
380+
/// __sized_ptr_t __size_returning_new_aligned(size_t, std::align_val_t, __hot_cold_t)
381+
TLI_DEFINE_ENUM_INTERNAL(size_returning_new_aligned_hot_cold)
382+
TLI_DEFINE_STRING_INTERNAL("__size_returning_new_aligned_hot_cold")
383+
TLI_DEFINE_SIG_INTERNAL(Struct, Long, Long, Bool)
384+
359385
/// double __acos_finite(double x);
360386
TLI_DEFINE_ENUM_INTERNAL(acos_finite)
361387
TLI_DEFINE_STRING_INTERNAL("__acos_finite")

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
512512
TLI.setUnavailable(LibFunc_Znam12__hot_cold_t);
513513
TLI.setUnavailable(LibFunc_ZnamSt11align_val_t12__hot_cold_t);
514514
TLI.setUnavailable(LibFunc_ZnamSt11align_val_tRKSt9nothrow_t12__hot_cold_t);
515+
TLI.setUnavailable(LibFunc_size_returning_new);
516+
TLI.setUnavailable(LibFunc_size_returning_new_hot_cold);
517+
TLI.setUnavailable(LibFunc_size_returning_new_aligned);
518+
TLI.setUnavailable(LibFunc_size_returning_new_aligned_hot_cold);
515519
} else {
516520
// Not MSVC, assume it's Itanium.
517521
TLI.setUnavailable(LibFunc_msvc_new_int);

llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,24 @@
3232
# RUN: FileCheck %s --check-prefix=AVAIL --input-file %t3.txt
3333
# RUN: FileCheck %s --check-prefix=UNAVAIL --input-file %t3.txt
3434
#
35-
# CHECK: << Total TLI yes SDK no: 8
35+
# CHECK: << Total TLI yes SDK no: 12
3636
# CHECK: >> Total TLI no SDK yes: 0
3737
# CHECK: == Total TLI yes SDK yes: 248
3838
#
3939
# WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
4040
# WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
41-
# WRONG_DETAIL-COUNT-8: << TLI yes SDK no : {{.*}}__hot_cold_t
42-
# WRONG_SUMMARY: << Total TLI yes SDK no: 9{{$}}
41+
# WRONG_DETAIL-COUNT-8: << TLI yes SDK no : '_Zn{{.*}}__hot_cold_t
42+
# WRONG_DETAIL-COUNT-4: << TLI yes SDK no : '__size_returning_new{{.*}}
43+
# WRONG_SUMMARY: << Total TLI yes SDK no: 13{{$}}
4344
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
4445
# WRONG_SUMMARY: == Total TLI yes SDK yes: 247
4546
#
4647
## The -COUNT suffix doesn't care if there are too many matches, so check
4748
## the exact count first; the two directives should add up to that.
4849
## Yes, this means additions to TLI will fail this test, but the argument
4950
## to -COUNT can't be an expression.
50-
# AVAIL: TLI knows 489 symbols, 256 available
51-
# AVAIL-COUNT-256: {{^}} available
51+
# AVAIL: TLI knows 493 symbols, 260 available
52+
# AVAIL-COUNT-260: {{^}} available
5253
# AVAIL-NOT: {{^}} available
5354
# UNAVAIL-COUNT-233: not available
5455
# UNAVAIL-NOT: not available

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
472472
"declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t(i64, i64, %struct*)\n"
473473
"declare i8* @_ZnwmSt11align_val_tRKSt9nothrow_t12__hot_cold_t(i64, i64, "
474474
"%struct*, i8)\n"
475+
"declare %struct @__size_returning_new(i64)\n"
476+
"declare %struct @__size_returning_new_hot_cold(i64, i8)\n"
477+
"declare %struct @__size_returning_new_aligned(i64, i64)\n"
478+
"declare %struct @__size_returning_new_aligned_hot_cold(i64, i64, i8)\n"
475479

476480
"declare void @\"??3@YAXPEAX@Z\"(i8*)\n"
477481
"declare void @\"??3@YAXPEAXAEBUnothrow_t@std@@@Z\"(i8*, %struct*)\n"

0 commit comments

Comments
 (0)