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 <[email protected]> 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) <[email protected]> --- .../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); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
