Skip to content

WebAssembly: Stop directly using RuntimeLibcalls.def #143054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,25 +528,19 @@ 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},
#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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we store the map in the subtarget instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs in TargetLowering, which is owned by the subtarget. I'll probably end up fixing this in the next step after moving the definitions to tablegen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signatures should be a static, generated table

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this handled in the new version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeLibcallsInfo directly sets this, this was already moved in the parent PR

}
};

Expand Down Expand Up @@ -942,7 +936,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
Expand Down
Loading