Skip to content

Commit efd42b9

Browse files
authored
WebAssembly: Stop directly using RuntimeLibcalls.def (#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.
1 parent 9143981 commit efd42b9

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -528,25 +528,19 @@ RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() {
528528
// constructor for use with a static variable
529529
struct StaticLibcallNameMap {
530530
StringMap<RTLIB::Libcall> Map;
531-
StaticLibcallNameMap() {
532-
static const std::pair<const char *, RTLIB::Libcall> NameLibcalls[] = {
533-
#define HANDLE_LIBCALL(code, name) {(const char *)name, RTLIB::code},
534-
#define LIBCALL_NO_NAME nullptr
535-
#include "llvm/IR/RuntimeLibcalls.def"
536-
#undef HANDLE_LIBCALL
537-
#undef LIBCALL_NO_NAME
538-
};
539-
for (const auto &NameLibcall : NameLibcalls) {
540-
if (NameLibcall.first != nullptr &&
541-
getRuntimeLibcallSignatures().Table[NameLibcall.second] !=
542-
unsupported) {
543-
assert(!Map.contains(NameLibcall.first) &&
531+
StaticLibcallNameMap(const Triple &TT) {
532+
// FIXME: This is broken if there are ever different triples compiled with
533+
// different libcalls.
534+
RTLIB::RuntimeLibcallsInfo RTCI(TT);
535+
for (RTLIB::Libcall LC : RTLIB::libcalls()) {
536+
const char *NameLibcall = RTCI.getLibcallName(LC);
537+
if (NameLibcall != nullptr &&
538+
getRuntimeLibcallSignatures().Table[LC] != unsupported) {
539+
assert(!Map.contains(NameLibcall) &&
544540
"duplicate libcall names in name map");
545-
Map[NameLibcall.first] = NameLibcall.second;
541+
Map[NameLibcall] = LC;
546542
}
547543
}
548-
549-
Map["emscripten_return_address"] = RTLIB::RETURN_ADDRESS;
550544
}
551545
};
552546

@@ -942,7 +936,7 @@ void WebAssembly::getLibcallSignature(const WebAssemblySubtarget &Subtarget,
942936
StringRef Name,
943937
SmallVectorImpl<wasm::ValType> &Rets,
944938
SmallVectorImpl<wasm::ValType> &Params) {
945-
static StaticLibcallNameMap LibcallNameMap;
939+
static StaticLibcallNameMap LibcallNameMap(Subtarget.getTargetTriple());
946940
auto &Map = LibcallNameMap.Map;
947941
auto Val = Map.find(Name);
948942
#ifndef NDEBUG

0 commit comments

Comments
 (0)