Skip to content
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
5 changes: 4 additions & 1 deletion llvm/include/llvm/IR/RuntimeLibcalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ struct RuntimeLibcallsInfo {
static StringRef getLibcallImplName(RTLIB::LibcallImpl CallImpl) {
if (CallImpl == RTLIB::Unsupported)
return StringRef();
return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]];
return StringRef(RuntimeLibcallImplNameTable.getCString(
RuntimeLibcallNameOffsetTable[CallImpl]),
RuntimeLibcallNameSizeTable[CallImpl]);
}

/// Return the lowering's selection of implementation call for \p Call
Expand Down Expand Up @@ -182,6 +184,7 @@ 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];
Expand Down
23 changes: 18 additions & 5 deletions llvm/test/TableGen/RuntimeLibcallEmitter.td
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
// CHECK-NEXT: 54, // sqrtl
// CHECK-NEXT: 54, // sqrtl
// CHECK-NEXT: };
// CHECK-EMPTY:
// CHECK-NEXT: const uint8_t RTLIB::RuntimeLibcallsInfo::RuntimeLibcallNameSizeTable[] = {
// CHECK-NEXT: 0,
// CHECK-NEXT: 9,
// CHECK-NEXT: 9,
// CHECK-NEXT: 9,
// CHECK-NEXT: 9,
// CHECK-NEXT: 5,
// CHECK-NEXT: 6,
// CHECK-NEXT: 5,
// CHECK-NEXT: 5,
// CHECK-NEXT: };
// CHECK-EMPTY:
// CHECK-NEXT: const RTLIB::Libcall llvm::RTLIB::RuntimeLibcallsInfo::ImplToLibcall[RTLIB::NumLibcallImpls] = {
// CHECK-NEXT: RTLIB::UNKNOWN_LIBCALL, // RTLIB::Unsupported
// CHECK-NEXT: RTLIB::MEMCPY, // RTLIB::___memcpy
Expand All @@ -162,11 +175,11 @@ def BlahLibrary : SystemRuntimeLibrary<isBlahArch, (add calloc, LibraryWithCondi
// CHECK-NEXT: }

// CHECK: iota_range<RTLIB::LibcallImpl> RTLIB::RuntimeLibcallsInfo::lookupLibcallImplNameImpl(StringRef Name) {
// CHECK: static constexpr std::pair<uint16_t, uint16_t> HashTableNameToEnum[16] = {
// CHECK: {2, 9}, // 0x000000705301b8, ___memset
// CHECK: {0, 0},
// CHECK: {6, 6}, // 0x0000001417a2af, calloc
// CHECK: {0, 0},
// CHECK: static constexpr uint16_t HashTableNameToEnum[16] = {
// CHECK: 2, // 0x000000705301b8, ___memset
// CHECK: 0,
// CHECK: 6, // 0x0000001417a2af, calloc
// CHECK: 0,
// CHECK: };

// CHECK: unsigned Idx = (hash(Name) % 8) * 2;
Expand Down
27 changes: 17 additions & 10 deletions llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,14 @@ void RuntimeLibcallEmitter::emitNameMatchHashTable(
OS << "iota_range<RTLIB::LibcallImpl> RTLIB::RuntimeLibcallsInfo::"
"lookupLibcallImplNameImpl(StringRef Name) {\n";

// Emit pair of RTLIB::LibcallImpl, size of the string name. It's important to
// avoid strlen on the string table entries.
OS << " static constexpr std::pair<uint16_t, uint16_t> HashTableNameToEnum["
<< Lookup.size() << "] = {\n";
// Emit RTLIB::LibcallImpl values
OS << " static constexpr uint16_t HashTableNameToEnum[" << Lookup.size()
<< "] = {\n";

for (auto [FuncName, Hash, TableVal] : Lookup) {
OS << " {" << TableVal << ", " << FuncName.size() << "},";

if (TableVal != 0) {
OS << " " << TableVal << ',';
if (TableVal != 0)
OS << " // " << format_hex(Hash, 16) << ", " << FuncName;
}

OS << '\n';
}
Expand All @@ -480,11 +477,12 @@ void RuntimeLibcallEmitter::emitNameMatchHashTable(
<< ";\n\n"
" for (int I = 0; I != "
<< Collisions << R"(; ++I) {
auto [Entry, StringSize] = HashTableNameToEnum[Idx + I];
const uint16_t Entry = HashTableNameToEnum[Idx + I];
const uint16_t StrOffset = RuntimeLibcallNameOffsetTable[Entry];
const uint8_t StrSize = RuntimeLibcallNameSizeTable[Entry];
StringRef Str(
&RTLIB::RuntimeLibcallsInfo::RuntimeLibcallImplNameTableStorage[StrOffset],
StringSize);
StrSize);
if (Str == Name)
return libcallImplNameHit(Entry, StrOffset);
}
Expand Down Expand Up @@ -520,6 +518,15 @@ const uint16_t RTLIB::RuntimeLibcallsInfo::RuntimeLibcallNameOffsetTable[] = {
}
OS << "};\n";

OS << R"(
const uint8_t RTLIB::RuntimeLibcallsInfo::RuntimeLibcallNameSizeTable[] = {
)";

OS << " 0,\n";
for (const RuntimeLibcallImpl &LibCallImpl : RuntimeLibcallImplDefList)
OS << " " << LibCallImpl.getLibcallFuncName().size() << ",\n";
OS << "};\n\n";

// Emit the reverse mapping from implementation libraries to RTLIB::Libcall
OS << "const RTLIB::Libcall llvm::RTLIB::RuntimeLibcallsInfo::"
"ImplToLibcall[RTLIB::NumLibcallImpls] = {\n"
Expand Down