https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/143054
Construct RuntimeLibcallsInfo instead of manually creating a map. This was repeating the setting of the RETURN_ADDRESS. This removes an obstacle to generating libcall information with tablegen. This is also not great, since it's setting a static map which would be broken if there were ever a triple with a different libcall configuration. >From 9405d81822edcfc0071c8de5c1d09dcb8ea22910 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <matthew.arsena...@amd.com> Date: Fri, 6 Jun 2025 10:01:59 +0900 Subject: [PATCH] WebAssembly: Stop directly using RuntimeLibcalls.def Construct RuntimeLibcallsInfo instead of manually creating a map. This was repeating the setting of the RETURN_ADDRESS. This removes an obstacle to generating libcall information with tablegen. This is also not great, since it's setting a static map which would be broken if there were ever a triple with a different libcall configuration. --- .../WebAssemblyRuntimeLibcallSignatures.cpp | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp index ce795d3dedc6a..9622b5a54dc62 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp @@ -528,23 +528,20 @@ RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() { // constructor for use with a static variable struct StaticLibcallNameMap { StringMap<RTLIB::Libcall> Map; - StaticLibcallNameMap() { - static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = { -#define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code}, -#include "llvm/IR/RuntimeLibcalls.def" -#undef HANDLE_LIBCALL - }; - 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 (int I = 0; I < RTLIB::UNKNOWN_LIBCALL; ++I) { + RTLIB::Libcall LC = static_cast<RTLIB::Libcall>(I); + 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; } }; @@ -940,7 +937,7 @@ void WebAssembly::getLibcallSignature(const WebAssemblySubtarget &Subtarget, StringRef Name, SmallVectorImpl<wasm::ValType> &Rets, SmallVectorImpl<wasm::ValType> &Params) { - static StaticLibcallNameMap LibcallNameMap; + static StaticLibcallNameMap LibcallNameMap(Subtarget.getTargetTriple()); auto &Map = LibcallNameMap.Map; auto Val = Map.find(Name); #ifndef NDEBUG _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits