Skip to content

Commit 334e9bf

Browse files
authored
Revert "RuntimeLibcalls: Generate table of libcall name lengths (#153… (#153864)
…210)" This reverts commit 9a14b1d. Revert "RuntimeLibcalls: Return StringRef for libcall names (#153209)" This reverts commit cb1228f. Revert "TableGen: Emit statically generated hash table for runtime libcalls (#150192)" This reverts commit 769a905. Reverted three changes because of a CMake error while building llvm-nm as reported in the following PR: #150192 (comment)
1 parent 5c51a88 commit 334e9bf

File tree

14 files changed

+100
-534
lines changed

14 files changed

+100
-534
lines changed

llvm/benchmarks/CMakeLists.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,3 @@ add_benchmark(FormatVariadicBM FormatVariadicBM.cpp PARTIAL_SOURCES_INTENDED)
1111
add_benchmark(GetIntrinsicInfoTableEntriesBM GetIntrinsicInfoTableEntriesBM.cpp PARTIAL_SOURCES_INTENDED)
1212
add_benchmark(SandboxIRBench SandboxIRBench.cpp PARTIAL_SOURCES_INTENDED)
1313

14-
# Extract the list of symbols in a random utility as sample data.
15-
set(SYMBOL_TEST_DATA_FILE "sample_symbol_list.txt")
16-
set(SYMBOL_TEST_DATA_SOURCE_BINARY $<TARGET_FILE:llc>)
17-
18-
add_custom_command(OUTPUT ${SYMBOL_TEST_DATA_FILE}
19-
COMMAND $<TARGET_FILE:llvm-nm> --no-demangle --no-sort
20-
--format=just-symbols
21-
${SYMBOL_TEST_DATA_SOURCE_BINARY} > ${SYMBOL_TEST_DATA_FILE}
22-
DEPENDS "$<TARGET_FILE:llvm-nm>" "$<TARGET_FILE:llc>")
23-
24-
add_custom_target(generate-runtime-libcalls-sample-symbol-list
25-
DEPENDS ${SYMBOL_TEST_DATA_FILE})
26-
add_benchmark(RuntimeLibcallsBench RuntimeLibcalls.cpp PARTIAL_SOURCES_INTENDED)
27-
28-
add_dependencies(RuntimeLibcallsBench generate-runtime-libcalls-sample-symbol-list)
29-
target_compile_definitions(RuntimeLibcallsBench PRIVATE
30-
-DSYMBOL_TEST_DATA_FILE="${CMAKE_CURRENT_BINARY_DIR}/${SYMBOL_TEST_DATA_FILE}")

llvm/benchmarks/RuntimeLibcalls.cpp

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

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,19 +3557,15 @@ class LLVM_ABI TargetLoweringBase {
35573557

35583558
/// Get the libcall routine name for the specified libcall.
35593559
const char *getLibcallName(RTLIB::Libcall Call) const {
3560-
// FIXME: Return StringRef
3561-
return Libcalls.getLibcallName(Call).data();
3560+
return Libcalls.getLibcallName(Call);
35623561
}
35633562

35643563
/// Get the libcall routine name for the specified libcall implementation
3565-
static StringRef getLibcallImplName(RTLIB::LibcallImpl Call) {
3566-
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Call);
3564+
const char *getLibcallImplName(RTLIB::LibcallImpl Call) const {
3565+
return Libcalls.getLibcallImplName(Call);
35673566
}
35683567

3569-
const char *getMemcpyName() const {
3570-
// FIXME: Return StringRef
3571-
return Libcalls.getMemcpyName().data();
3572-
}
3568+
const char *getMemcpyName() const { return Libcalls.getMemcpyName(); }
35733569

35743570
/// Get the comparison predicate that's to be used to test the result of the
35753571
/// comparison libcall against zero. This should only be used with

llvm/include/llvm/IR/RuntimeLibcalls.h

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ struct RuntimeLibcallsInfo {
7777

7878
/// Get the libcall routine name for the specified libcall.
7979
// FIXME: This should be removed. Only LibcallImpl should have a name.
80-
StringRef getLibcallName(RTLIB::Libcall Call) const {
80+
const char *getLibcallName(RTLIB::Libcall Call) const {
8181
return getLibcallImplName(LibcallImpls[Call]);
8282
}
8383

8484
/// Get the libcall routine name for the specified libcall implementation.
85-
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
85+
// FIXME: Change to return StringRef
86+
static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
8687
if (CallImpl == RTLIB::Unsupported)
87-
return StringRef();
88-
return StringRef(RuntimeLibcallImplNameTable.getCString(
89-
RuntimeLibcallNameOffsetTable[CallImpl]),
90-
RuntimeLibcallNameSizeTable[CallImpl]);
88+
return nullptr;
89+
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
90+
.data();
9191
}
9292

9393
/// Return the lowering's selection of implementation call for \p Call
@@ -119,10 +119,9 @@ struct RuntimeLibcallsInfo {
119119

120120
/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
121121
/// unsupported.
122-
StringRef getMemcpyName() const {
123-
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
124-
if (Memcpy != RTLIB::Unsupported)
125-
return getLibcallImplName(Memcpy);
122+
const char *getMemcpyName() const {
123+
if (const char *Memcpy = getLibcallName(RTLIB::MEMCPY))
124+
return Memcpy;
126125

127126
// Fallback to memmove if memcpy isn't available.
128127
return getLibcallName(RTLIB::MEMMOVE);
@@ -133,41 +132,11 @@ struct RuntimeLibcallsInfo {
133132
return ImplToLibcall[Impl];
134133
}
135134

136-
/// Check if a function name is a recognized runtime call of any kind. This
137-
/// does not consider if this call is available for any current compilation,
138-
/// just that it is a known call somewhere. This returns the set of all
139-
/// LibcallImpls which match the name; multiple implementations with the same
140-
/// name may exist but differ in interpretation based on the target context.
141-
///
142-
/// Generated by tablegen.
143-
LLVM_ABI static inline iota_range<RTLIB::LibcallImpl>
144-
lookupLibcallImplName(StringRef Name){
145-
// Inlining the early exit on the string name appears to be worthwhile when
146-
// querying a real set of symbols
147-
#define GET_LOOKUP_LIBCALL_IMPL_NAME_BODY
148-
#include "llvm/IR/RuntimeLibcalls.inc"
149-
#undef GET_LOOKUP_LIBCALL_IMPL_NAME_BODY
150-
}
151-
152135
/// Check if this is valid libcall for the current module, otherwise
153136
/// RTLIB::Unsupported.
154-
LLVM_ABI RTLIB::LibcallImpl
155-
getSupportedLibcallImpl(StringRef FuncName) const {
156-
for (RTLIB::LibcallImpl Impl : lookupLibcallImplName(FuncName)) {
157-
// FIXME: This should not depend on looking up ImplToLibcall, only the
158-
// list of libcalls for the module.
159-
RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
160-
if (Recognized != RTLIB::Unsupported)
161-
return Recognized;
162-
}
163-
164-
return RTLIB::Unsupported;
165-
}
137+
LLVM_ABI RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const;
166138

167139
private:
168-
LLVM_ABI static iota_range<RTLIB::LibcallImpl>
169-
lookupLibcallImplNameImpl(StringRef Name);
170-
171140
/// Stores the implementation choice for each each libcall.
172141
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
173142
RTLIB::Unsupported};
@@ -184,16 +153,17 @@ struct RuntimeLibcallsInfo {
184153
LLVM_ABI static const char RuntimeLibcallImplNameTableStorage[];
185154
LLVM_ABI static const StringTable RuntimeLibcallImplNameTable;
186155
LLVM_ABI static const uint16_t RuntimeLibcallNameOffsetTable[];
187-
LLVM_ABI static const uint8_t RuntimeLibcallNameSizeTable[];
188156

189157
/// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
190158
LLVM_ABI static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];
191159

192-
/// Utility function for tablegenerated lookup function. Return a range of
193-
/// enum values that apply for the function name at \p NameOffsetEntry with
194-
/// the value \p StrOffset.
195-
static inline iota_range<RTLIB::LibcallImpl>
196-
libcallImplNameHit(uint16_t NameOffsetEntry, uint16_t StrOffset);
160+
/// Check if a function name is a recognized runtime call of any kind. This
161+
/// does not consider if this call is available for any current compilation,
162+
/// just that it is a known call somewhere. This returns the set of all
163+
/// LibcallImpls which match the name; multiple implementations with the same
164+
/// name may exist but differ in interpretation based on the target context.
165+
LLVM_ABI static iterator_range<ArrayRef<uint16_t>::const_iterator>
166+
getRecognizedLibcallImpls(StringRef FuncName);
197167

198168
static bool darwinHasSinCosStret(const Triple &TT) {
199169
if (!TT.isOSDarwin())

llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static bool lowerObjCCall(Function &F, RTLIB::LibcallImpl NewFn,
145145

146146
// FIXME: When RuntimeLibcalls is an analysis, check if the function is really
147147
// supported, and go through RTLIB::Libcall.
148-
StringRef NewFnName = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(NewFn);
148+
const char *NewFnName = RTLIB::RuntimeLibcallsInfo::getLibcallImplName(NewFn);
149149

150150
// If we haven't already looked up this function, check to see if the
151151
// program already contains a function with this name.

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "llvm/IR/RuntimeLibcalls.h"
1010
#include "llvm/ADT/StringTable.h"
1111
#include "llvm/Support/Debug.h"
12-
#include "llvm/Support/xxhash.h"
1312
#include "llvm/TargetParser/ARMTargetParser.h"
1413

1514
#define DEBUG_TYPE "runtime-libcalls-info"
@@ -19,11 +18,9 @@ using namespace RTLIB;
1918

2019
#define GET_INIT_RUNTIME_LIBCALL_NAMES
2120
#define GET_SET_TARGET_RUNTIME_LIBCALL_SETS
22-
#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
2321
#include "llvm/IR/RuntimeLibcalls.inc"
2422
#undef GET_INIT_RUNTIME_LIBCALL_NAMES
2523
#undef GET_SET_TARGET_RUNTIME_LIBCALL_SETS
26-
#undef DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
2724

2825
/// Set default libcall names. If a target wants to opt-out of a libcall it
2926
/// should be placed here.
@@ -61,23 +58,49 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
6158
}
6259
}
6360

64-
LLVM_ATTRIBUTE_ALWAYS_INLINE
65-
iota_range<RTLIB::LibcallImpl>
66-
RuntimeLibcallsInfo::libcallImplNameHit(uint16_t NameOffsetEntry,
67-
uint16_t StrOffset) {
68-
int NumAliases = 1;
69-
for (uint16_t Entry : ArrayRef(RuntimeLibcallNameOffsetTable)
70-
.drop_front(NameOffsetEntry + 1)) {
71-
if (Entry != StrOffset)
72-
break;
73-
++NumAliases;
61+
RTLIB::LibcallImpl
62+
RuntimeLibcallsInfo::getSupportedLibcallImpl(StringRef FuncName) const {
63+
const ArrayRef<uint16_t> RuntimeLibcallNameOffsets(
64+
RuntimeLibcallNameOffsetTable);
65+
66+
iterator_range<ArrayRef<uint16_t>::const_iterator> Range =
67+
getRecognizedLibcallImpls(FuncName);
68+
69+
for (auto I = Range.begin(); I != Range.end(); ++I) {
70+
RTLIB::LibcallImpl Impl =
71+
static_cast<RTLIB::LibcallImpl>(I - RuntimeLibcallNameOffsets.begin());
72+
73+
// FIXME: This should not depend on looking up ImplToLibcall, only the list
74+
// of libcalls for the module.
75+
RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
76+
if (Recognized != RTLIB::Unsupported)
77+
return Recognized;
7478
}
7579

76-
RTLIB::LibcallImpl ImplStart = static_cast<RTLIB::LibcallImpl>(
77-
&RuntimeLibcallNameOffsetTable[NameOffsetEntry] -
78-
&RuntimeLibcallNameOffsetTable[0]);
79-
return enum_seq(ImplStart,
80-
static_cast<RTLIB::LibcallImpl>(ImplStart + NumAliases));
80+
return RTLIB::Unsupported;
81+
}
82+
83+
iterator_range<ArrayRef<uint16_t>::const_iterator>
84+
RuntimeLibcallsInfo::getRecognizedLibcallImpls(StringRef FuncName) {
85+
StringTable::Iterator It = lower_bound(RuntimeLibcallImplNameTable, FuncName);
86+
if (It == RuntimeLibcallImplNameTable.end() || *It != FuncName)
87+
return iterator_range(ArrayRef<uint16_t>());
88+
89+
uint16_t IndexVal = It.offset().value();
90+
const ArrayRef<uint16_t> TableRef(RuntimeLibcallNameOffsetTable);
91+
92+
ArrayRef<uint16_t>::const_iterator E = TableRef.end();
93+
ArrayRef<uint16_t>::const_iterator EntriesBegin =
94+
std::lower_bound(TableRef.begin(), E, IndexVal);
95+
ArrayRef<uint16_t>::const_iterator EntriesEnd = EntriesBegin;
96+
97+
while (EntriesEnd != E && *EntriesEnd == IndexVal)
98+
++EntriesEnd;
99+
100+
assert(EntriesBegin != E &&
101+
"libcall found in name table but not offset table");
102+
103+
return make_range(EntriesBegin, EntriesEnd);
81104
}
82105

83106
bool RuntimeLibcallsInfo::isAAPCS_ABI(const Triple &TT, StringRef ABIName) {

llvm/lib/LTO/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {
14221422

14231423
for (RTLIB::LibcallImpl Impl : LibcallImpls) {
14241424
if (Impl != RTLIB::Unsupported)
1425-
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl).data());
1425+
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl));
14261426
}
14271427

14281428
return LibcallSymbols;

0 commit comments

Comments
 (0)