Skip to content

[ByteCode] Avoid repeated hash lookups (NFC) #132141

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@kazutakahirata kazutakahirata requested a review from nikic March 20, 2025 03:39
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 20, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2025

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/132141.diff

1 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Program.cpp (+2-2)
diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp
index c33d7fd7a2dc5..665e87bb5d2c8 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -213,12 +213,12 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
   if (auto Idx =
           createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init)) {
     for (const Decl *P = VD; P; P = P->getPreviousDecl()) {
+      unsigned &PIdx = GlobalIndices[P];
       if (P != VD) {
-        unsigned PIdx = GlobalIndices[P];
         if (Globals[PIdx]->block()->isExtern())
           Globals[PIdx] = Globals[*Idx];
       }
-      GlobalIndices[P] = *Idx;
+      PIdx = *Idx;
     }
     return *Idx;
   }

@kazutakahirata kazutakahirata merged commit c38ef58 into llvm:main Mar 20, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_clang_ByteCode branch March 20, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants