Skip to content

Revert "RuntimeLibcalls: Generate table of libcall name lengths (#153… #153864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions llvm/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,3 @@ add_benchmark(FormatVariadicBM FormatVariadicBM.cpp PARTIAL_SOURCES_INTENDED)
add_benchmark(GetIntrinsicInfoTableEntriesBM GetIntrinsicInfoTableEntriesBM.cpp PARTIAL_SOURCES_INTENDED)
add_benchmark(SandboxIRBench SandboxIRBench.cpp PARTIAL_SOURCES_INTENDED)

# Extract the list of symbols in a random utility as sample data.
set(SYMBOL_TEST_DATA_FILE "sample_symbol_list.txt")
set(SYMBOL_TEST_DATA_SOURCE_BINARY $<TARGET_FILE:llc>)

add_custom_command(OUTPUT ${SYMBOL_TEST_DATA_FILE}
COMMAND $<TARGET_FILE:llvm-nm> --no-demangle --no-sort
--format=just-symbols
${SYMBOL_TEST_DATA_SOURCE_BINARY} > ${SYMBOL_TEST_DATA_FILE}
DEPENDS "$<TARGET_FILE:llvm-nm>" "$<TARGET_FILE:llc>")

add_custom_target(generate-runtime-libcalls-sample-symbol-list
DEPENDS ${SYMBOL_TEST_DATA_FILE})
add_benchmark(RuntimeLibcallsBench RuntimeLibcalls.cpp PARTIAL_SOURCES_INTENDED)

add_dependencies(RuntimeLibcallsBench generate-runtime-libcalls-sample-symbol-list)
target_compile_definitions(RuntimeLibcallsBench PRIVATE
-DSYMBOL_TEST_DATA_FILE="${CMAKE_CURRENT_BINARY_DIR}/${SYMBOL_TEST_DATA_FILE}")
114 changes: 0 additions & 114 deletions llvm/benchmarks/RuntimeLibcalls.cpp

This file was deleted.

12 changes: 4 additions & 8 deletions llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -3557,19 +3557,15 @@ class LLVM_ABI TargetLoweringBase {

/// Get the libcall routine name for the specified libcall.
const char *getLibcallName(RTLIB::Libcall Call) const {
// FIXME: Return StringRef
return Libcalls.getLibcallName(Call).data();
return Libcalls.getLibcallName(Call);
}

/// Get the libcall routine name for the specified libcall implementation
static StringRef getLibcallImplName(RTLIB::LibcallImpl Call) {
return RTLIB::RuntimeLibcallsInfo::getLibcallImplName(Call);
const char *getLibcallImplName(RTLIB::LibcallImpl Call) const {
return Libcalls.getLibcallImplName(Call);
}

const char *getMemcpyName() const {
// FIXME: Return StringRef
return Libcalls.getMemcpyName().data();
}
const char *getMemcpyName() const { return Libcalls.getMemcpyName(); }

/// Get the comparison predicate that's to be used to test the result of the
/// comparison libcall against zero. This should only be used with
Expand Down
64 changes: 17 additions & 47 deletions llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ struct RuntimeLibcallsInfo {

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

/// Get the libcall routine name for the specified libcall implementation.
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
// FIXME: Change to return StringRef
static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
if (CallImpl == RTLIB::Unsupported)
return StringRef();
return StringRef(RuntimeLibcallImplNameTable.getCString(
RuntimeLibcallNameOffsetTable[CallImpl]),
RuntimeLibcallNameSizeTable[CallImpl]);
return nullptr;
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
.data();
}

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

/// Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
/// unsupported.
StringRef getMemcpyName() const {
RTLIB::LibcallImpl Memcpy = getLibcallImpl(RTLIB::MEMCPY);
if (Memcpy != RTLIB::Unsupported)
return getLibcallImplName(Memcpy);
const char *getMemcpyName() const {
if (const char *Memcpy = getLibcallName(RTLIB::MEMCPY))
return Memcpy;

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

/// Check if a function name is a recognized runtime call of any kind. This
/// does not consider if this call is available for any current compilation,
/// just that it is a known call somewhere. This returns the set of all
/// LibcallImpls which match the name; multiple implementations with the same
/// name may exist but differ in interpretation based on the target context.
///
/// Generated by tablegen.
LLVM_ABI static inline iota_range<RTLIB::LibcallImpl>
lookupLibcallImplName(StringRef Name){
// Inlining the early exit on the string name appears to be worthwhile when
// querying a real set of symbols
#define GET_LOOKUP_LIBCALL_IMPL_NAME_BODY
#include "llvm/IR/RuntimeLibcalls.inc"
#undef GET_LOOKUP_LIBCALL_IMPL_NAME_BODY
}

/// Check if this is valid libcall for the current module, otherwise
/// RTLIB::Unsupported.
LLVM_ABI RTLIB::LibcallImpl
getSupportedLibcallImpl(StringRef FuncName) const {
for (RTLIB::LibcallImpl Impl : lookupLibcallImplName(FuncName)) {
// FIXME: This should not depend on looking up ImplToLibcall, only the
// list of libcalls for the module.
RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
if (Recognized != RTLIB::Unsupported)
return Recognized;
}

return RTLIB::Unsupported;
}
LLVM_ABI RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const;

private:
LLVM_ABI static iota_range<RTLIB::LibcallImpl>
lookupLibcallImplNameImpl(StringRef Name);

/// Stores the implementation choice for each each libcall.
RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1] = {
RTLIB::Unsupported};
Expand All @@ -184,16 +153,17 @@ struct RuntimeLibcallsInfo {
LLVM_ABI static const char RuntimeLibcallImplNameTableStorage[];
LLVM_ABI static const StringTable RuntimeLibcallImplNameTable;
LLVM_ABI static const uint16_t RuntimeLibcallNameOffsetTable[];
LLVM_ABI static const uint8_t RuntimeLibcallNameSizeTable[];

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

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

static bool darwinHasSinCosStret(const Triple &TT) {
if (!TT.isOSDarwin())
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static bool lowerObjCCall(Function &F, RTLIB::LibcallImpl NewFn,

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

// If we haven't already looked up this function, check to see if the
// program already contains a function with this name.
Expand Down
59 changes: 41 additions & 18 deletions llvm/lib/IR/RuntimeLibcalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "llvm/IR/RuntimeLibcalls.h"
#include "llvm/ADT/StringTable.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/xxhash.h"
#include "llvm/TargetParser/ARMTargetParser.h"

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

#define GET_INIT_RUNTIME_LIBCALL_NAMES
#define GET_SET_TARGET_RUNTIME_LIBCALL_SETS
#define DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME
#include "llvm/IR/RuntimeLibcalls.inc"
#undef GET_INIT_RUNTIME_LIBCALL_NAMES
#undef GET_SET_TARGET_RUNTIME_LIBCALL_SETS
#undef DEFINE_GET_LOOKUP_LIBCALL_IMPL_NAME

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

LLVM_ATTRIBUTE_ALWAYS_INLINE
iota_range<RTLIB::LibcallImpl>
RuntimeLibcallsInfo::libcallImplNameHit(uint16_t NameOffsetEntry,
uint16_t StrOffset) {
int NumAliases = 1;
for (uint16_t Entry : ArrayRef(RuntimeLibcallNameOffsetTable)
.drop_front(NameOffsetEntry + 1)) {
if (Entry != StrOffset)
break;
++NumAliases;
RTLIB::LibcallImpl
RuntimeLibcallsInfo::getSupportedLibcallImpl(StringRef FuncName) const {
const ArrayRef<uint16_t> RuntimeLibcallNameOffsets(
RuntimeLibcallNameOffsetTable);

iterator_range<ArrayRef<uint16_t>::const_iterator> Range =
getRecognizedLibcallImpls(FuncName);

for (auto I = Range.begin(); I != Range.end(); ++I) {
RTLIB::LibcallImpl Impl =
static_cast<RTLIB::LibcallImpl>(I - RuntimeLibcallNameOffsets.begin());

// FIXME: This should not depend on looking up ImplToLibcall, only the list
// of libcalls for the module.
RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
if (Recognized != RTLIB::Unsupported)
return Recognized;
}

RTLIB::LibcallImpl ImplStart = static_cast<RTLIB::LibcallImpl>(
&RuntimeLibcallNameOffsetTable[NameOffsetEntry] -
&RuntimeLibcallNameOffsetTable[0]);
return enum_seq(ImplStart,
static_cast<RTLIB::LibcallImpl>(ImplStart + NumAliases));
return RTLIB::Unsupported;
}

iterator_range<ArrayRef<uint16_t>::const_iterator>
RuntimeLibcallsInfo::getRecognizedLibcallImpls(StringRef FuncName) {
StringTable::Iterator It = lower_bound(RuntimeLibcallImplNameTable, FuncName);
if (It == RuntimeLibcallImplNameTable.end() || *It != FuncName)
return iterator_range(ArrayRef<uint16_t>());

uint16_t IndexVal = It.offset().value();
const ArrayRef<uint16_t> TableRef(RuntimeLibcallNameOffsetTable);

ArrayRef<uint16_t>::const_iterator E = TableRef.end();
ArrayRef<uint16_t>::const_iterator EntriesBegin =
std::lower_bound(TableRef.begin(), E, IndexVal);
ArrayRef<uint16_t>::const_iterator EntriesEnd = EntriesBegin;

while (EntriesEnd != E && *EntriesEnd == IndexVal)
++EntriesEnd;

assert(EntriesBegin != E &&
"libcall found in name table but not offset table");

return make_range(EntriesBegin, EntriesEnd);
}

bool RuntimeLibcallsInfo::isAAPCS_ABI(const Triple &TT, StringRef ABIName) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/LTO/LTO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ SmallVector<const char *> LTO::getRuntimeLibcallSymbols(const Triple &TT) {

for (RTLIB::LibcallImpl Impl : LibcallImpls) {
if (Impl != RTLIB::Unsupported)
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl).data());
LibcallSymbols.push_back(Libcalls.getLibcallImplName(Impl));
}

return LibcallSymbols;
Expand Down
Loading