Skip to content

Commit 7a49ea2

Browse files
committed
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.
1 parent 9fd32f4 commit 7a49ea2

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -528,23 +528,20 @@ 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-
#include "llvm/IR/RuntimeLibcalls.def"
535-
#undef HANDLE_LIBCALL
536-
};
537-
for (const auto &NameLibcall : NameLibcalls) {
538-
if (NameLibcall.first != nullptr &&
539-
getRuntimeLibcallSignatures().Table[NameLibcall.second] !=
540-
unsupported) {
541-
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 (int I = 0; I < RTLIB::UNKNOWN_LIBCALL; ++I) {
536+
RTLIB::Libcall LC = static_cast<RTLIB::Libcall>(I);
537+
const char *NameLibcall = RTCI.getLibcallName(LC);
538+
if (NameLibcall != nullptr &&
539+
getRuntimeLibcallSignatures().Table[LC] != unsupported) {
540+
assert(!Map.contains(NameLibcall) &&
542541
"duplicate libcall names in name map");
543-
Map[NameLibcall.first] = NameLibcall.second;
542+
Map[NameLibcall] = LC;
544543
}
545544
}
546-
547-
Map["emscripten_return_address"] = RTLIB::RETURN_ADDRESS;
548545
}
549546
};
550547

@@ -940,7 +937,7 @@ void WebAssembly::getLibcallSignature(const WebAssemblySubtarget &Subtarget,
940937
StringRef Name,
941938
SmallVectorImpl<wasm::ValType> &Rets,
942939
SmallVectorImpl<wasm::ValType> &Params) {
943-
static StaticLibcallNameMap LibcallNameMap;
940+
static StaticLibcallNameMap LibcallNameMap(Subtarget.getTargetTriple());
944941
auto &Map = LibcallNameMap.Map;
945942
auto Val = Map.find(Name);
946943
#ifndef NDEBUG

0 commit comments

Comments
 (0)