[llvm-branch-commits] [clang] Cherry pick: [Clang][Sema] Make UnresolvedLookupExprs in class scope explicit spec… (PR #102514)
https://github.com/nga888 created
https://github.com/llvm/llvm-project/pull/102514
…ializations instantiation dependent (#100392)
Cherry pick of 55ea36002bd364518c20b3ce282640c920697bf7
>From c7377a35fc99b537a5198335c5aabc5d142a3972 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski
Date: Tue, 6 Aug 2024 12:40:44 -0400
Subject: [PATCH] [Clang][Sema] Make UnresolvedLookupExprs in class scope
explicit specializations instantiation dependent (#100392)
A class member named by an expression in a member function that may instantiate
to a static _or_ non-static member is represented by a `UnresolvedLookupExpr`
in order to defer the implicit transformation to a class member access
expression until instantiation. Since `ASTContext::getDecltypeType` only
creates a `DecltypeType` that has a `DependentDecltypeType` as its canonical
type when the operand is instantiation dependent, and since we do not transform
types unless they are instantiation dependent, we need to mark the
`UnresolvedLookupExpr` as instantiation dependent in order to correctly build a
`DecltypeType` using the expression as its operand with a
`DependentDecltypeType` canonical type. Fixes #99873.
(cherry picked from commit 55ea36002bd364518c20b3ce282640c920697bf7)
---
clang/include/clang/AST/ExprCXX.h | 7 ---
clang/lib/AST/ASTImporter.cpp | 6 --
clang/lib/AST/ExprCXX.cpp | 19 +++
clang/lib/Sema/SemaCoroutine.cpp | 3 ++-
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/lib/Sema/SemaDeclCXX.cpp| 2 +-
clang/lib/Sema/SemaExpr.cpp | 2 +-
clang/lib/Sema/SemaExprMember.cpp | 3 ++-
clang/lib/Sema/SemaOpenMP.cpp | 6 --
clang/lib/Sema/SemaOverload.cpp | 6 +++---
clang/lib/Sema/SemaTemplate.cpp | 3 ++-
clang/lib/Sema/TreeTransform.h| 8
clang/test/SemaCXX/decltype.cpp | 25 +
13 files changed, 64 insertions(+), 28 deletions(-)
diff --git a/clang/include/clang/AST/ExprCXX.h
b/clang/include/clang/AST/ExprCXX.h
index c2feac525c1ea6..45cfd7bfb7f92c 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3229,7 +3229,7 @@ class UnresolvedLookupExpr final
const DeclarationNameInfo &NameInfo, bool RequiresADL,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End,
- bool KnownDependent);
+ bool KnownDependent, bool KnownInstantiationDependent);
UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
bool HasTemplateKWAndArgsInfo);
@@ -3248,7 +3248,7 @@ class UnresolvedLookupExpr final
NestedNameSpecifierLoc QualifierLoc,
const DeclarationNameInfo &NameInfo, bool RequiresADL,
UnresolvedSetIterator Begin, UnresolvedSetIterator End,
- bool KnownDependent);
+ bool KnownDependent, bool KnownInstantiationDependent);
// After canonicalization, there may be dependent template arguments in
// CanonicalConverted But none of Args is dependent. When any of
@@ -3258,7 +3258,8 @@ class UnresolvedLookupExpr final
NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
const DeclarationNameInfo &NameInfo, bool RequiresADL,
const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
- UnresolvedSetIterator End, bool KnownDependent);
+ UnresolvedSetIterator End, bool KnownDependent,
+ bool KnownInstantiationDependent);
static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
unsigned NumResults,
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 08ef09d353afc9..e95992b99f7e9d 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8578,13 +8578,15 @@
ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
return UnresolvedLookupExpr::Create(
Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
*ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
-ToDecls.begin(), ToDecls.end(), KnownDependent);
+ToDecls.begin(), ToDecls.end(), KnownDependent,
+/*KnownInstantiationDependent=*/E->isInstantiationDependent());
}
return UnresolvedLookupExpr::Create(
Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
- /*KnownDependent=*/E->isTypeDependent());
+ /*KnownDependent=*/E->isTypeDependent(),
+ /*KnownInstantiationDependent=*/E->isInstantiationDependent());
}
ExpectedStmt
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 8d2a1b5611ccc6..45e2badf2ddd4a 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -402,10 +402,11 @@ UnresolvedLookupExpr::U
[llvm-branch-commits] [clang] Cherry pick: [Clang][Sema] Make UnresolvedLookupExprs in class scope explicit spec… (PR #102514)
https://github.com/nga888 milestoned https://github.com/llvm/llvm-project/pull/102514 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] Cherry pick: [Clang][Sema] Make UnresolvedLookupExprs in class scope explicit spec… (PR #102514)
https://github.com/nga888 edited https://github.com/llvm/llvm-project/pull/102514 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] release/18.x: [Support] Fix color handling in formatted_raw_ostream (#86700) (PR #86940)
nga888 wrote: > Hi @nga888 (or anyone else). If you would like to add a note about this fix > in the release notes (completely optional). Please reply to this comment with > a one or two sentence description of the fix. Fix color handling for buffered formatted_raw_ostream which allows the unbuffered workaround in llvm-objdump to be removed, restoring the performance of llvm-objdump disassembly when the output is redirected. https://github.com/llvm/llvm-project/pull/86940 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Backport #164873 and #166067 to `release/21.x` (PR #166409)
https://github.com/nga888 closed https://github.com/llvm/llvm-project/pull/166409 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Backport #164873 and #166067 to `release/21.x` (PR #166409)
nga888 wrote: > Hi @nga888, at this point in the release cycle we are only accepting fixes > for regressions or major bug fixes. This only seems to be a performance > improvement in a very specific scenario, so it does not seem to meet the bar, > plus I am unsure how risky taking these two changes might be for the release > branch. Can you provide some detail on why you feel we should incorporate > these changes into the release branch at this time? Yes, I forgot that these "final" point releases are only for regressions or bug fixes. Both these changes are NFC but you're right they don't really meet the criteria. Will have to wait for the improvement in the next release. Thanks! https://github.com/llvm/llvm-project/pull/166409 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] Backport #164873 and #166067 to `release/21.x` (PR #166409)
https://github.com/nga888 created
https://github.com/llvm/llvm-project/pull/166409
Backport the following commits to `release/21.x`:
0341fb63: [ThinLTO] Avoid creating map entries on lookup (NFCI) (#164873)
564c3de6: [ThinLTO][NFC] Improve performance of `addThinLTO` (#166067)
>From 0b5b2ad793aa4384b58eb9c0fd917499f50a44a4 Mon Sep 17 00:00:00 2001
From: Teresa Johnson
Date: Thu, 23 Oct 2025 19:40:42 -0700
Subject: [PATCH 1/2] [ThinLTO] Avoid creating map entries on lookup (NFCI)
(#164873)
We could inadvertently create new entries in the PrevailingModuleForGUID
map during lookup, which was always using operator[]. In most cases we
will have one for external symbols, but not in cases where the
prevailing copy is in a native object. Or if this happened to be looked
up for a local.
Make the map private and create and use accessors.
(cherry picked from commit 0341fb63f2abe2ce98434c45fef8826718f9198c)
---
llvm/include/llvm/LTO/LTO.h | 13 +
llvm/lib/LTO/LTO.cpp| 12 ++--
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h
index d8e632b5a49d5..d5e7d2ede7e9b 100644
--- a/llvm/include/llvm/LTO/LTO.h
+++ b/llvm/include/llvm/LTO/LTO.h
@@ -464,6 +464,19 @@ class LTO {
ModuleMapType ModuleMap;
// The bitcode modules to compile, if specified by the LTO Config.
std::optional ModulesToCompile;
+
+void setPrevailingModuleForGUID(GlobalValue::GUID GUID, StringRef Module) {
+ PrevailingModuleForGUID[GUID] = Module;
+}
+bool isPrevailingModuleForGUID(GlobalValue::GUID GUID,
+ StringRef Module) const {
+ auto It = PrevailingModuleForGUID.find(GUID);
+ return It != PrevailingModuleForGUID.end() && It->second == Module;
+}
+
+ private:
+// Make this private so all accesses must go through above accessor methods
+// to avoid inadvertently creating new entries on lookups.
DenseMap PrevailingModuleForGUID;
} ThinLTO;
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 73e79c08a56ca..523ece12d1666 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1045,15 +1045,15 @@ Error LTO::addThinLTO(BitcodeModule BM,
ArrayRef Syms,
GlobalValue::getGlobalIdentifier(Sym.getIRName(),
GlobalValue::ExternalLinkage, ""));
if (Res.Prevailing)
-ThinLTO.PrevailingModuleForGUID[GUID] = BM.getModuleIdentifier();
+ThinLTO.setPrevailingModuleForGUID(GUID, BM.getModuleIdentifier());
}
}
if (Error Err =
BM.readSummary(ThinLTO.CombinedIndex, BM.getModuleIdentifier(),
[&](GlobalValue::GUID GUID) {
- return ThinLTO.PrevailingModuleForGUID[GUID] ==
- BM.getModuleIdentifier();
+ return ThinLTO.isPrevailingModuleForGUID(
+ GUID, BM.getModuleIdentifier());
}))
return Err;
LLVM_DEBUG(dbgs() << "Module " << BM.getModuleIdentifier() << "\n");
@@ -1067,8 +1067,8 @@ Error LTO::addThinLTO(BitcodeModule BM,
ArrayRef Syms,
GlobalValue::getGlobalIdentifier(Sym.getIRName(),
GlobalValue::ExternalLinkage, ""));
if (Res.Prevailing) {
-assert(ThinLTO.PrevailingModuleForGUID[GUID] ==
- BM.getModuleIdentifier());
+assert(
+ThinLTO.isPrevailingModuleForGUID(GUID, BM.getModuleIdentifier()));
// For linker redefined symbols (via --wrap or --defsym) we want to
// switch the linkage to `weak` to prevent IPOs from happening.
@@ -1974,7 +1974,7 @@ Error LTO::runThinLTO(AddStreamFn AddStream, FileCache
Cache,
LocalWPDTargetsMap);
auto isPrevailing = [&](GlobalValue::GUID GUID, const GlobalValueSummary *S)
{
-return ThinLTO.PrevailingModuleForGUID[GUID] == S->modulePath();
+return ThinLTO.isPrevailingModuleForGUID(GUID, S->modulePath());
};
if (EnableMemProfContextDisambiguation) {
MemProfContextDisambiguation ContextDisambiguation;
>From 115ae08777c6022d8a148d0806d250c859313244 Mon Sep 17 00:00:00 2001
From: Andrew Ng
Date: Mon, 3 Nov 2025 11:10:44 +
Subject: [PATCH 2/2] [ThinLTO][NFC] Improve performance of `addThinLTO`
(#166067)
Avoid the construction of `GUID` when not required. This improves the
performance of a LLD `--thinlto-index-only` link of `clang` by ~4-5% on
both Windows and Linux.
(cherry picked from commit 564c3de67d20d578d05678b49045378fdcf5ccaa)
---
llvm/lib/LTO/LTO.cpp | 40 ++--
1 file changed, 18 insertions(+), 22 deletions(-)
diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index 523ece12d1666..3c6951d8ec5fe 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -1035,63 +1035,59 @@ Error LTO::linkRegularLTO(RegularLTOState::
[llvm-branch-commits] [llvm] Backport #164873 and #166067 to `release/21.x` (PR #166409)
https://github.com/nga888 milestoned https://github.com/llvm/llvm-project/pull/166409 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
