Skip to content

Commit c9f5734

Browse files
authored
[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.
1 parent 11dff3a commit c9f5734

File tree

19 files changed

+2101
-2807
lines changed

19 files changed

+2101
-2807
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set(LLVM_TARGET_DEFINITIONS TargetLibraryInfo.td)
2+
tablegen(LLVM TargetLibraryInfo.inc -gen-target-library-info)
3+
add_public_tablegen_target(analysis_gen)

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 0 additions & 2728 deletions
This file was deleted.

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
1111

1212
#include "llvm/ADT/DenseMap.h"
13+
#include "llvm/ADT/StringTable.h"
1314
#include "llvm/IR/Constants.h"
1415
#include "llvm/IR/InstrTypes.h"
1516
#include "llvm/IR/Module.h"
@@ -70,13 +71,8 @@ class VecDesc {
7071
LLVM_ABI std::string getVectorFunctionABIVariantString() const;
7172
};
7273

73-
enum LibFunc : unsigned {
74-
#define TLI_DEFINE_ENUM
75-
#include "llvm/Analysis/TargetLibraryInfo.def"
76-
77-
NumLibFuncs,
78-
NotLibFunc
79-
};
74+
#define GET_TARGET_LIBRARY_INFO_ENUM
75+
#include "llvm/Analysis/TargetLibraryInfo.inc"
8076

8177
/// Implementation of the target library information.
8278
///
@@ -89,7 +85,8 @@ class TargetLibraryInfoImpl {
8985

9086
unsigned char AvailableArray[(NumLibFuncs+3)/4];
9187
DenseMap<unsigned, std::string> CustomNames;
92-
LLVM_ABI static StringLiteral const StandardNames[NumLibFuncs];
88+
#define GET_TARGET_LIBRARY_INFO_IMPL_DECL
89+
#include "llvm/Analysis/TargetLibraryInfo.inc"
9390
bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
9491
unsigned SizeOfInt;
9592

@@ -160,7 +157,8 @@ class TargetLibraryInfoImpl {
160157
/// Forces a function to be marked as available and provide an alternate name
161158
/// that must be used.
162159
void setAvailableWithName(LibFunc F, StringRef Name) {
163-
if (StandardNames[F] != Name) {
160+
if (StringRef(StandardNamesStrTable.getCString(StandardNamesOffsets[F]),
161+
StandardNamesSizeTable[F]) != Name) {
164162
setState(F, CustomName);
165163
CustomNames[F] = std::string(Name);
166164
assert(CustomNames.contains(F));
@@ -438,15 +436,19 @@ class TargetLibraryInfo {
438436
/// Return the canonical name for a LibFunc. This should not be used for
439437
/// semantic purposes, use getName instead.
440438
static StringRef getStandardName(LibFunc F) {
441-
return TargetLibraryInfoImpl::StandardNames[F];
439+
return StringRef(TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
440+
TargetLibraryInfoImpl::StandardNamesOffsets[F]),
441+
TargetLibraryInfoImpl::StandardNamesSizeTable[F]);
442442
}
443443

444444
StringRef getName(LibFunc F) const {
445445
auto State = getState(F);
446446
if (State == TargetLibraryInfoImpl::Unavailable)
447447
return StringRef();
448448
if (State == TargetLibraryInfoImpl::StandardName)
449-
return Impl->StandardNames[F];
449+
return StringRef(
450+
Impl->StandardNamesStrTable.getCString(Impl->StandardNamesOffsets[F]),
451+
Impl->StandardNamesSizeTable[F]);
450452
assert(State == TargetLibraryInfoImpl::CustomName);
451453
return Impl->CustomNames.find(F)->second;
452454
}

0 commit comments

Comments
 (0)