diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2025-08-12 21:08:47 +0900 |
---|---|---|
committer | Matt Arsenault <arsenm2@gmail.com> | 2025-08-13 16:49:59 +0900 |
commit | 1d38b18aa6e8cb346c05aed9262d8e1e378a6d5f (patch) | |
tree | 58c9917c467f122e4befd014a6193d0d83555049 | |
parent | b38597a96f3552cd45daa94defd5fc63acd45183 (diff) | |
download | llvm-users/arsenm/runtime-libcalls/store-libcall-string-lengths-table.zip llvm-users/arsenm/runtime-libcalls/store-libcall-string-lengths-table.tar.gz llvm-users/arsenm/runtime-libcalls/store-libcall-string-lengths-table.tar.bz2 |
RuntimeLibcalls: Generate table of libcall name lengthsusers/arsenm/runtime-libcalls/store-libcall-string-lengths-table
Avoids strlen when constructing the returned StringRef. We were emitting
these in the libcall name lookup anyway, so split out the offsets for
general use.
Currently emitted as a separate table, not sure if it would be better
to change the string offset table to store pairs of offset and width
instead.
-rw-r--r-- | llvm/include/llvm/IR/RuntimeLibcalls.h | 5 | ||||
-rw-r--r-- | llvm/test/TableGen/RuntimeLibcallEmitter.td | 22 | ||||
-rw-r--r-- | llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp | 24 |
3 files changed, 37 insertions, 14 deletions
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 98c3dd0..4b9c300 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -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 @@ -182,6 +184,7 @@ private: 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]; diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter.td b/llvm/test/TableGen/RuntimeLibcallEmitter.td index 4128219..41d2196 100644 --- a/llvm/test/TableGen/RuntimeLibcallEmitter.td +++ b/llvm/test/TableGen/RuntimeLibcallEmitter.td @@ -137,6 +137,18 @@ 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: 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 @@ -162,11 +174,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; diff --git a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp index 0423139..7dfa10d 100644 --- a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp +++ b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp @@ -463,15 +463,13 @@ void RuntimeLibcallEmitter::emitNameMatchHashTable( // 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"; + 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'; } @@ -482,11 +480,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); } @@ -522,6 +521,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" |