diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h index 85db45e27e912..8058c8a4c5510 100644 --- a/llvm/include/llvm/IR/RuntimeLibcalls.h +++ b/llvm/include/llvm/IR/RuntimeLibcalls.h @@ -16,6 +16,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Sequence.h" +#include "llvm/ADT/StringTable.h" #include "llvm/IR/CallingConv.h" #include "llvm/IR/InstrTypes.h" #include "llvm/Support/AtomicOrdering.h" @@ -77,12 +78,16 @@ struct RuntimeLibcallsInfo { /// Get the libcall routine name for the specified libcall. // FIXME: This should be removed. Only LibcallImpl should have a name. const char *getLibcallName(RTLIB::Libcall Call) const { - return LibCallImplNames[LibcallImpls[Call]]; + return getLibcallImplName(LibcallImpls[Call]); } /// Get the libcall routine name for the specified libcall implementation. + // FIXME: Change to return StringRef static const char *getLibcallImplName(RTLIB::LibcallImpl CallImpl) { - return LibCallImplNames[CallImpl]; + if (CallImpl == RTLIB::Unsupported) + return nullptr; + return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]] + .data(); } /// Return the lowering's selection of implementation call for \p Call @@ -144,7 +149,9 @@ struct RuntimeLibcallsInfo { /// Names of concrete implementations of runtime calls. e.g. __ashlsi3 for /// SHL_I32 - LLVM_ABI static const char *const LibCallImplNames[RTLIB::NumLibcallImpls]; + LLVM_ABI static const char RuntimeLibcallImplNameTableStorage[]; + LLVM_ABI static const StringTable RuntimeLibcallImplNameTable; + LLVM_ABI static const uint16_t RuntimeLibcallNameOffsetTable[]; /// Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind. LLVM_ABI static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls]; diff --git a/llvm/include/llvm/TableGen/StringToOffsetTable.h b/llvm/include/llvm/TableGen/StringToOffsetTable.h index 1550515ce3d7b..154ded8e94d7f 100644 --- a/llvm/include/llvm/TableGen/StringToOffsetTable.h +++ b/llvm/include/llvm/TableGen/StringToOffsetTable.h @@ -23,10 +23,15 @@ namespace llvm { class StringToOffsetTable { StringMap StringOffset; std::string AggregateString; + + /// If this is to be a static class member, the prefix to use (i.e. class name + /// plus ::) + const StringRef ClassPrefix; const bool AppendZero; public: - StringToOffsetTable(bool AppendZero = true) : AppendZero(AppendZero) { + StringToOffsetTable(bool AppendZero = true, StringRef ClassPrefix = "") + : ClassPrefix(ClassPrefix), AppendZero(AppendZero) { // Ensure we always put the empty string at offset zero. That lets empty // initialization also be zero initialization for offsets into the table. GetOrAddStringOffset(""); diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp index 6624e24cc7cf5..b1864897dafa6 100644 --- a/llvm/lib/IR/RuntimeLibcalls.cpp +++ b/llvm/lib/IR/RuntimeLibcalls.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/IR/RuntimeLibcalls.h" +#include "llvm/ADT/StringTable.h" using namespace llvm; using namespace RTLIB; diff --git a/llvm/lib/TableGen/StringToOffsetTable.cpp b/llvm/lib/TableGen/StringToOffsetTable.cpp index 17e1e660c15ee..9fb41485db745 100644 --- a/llvm/lib/TableGen/StringToOffsetTable.cpp +++ b/llvm/lib/TableGen/StringToOffsetTable.cpp @@ -38,8 +38,8 @@ void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS, #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Woverlength-strings" #endif -static constexpr char {}Storage[] = )", - Name); +{} constexpr char {}{}Storage[] = )", + ClassPrefix.empty() ? "static" : "", ClassPrefix, Name); // MSVC silently miscompiles string literals longer than 64k in some // circumstances. The build system sets EmitLongStrLiterals to false when it @@ -83,10 +83,10 @@ static constexpr char {}Storage[] = )", #pragma GCC diagnostic pop #endif -static constexpr llvm::StringTable -{0} = {0}Storage; +{1}constexpr llvm::StringTable +{2}{0} = {0}Storage; )", - Name); + Name, ClassPrefix.empty() ? "static " : "", ClassPrefix); } void StringToOffsetTable::EmitString(raw_ostream &O) const { diff --git a/llvm/test/TableGen/RuntimeLibcallEmitter.td b/llvm/test/TableGen/RuntimeLibcallEmitter.td index a0061afab1db0..2a7da5dede3f6 100644 --- a/llvm/test/TableGen/RuntimeLibcallEmitter.td +++ b/llvm/test/TableGen/RuntimeLibcallEmitter.td @@ -116,19 +116,40 @@ def BlahLibrary : SystemRuntimeLibrary