[clang] [llvm] Disentangle DISubprogram ODR type method uniquing from metadata uniquing (PR #217042)
Kristina Bessonova via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 22 13:49:20 PDT 2026
================
@@ -0,0 +1,106 @@
+//===- llvm/IR/DebugInfoODRUniquer.h - Debug info metadata ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines a class used to merge debug info for ODR types.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/Metadata.h"
+
+namespace llvm {
+class MDString;
+class Metadata;
+class DICompositeType;
+
+/// Dense set/map find_as key for use alongside DISubprogramODRInfo to
+/// merge function declarations of ODR types.
+struct DISubprogramODRKey {
+ StringRef ScopeIdentifier;
+ StringRef LinkageName;
+
+ DISubprogramODRKey(StringRef ScopeIdentifier, StringRef LinkageName)
+ : ScopeIdentifier(ScopeIdentifier), LinkageName(LinkageName) {}
+
+ DISubprogramODRKey(const DISubprogram *SP) {
+ auto *CT = dyn_cast_or_null<DICompositeType>(SP->getRawScope());
+ ScopeIdentifier = CT ? CT->getIdentifier() : StringRef();
+ LinkageName = SP->getLinkageName();
+ }
+
+ static bool isEqual(const DISubprogramODRKey &LHS, const DISubprogram *RHS) {
+ StringRef RHSIdentifier;
+ if (auto *CT = dyn_cast_or_null<DICompositeType>(RHS->getRawScope()))
+ RHSIdentifier = CT->getIdentifier();
+
+ return LHS.LinkageName == RHS->getLinkageName() &&
+ LHS.ScopeIdentifier == RHSIdentifier;
+ }
+
+ static bool isEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
+ assert(!LHS->isDefinition() && !RHS->isDefinition());
+ return isEqual(DISubprogramODRKey(LHS), RHS);
+ }
+};
+
+/// Dense set/map info to merge function declarations of ODR types.
+struct DISubprogramODRInfo {
+ static unsigned getHashValue(const DISubprogramODRKey &SP) {
+ return hash_combine(SP.ScopeIdentifier, SP.LinkageName);
+ }
+
+ static bool isEqual(const DISubprogramODRKey &LHS, const DISubprogram *RHS) {
+ return DISubprogramODRKey::isEqual(LHS, RHS);
+ }
+
+ static bool isEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
+ assert(!LHS->isDefinition() && !RHS->isDefinition());
+ return DISubprogramODRKey::isEqual(DISubprogramODRKey(LHS), RHS);
+ }
+};
+
+class DebugInfoODRUniquer {
+ /// Function declarations keyed by DISubprogramODRKey to unique on a subset
+ /// of fields, rather than the built-in metadata uniquing which requires
+ /// full structural equality.
+ DenseSet<DISubprogram *, DISubprogramODRInfo> FnDecls;
+
+ /// Function declarations that cannot be ODR-uniqued yet due to a temporary
+ /// scope operand.
+ SmallVector<TempDISubprogram> PendingFnDecls;
+
+public:
+ ~DebugInfoODRUniquer() {
+ assert(PendingFnDecls.empty() &&
+ "Unexpected unresolved maybe-ODR-unqiue DISubprograms");
----------------
chbessonova wrote:
typo: unqiue -> unique
https://github.com/llvm/llvm-project/pull/217042
More information about the cfe-commits
mailing list