@@ -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- const char * getLibcallName (RTLIB::Libcall Call) const {
80+ StringRef getLibcallName (RTLIB::Libcall Call) const {
8181 return getLibcallImplName (LibcallImpls[Call]);
8282 }
8383
8484 // / Get the libcall routine name for the specified libcall implementation.
85- // FIXME: Change to return StringRef
86- static const char *getLibcallImplName (RTLIB::LibcallImpl CallImpl) {
85+ static StringRef getLibcallImplName (RTLIB::LibcallImpl CallImpl) {
8786 if (CallImpl == RTLIB::Unsupported)
88- return nullptr ;
89- return RuntimeLibcallImplNameTable[RuntimeLibcallNameOffsetTable[CallImpl]]
90- .data ();
87+ return StringRef ();
88+ return StringRef (RuntimeLibcallImplNameTable.getCString (
89+ RuntimeLibcallNameOffsetTable[CallImpl]),
90+ RuntimeLibcallNameSizeTable[CallImpl]);
9191 }
9292
9393 // / Return the lowering's selection of implementation call for \p Call
@@ -119,9 +119,10 @@ struct RuntimeLibcallsInfo {
119119
120120 // / Return a function name compatible with RTLIB::MEMCPY, or nullptr if fully
121121 // / unsupported.
122- const char *getMemcpyName () const {
123- if (const char *Memcpy = getLibcallName (RTLIB::MEMCPY))
124- return Memcpy;
122+ StringRef getMemcpyName () const {
123+ RTLIB::LibcallImpl Memcpy = getLibcallImpl (RTLIB::MEMCPY);
124+ if (Memcpy != RTLIB::Unsupported)
125+ return getLibcallImplName (Memcpy);
125126
126127 // Fallback to memmove if memcpy isn't available.
127128 return getLibcallName (RTLIB::MEMMOVE);
@@ -132,11 +133,41 @@ struct RuntimeLibcallsInfo {
132133 return ImplToLibcall[Impl];
133134 }
134135
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+
135152 // / Check if this is valid libcall for the current module, otherwise
136153 // / RTLIB::Unsupported.
137- LLVM_ABI RTLIB::LibcallImpl getSupportedLibcallImpl (StringRef FuncName) const ;
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+ }
138166
139167private:
168+ LLVM_ABI static iota_range<RTLIB::LibcallImpl>
169+ lookupLibcallImplNameImpl (StringRef Name);
170+
140171 // / Stores the implementation choice for each each libcall.
141172 RTLIB::LibcallImpl LibcallImpls[RTLIB::UNKNOWN_LIBCALL + 1 ] = {
142173 RTLIB::Unsupported};
@@ -153,17 +184,16 @@ struct RuntimeLibcallsInfo {
153184 LLVM_ABI static const char RuntimeLibcallImplNameTableStorage[];
154185 LLVM_ABI static const StringTable RuntimeLibcallImplNameTable;
155186 LLVM_ABI static const uint16_t RuntimeLibcallNameOffsetTable[];
187+ LLVM_ABI static const uint8_t RuntimeLibcallNameSizeTable[];
156188
157189 // / Map from a concrete LibcallImpl implementation to its RTLIB::Libcall kind.
158190 LLVM_ABI static const RTLIB::Libcall ImplToLibcall[RTLIB::NumLibcallImpls];
159191
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);
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);
167197
168198 static bool darwinHasSinCosStret (const Triple &TT) {
169199 if (!TT.isOSDarwin ())
0 commit comments