diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp index d5c4532824c07..4548a7520b3b4 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp @@ -528,25 +528,19 @@ RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() { // constructor for use with a static variable struct StaticLibcallNameMap { StringMap Map; - StaticLibcallNameMap() { - static const std::pair NameLibcalls[] = { -#define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code}, -#define LIBCALL_NO_NAME nullptr -#include "llvm/IR/RuntimeLibcalls.def" -#undef HANDLE_LIBCALL -#undef LIBCALL_NO_NAME - }; - for (const auto &NameLibcall : NameLibcalls) { - if (NameLibcall.first != nullptr && - getRuntimeLibcallSignatures().Table[NameLibcall.second] != - unsupported) { - assert(!Map.contains(NameLibcall.first) && + StaticLibcallNameMap(const Triple &TT) { + // FIXME: This is broken if there are ever different triples compiled with + // different libcalls. + RTLIB::RuntimeLibcallsInfo RTCI(TT); + for (RTLIB::Libcall LC : RTLIB::libcalls()) { + const char *NameLibcall = RTCI.getLibcallName(LC); + if (NameLibcall != nullptr && + getRuntimeLibcallSignatures().Table[LC] != unsupported) { + assert(!Map.contains(NameLibcall) && "duplicate libcall names in name map"); - Map[NameLibcall.first] = NameLibcall.second; + Map[NameLibcall] = LC; } } - - Map["emscripten_return_address"] = RTLIB::RETURN_ADDRESS; } }; @@ -942,7 +936,7 @@ void WebAssembly::getLibcallSignature(const WebAssemblySubtarget &Subtarget, StringRef Name, SmallVectorImpl &Rets, SmallVectorImpl &Params) { - static StaticLibcallNameMap LibcallNameMap; + static StaticLibcallNameMap LibcallNameMap(Subtarget.getTargetTriple()); auto &Map = LibcallNameMap.Map; auto Val = Map.find(Name); #ifndef NDEBUG