Skip to content

Commit b20c203

Browse files
committed
[Analysis] Move TargetLibraryInfo data to TableGen
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 22f29d6 commit b20c203

File tree

19 files changed

+1963
-2777
lines changed

19 files changed

+1963
-2777
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 & 2698 deletions
This file was deleted.

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 10 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"
@@ -69,13 +70,8 @@ class VecDesc {
6970
LLVM_ABI std::string getVectorFunctionABIVariantString() const;
7071
};
7172

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

8076
/// Implementation of the target library information.
8177
///
@@ -88,7 +84,8 @@ class TargetLibraryInfoImpl {
8884

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

@@ -177,7 +174,7 @@ class TargetLibraryInfoImpl {
177174
/// Forces a function to be marked as available and provide an alternate name
178175
/// that must be used.
179176
void setAvailableWithName(LibFunc F, StringRef Name) {
180-
if (StandardNames[F] != Name) {
177+
if (StandardNamesStrTable.getCString(StandardNamesOffsets[F]) != Name) {
181178
setState(F, CustomName);
182179
CustomNames[F] = std::string(Name);
183180
assert(CustomNames.contains(F));
@@ -455,15 +452,17 @@ class TargetLibraryInfo {
455452
/// Return the canonical name for a LibFunc. This should not be used for
456453
/// semantic purposes, use getName instead.
457454
static StringRef getStandardName(LibFunc F) {
458-
return TargetLibraryInfoImpl::StandardNames[F];
455+
return TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
456+
TargetLibraryInfoImpl::StandardNamesOffsets[F]);
459457
}
460458

461459
StringRef getName(LibFunc F) const {
462460
auto State = getState(F);
463461
if (State == TargetLibraryInfoImpl::Unavailable)
464462
return StringRef();
465463
if (State == TargetLibraryInfoImpl::StandardName)
466-
return Impl->StandardNames[F];
464+
return Impl->StandardNamesStrTable.getCString(
465+
Impl->StandardNamesOffsets[F]);
467466
assert(State == TargetLibraryInfoImpl::CustomName);
468467
return Impl->CustomNames.find(F)->second;
469468
}

0 commit comments

Comments
 (0)