[llvm-branch-commits] [llvm] RuntimeLibcallsEmitter: Attribute DefaultCC to the library that references it (PR #229568)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Oct 7 02:54:34 PDT 2026
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/229568
>From 62ec7a1a29e598a7d59aa76eb2ff97958fecf8e3 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Tue, 15 Sep 2026 22:41:59 +0200
Subject: [PATCH] RuntimeLibcallsEmitter: Attribute DefaultCC to the library
that references it
Libraries sharing a LibraryName are emitted as one function, so the
DefaultCC for that function was collected from every SystemRuntimeLibrary
that referenced any library with that name. A consumer that references
only a variant not using DefaultCC still contributed its
DefaultLibcallCallingConv, and two such consumers made the name ambiguous.
Only take DefaultCC from consumers whose referenced library uses it. This
is needed once ARM's DefaultCC-using compiler-rt and Lanai's FASTCC both
reference the shared "compiler-rt" name. No change to generated output.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
---
.../TableGen/Basic/RuntimeLibcallsEmitter.cpp | 30 +++++++++++++++----
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
index f4b6a10198b1a..a2f585c63e167 100644
--- a/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/RuntimeLibcallsEmitter.cpp
@@ -139,6 +139,9 @@ class RuntimeLibcallEmitter {
MapVector<StringRef, std::vector<const Record *>>
collectLibrariesByName() const;
+ // Whether any member of \p Lib has a calling convention using DefaultCC.
+ bool libraryReferencesDefaultCC(const Record *Lib) const;
+
void emitRuntimeLibcallsInfoMemberDecls(raw_ostream &OS) const;
void emitSystemRuntimeLibrarySetCalls(raw_ostream &OS) const;
@@ -727,6 +730,22 @@ static StringRef libFuncKey(const Record *Lib) {
: Lib->getValueAsString("LibraryName");
}
+bool RuntimeLibcallEmitter::libraryReferencesDefaultCC(
+ const Record *Lib) const {
+ SetTheory Sets;
+ DenseMap<const RuntimeLibcallImpl *,
+ std::pair<std::vector<const Record *>, const Record *>>
+ Func2Preds;
+ Sets.addExpander("LibcallImpls", std::make_unique<LibcallPredicateExpander>(
+ Libcalls, Func2Preds));
+ SetTheory::RecSet Elements;
+ Sets.evaluate(Lib->getValueInit("Impls"), Elements, Lib->getLoc());
+ return any_of(Func2Preds, [](const auto &ImplAndPreds) {
+ const Record *CC = ImplAndPreds.second.second;
+ return CC && CC->getValueAsString("CallingConv").contains("DefaultCC");
+ });
+}
+
MapVector<StringRef, std::vector<const Record *>>
RuntimeLibcallEmitter::collectLibrariesByName() const {
MapVector<StringRef, std::vector<const Record *>> LibsByName;
@@ -778,11 +797,10 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
}
}
- // Collect, per library name, the distinct DefaultLibcallCallingConv snippets
- // its consuming system libraries supply (a plain Record walk; no member
- // expansion). emitLibraryFunction, which already expands the members, picks
- // the snippet for a library that names the DefaultCC sentinel and diagnoses a
- // missing (none) or ambiguous (more than one) snippet.
+ // Collect, per library name, the distinct DefaultLibcallCallingConv of each
+ // system library referencing a library that uses DefaultCC. Other libraries
+ // sharing the name do not contribute. emitLibraryFunction diagnoses a missing
+ // or ambiguous DefaultCC.
MapVector<StringRef, SetVector<StringRef>> DefaultCCsByLibName;
for (const Record *R : AllLibs) {
const Record *DefaultCCClass =
@@ -804,7 +822,7 @@ void RuntimeLibcallEmitter::emitSystemRuntimeLibrarySetCalls(
Lib = Def;
else if (Def->isSubClassOf("LibraryRef"))
Lib = Def->getValueAsDef("Library");
- if (!Lib)
+ if (!Lib || !libraryReferencesDefaultCC(Lib))
continue;
DefaultCCsByLibName[Lib->getValueAsString("LibraryName")].insert(
DefaultCC);
More information about the llvm-branch-commits
mailing list