================ @@ -0,0 +1,79 @@ +//===- llvm/IR/DebugInfoODRUniquer.cpp - Debug Information Builder --------===// +// +// 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/IR/DebugInfoODRUniquer.h" +#include "llvm/IR/DebugInfoMetadata.h" + +using namespace llvm; + +DISubprogram *DebugInfoODRUniquer::getODRSubprogramDecl(DIScope *Scope, + StringRef LinkageName) { + // Only methods, which have a type scope, are eligable for ODR uniquing. + auto *CT = dyn_cast_or_null<DICompositeType>(Scope); + if (!CT || !CT->getRawIdentifier()) + return nullptr; + + auto R = + FnDecls.find_as(DISubprogramODRKey(CT->getIdentifier(), LinkageName)); + if (R == FnDecls.end()) + return nullptr; + + assert(!(*R)->isDefinition() && "definition unexpectedly ODR-uniqued"); + return *R; +} + +void DebugInfoODRUniquer::addSubprogramDecl(DISubprogram *SP) { + assert(!SP->isDefinition() && + "only expect declarations DISubprogram ODR uniquing"); + assert(!SP->isDistinct() && "expect declarations to be uniqued"); + + if (SP->getLinkageName().empty()) + return; + // Only methods, which have a type scope, are eligable for ODR uniquing. + auto *CT = dyn_cast_or_null<DICompositeType>(SP->getScope()); + if (!CT || !CT->getRawIdentifier()) + return; + + FnDecls.insert(SP); +} + +void DebugInfoODRUniquer::addUnresolvedODRSubprogramDecl(TempDISubprogram SP) { + assert(!SP->isDefinition() && "expected declarations only"); + if (SP->getLinkageName().empty()) + return; + PendingFnDecls.push_back(std::move(SP)); +} + +void DebugInfoODRUniquer::finalizeUnresolvedSubprogramDecls() { + for (auto It = PendingFnDecls.begin(), End = PendingFnDecls.end(); It != End; + ++It) { + TempDISubprogram SP = std::move(*It); + if (MDNode *Scope = dyn_cast_or_null<MDNode>(SP->getRawScope())) { + assert(!SP->getLinkageName().empty() && "expcted linkage name"); ---------------- chbessonova wrote:
typo: expcted -> expected https://github.com/llvm/llvm-project/pull/217042 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
