llvm-project/llvm/test/TableGen/TargetLibraryInfo.td
Kai Nacke c9f573463e
[Analysis] Move TargetLibraryInfo data to TableGen (#165009)
The collection of library function names in TargetLibraryInfo faces
similar challenges as RuntimeLibCalls in the IR component. The number of
function names is large, there are numerous customizations based on the
triple (including alternate names), and there is a lot of replicated
data in the signature table.

The ultimate goal would be to capture all lbrary function related
information in a .td file. This PR brings the current .def file to
TableGen, almost as a 1:1 replacement. However, there are some
improvements which are not possible in the current implementation:

- the function names are now stored as a long string together with an
offset table.
- the table of signatures is now deduplicated, using an offset table for
access.

The size of the object file decreases about 34kB with these changes. The
hash table of all function names is still constructed dynamically. A
static table like for RuntimeLibCalls is the next logical step.

The main motivation for this change is that I have to add a large number
of custom names for z/OS (like in RuntimeLibCalls.td), and the current
infrastructur does not support this very well.
2025-11-19 16:05:00 -05:00

116 lines
3.7 KiB
TableGen

// RUN: llvm-tblgen -gen-target-library-info -I %p/../../include %s | FileCheck %s
include "llvm/Analysis/TargetLibraryInfoImpl.td"
def cosf : TargetLibCall< "cosf", Flt, [Flt]>;
def sinf : TargetLibCall< "sinf", Flt, [Flt]>;
def fmaxf : TargetLibCall< "fmaxf", Floating, [Same, Same]>;
def printf : TargetLibCall< "printf", Int, [Ptr, Ellip]>;
def cabs : TargetLibCall< "cabs", ? /* Checked manually. */>;
// CHECK: #ifdef GET_TARGET_LIBRARY_INFO_ENUM
// CHECK-NEXT: #undef GET_TARGET_LIBRARY_INFO_ENUM
// CHECK-NEXT: enum LibFunc : unsigned {
// CHECK-NEXT: NotLibFunc = 0,
// CHECK-NEXT: LibFunc_cosf,
// CHECK-NEXT: LibFunc_sinf,
// CHECK-NEXT: LibFunc_fmaxf,
// CHECK-NEXT: LibFunc_printf,
// CHECK-NEXT: LibFunc_cabs,
// CHECK-NEXT: NumLibFuncs,
// CHECK-NEXT: End_LibFunc = NumLibFuncs,
// CHECK-NEXT: Begin_LibFunc = LibFunc_cosf,
// CHECK-NEXT: };
// CHECK-NEXT: #endif
// CHECK: #ifdef GET_TARGET_LIBRARY_INFO_STRING_TABLE
// CHECK-NEXT: #undef GET_TARGET_LIBRARY_INFO_STRING_TABLE
// CHECK: #ifdef __GNUC__
// CHECK-NEXT: #pragma GCC diagnostic push
// CHECK-NEXT: #pragma GCC diagnostic ignored "-Woverlength-strings"
// CHECK-NEXT: #endif
// CHECK-NEXT: constexpr char StandardNamesStrTableStorage[] =
// CHECK-NEXT: "\0"
// CHECK-NEXT: "cosf\0"
// CHECK-NEXT: "sinf\0"
// CHECK-NEXT: "fmaxf\0"
// CHECK-NEXT: "printf\0"
// CHECK-NEXT: "cabs\0"
// CHECK-NEXT: ;
// CHECK-NEXT: #ifdef __GNUC__
// CHECK-NEXT: #pragma GCC diagnostic pop
// CHECK-NEXT: #endif
// CHECK: const llvm::StringTable
// CHECK-NEXT: TargetLibraryInfoImpl::StandardNamesStrTable = StandardNamesStrTableStorage;
// CHECK: const llvm::StringTable::Offset TargetLibraryInfoImpl::StandardNamesOffsets[6] = {
// CHECK-NEXT: 0, //
// CHECK-NEXT: 1, // cosf
// CHECK-NEXT: 6, // sinf
// CHECK-NEXT: 11, // fmaxf
// CHECK-NEXT: 17, // printf
// CHECK-NEXT: 24, // cabs
// CHECK-NEXT: };
// CHECK-NEXT: const uint8_t TargetLibraryInfoImpl::StandardNamesSizeTable[6] = {
// CHECK-NEXT: 0,
// CHECK-NEXT: 4,
// CHECK-NEXT: 4,
// CHECK-NEXT: 5,
// CHECK-NEXT: 6,
// CHECK-NEXT: 4,
// CHECK-NEXT: };
// CHECK-NEXT: #endif
// CHECK: #ifdef GET_TARGET_LIBRARY_INFO_IMPL_DECL
// CHECK-NEXT: #undef GET_TARGET_LIBRARY_INFO_IMPL_DECL
// CHECK-NEXT: LLVM_ABI static const llvm::StringTable StandardNamesStrTable;
// CHECK-NEXT: LLVM_ABI static const llvm::StringTable::Offset StandardNamesOffsets[6];
// CHECK-NEXT: LLVM_ABI static const uint8_t StandardNamesSizeTable[6];
// CHECK-NEXT: #endif
// CHECK: #ifdef GET_TARGET_LIBRARY_INFO_SIGNATURE_TABLE
// CHECK-NEXT: #undef GET_TARGET_LIBRARY_INFO_SIGNATURE_TABLE
// CHECK-NEXT: enum FuncArgTypeID : char {
// CHECK-NEXT: NoFuncArgType = 0,
// CHECK-NEXT: Void,
// CHECK-NEXT: Bool,
// CHECK-NEXT: Int16,
// CHECK-NEXT: Int32,
// CHECK-NEXT: Int,
// CHECK-NEXT: IntPlus,
// CHECK-NEXT: Long,
// CHECK-NEXT: IntX,
// CHECK-NEXT: Int64,
// CHECK-NEXT: LLong,
// CHECK-NEXT: SizeT,
// CHECK-NEXT: SSizeT,
// CHECK-NEXT: Flt,
// CHECK-NEXT: Dbl,
// CHECK-NEXT: LDbl,
// CHECK-NEXT: Floating,
// CHECK-NEXT: Ptr,
// CHECK-NEXT: Struct,
// CHECK-NEXT: Ellip,
// CHECK-NEXT: Same,
// CHECK-NEXT: };
// CHECK-NEXT: static const FuncArgTypeID SignatureTable[] = {
// CHECK-NEXT: /* 0 */ Int, Ptr, Ellip, NoFuncArgType,
// CHECK-NEXT: /* 4 */ Flt, Flt, NoFuncArgType,
// CHECK-NEXT: /* 7 */ Floating, Same, Same, NoFuncArgType,
// CHECK-NEXT: /* 11 */ Void, NoFuncArgType,
// CHECK-NEXT: };
// CHECK-NEXT: static const uint16_t SignatureOffset[] = {
// CHECK-NEXT: 11, //
// CHECK-NEXT: 4, // cosf
// CHECK-NEXT: 4, // sinf
// CHECK-NEXT: 7, // fmaxf
// CHECK-NEXT: 0, // printf
// CHECK-NEXT: 3, // cabs
// CHECK-NEXT: };
// CHECK-NEXT: #endif