================ @@ -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"); + } + + // FIXME: Improve the interface for types. + DenseMap<const MDString *, DICompositeType *> DITypeMap; + + /// Get an existing DISubprogram declaration with matching scope, linkage ---------------- chbessonova wrote:
The comment seems stale: declarations are now matched only by the scope’s identifier and the linkage name. https://github.com/llvm/llvm-project/pull/217042 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
