https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/111227
None >From 364f8e5778d8dd587ee8b58104edd931c4b9d336 Mon Sep 17 00:00:00 2001 From: Kazu Hirata <k...@google.com> Date: Fri, 4 Oct 2024 07:59:14 -0700 Subject: [PATCH] [Sema] Avoid repeated hash lookups (NFC) --- clang/lib/Sema/SemaOpenMP.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 8615da4b044a82..74ab52106e3234 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -1405,10 +1405,9 @@ const Expr *DSAStackTy::addUniqueAligned(const ValueDecl *D, assert(!isStackEmpty() && "Data sharing attributes stack is empty"); D = getCanonicalDecl(D); SharingMapTy &StackElem = getTopOfStack(); - auto It = StackElem.AlignedMap.find(D); - if (It == StackElem.AlignedMap.end()) { + auto [It, Inserted] = StackElem.AlignedMap.try_emplace(D, NewDE); + if (Inserted) { assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); - StackElem.AlignedMap[D] = NewDE; return nullptr; } assert(It->second && "Unexpected nullptr expr in the aligned map"); @@ -1420,10 +1419,9 @@ const Expr *DSAStackTy::addUniqueNontemporal(const ValueDecl *D, assert(!isStackEmpty() && "Data sharing attributes stack is empty"); D = getCanonicalDecl(D); SharingMapTy &StackElem = getTopOfStack(); - auto It = StackElem.NontemporalMap.find(D); - if (It == StackElem.NontemporalMap.end()) { + auto [It, Inserted] = StackElem.NontemporalMap.try_emplace(D, NewDE); + if (Inserted) { assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); - StackElem.NontemporalMap[D] = NewDE; return nullptr; } assert(It->second && "Unexpected nullptr expr in the aligned map"); @@ -21650,9 +21648,7 @@ SemaOpenMP::ActOnOpenMPDeclareReductionDirectiveStart( while (Filter.hasNext()) { auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); if (InCompoundScope) { - auto I = UsedAsPrevious.find(PrevDecl); - if (I == UsedAsPrevious.end()) - UsedAsPrevious[PrevDecl] = false; + UsedAsPrevious.try_emplace(PrevDecl, false); if (OMPDeclareReductionDecl *D = PrevDecl->getPrevDeclInScope()) UsedAsPrevious[D] = true; } @@ -21906,9 +21902,7 @@ SemaOpenMP::DeclGroupPtrTy SemaOpenMP::ActOnOpenMPDeclareMapperDirective( while (Filter.hasNext()) { auto *PrevDecl = cast<OMPDeclareMapperDecl>(Filter.next()); if (InCompoundScope) { - auto I = UsedAsPrevious.find(PrevDecl); - if (I == UsedAsPrevious.end()) - UsedAsPrevious[PrevDecl] = false; + UsedAsPrevious.try_emplace(PrevDecl, false); if (OMPDeclareMapperDecl *D = PrevDecl->getPrevDeclInScope()) UsedAsPrevious[D] = true; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits