aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
diff options
context:
space:
mode:
authorVladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com>2023-06-19 16:42:05 +0200
committerVladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com>2023-06-19 16:42:43 +0200
commit66511b401042f28c74d2ded3aac76d19a53bd7c4 (patch)
treec8e755fe154051a38273ff6d9df808db9814a658 /llvm/lib/Bitcode/Reader/MetadataLoader.cpp
parentfa45f81ff7ea9fc2a2a40fea8dd7626ecc3a8dbb (diff)
downloadllvm-66511b401042f28c74d2ded3aac76d19a53bd7c4.zip
llvm-66511b401042f28c74d2ded3aac76d19a53bd7c4.tar.gz
llvm-66511b401042f28c74d2ded3aac76d19a53bd7c4.tar.bz2
[DebugMetadata][DwarfDebug] Support function-local types in lexical block scopes (4/7)
RFC https://discourse.llvm.org/t/rfc-dwarfdebug-fix-and-improve-handling-imported-entities-types-and-static-local-in-subprogram-and-lexical-block-scopes/68544 Similar to imported declarations, the patch tracks function-local types in DISubprogram's 'retainedNodes' field. DwarfDebug is adjusted in accordance with the aforementioned metadata change and provided a support of function-local types scoped within a lexical block. The patch assumes that DICompileUnit's 'enums field' no longer tracks local types and DwarfDebug would assert if any locally-scoped types get placed there. Authored-by: Kristina Bessonova <kbessonova@accesssoftek.com> Differential Revision: https://reviews.llvm.org/D144006 Depends on D144005
Diffstat (limited to 'llvm/lib/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/MetadataLoader.cpp87
1 files changed, 56 insertions, 31 deletions
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 0a9a806..321eae6 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -548,6 +548,8 @@ class MetadataLoader::MetadataLoaderImpl {
/// Move local imports from DICompileUnit's 'imports' field to
/// DISubprogram's retainedNodes.
+ /// Move fucntion-local enums from DICompileUnit's enums
+ /// to DISubprogram's retainedNodes.
void upgradeCULocals() {
if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu")) {
for (unsigned I = 0, E = CUNodes->getNumOperands(); I != E; ++I) {
@@ -555,48 +557,71 @@ class MetadataLoader::MetadataLoaderImpl {
if (!CU)
continue;
- if (auto *RawImported = CU->getRawImportedEntities()) {
- // Collect a set of imported entities to be moved.
- SetVector<Metadata *> EntitiesToRemove;
+ SetVector<Metadata *> MetadataToRemove;
+ // Collect imported entities to be moved.
+ if (CU->getRawImportedEntities()) {
for (Metadata *Op : CU->getImportedEntities()->operands()) {
auto *IE = cast<DIImportedEntity>(Op);
- if (auto *S = dyn_cast_or_null<DILocalScope>(IE->getScope())) {
- EntitiesToRemove.insert(IE);
+ if (dyn_cast_or_null<DILocalScope>(IE->getScope())) {
+ MetadataToRemove.insert(IE);
}
}
+ }
+ // Collect enums to be moved.
+ if (CU->getRawEnumTypes()) {
+ for (Metadata *Op : CU->getEnumTypes()->operands()) {
+ auto *Enum = cast<DICompositeType>(Op);
+ if (dyn_cast_or_null<DILocalScope>(Enum->getScope())) {
+ MetadataToRemove.insert(Enum);
+ }
+ }
+ }
- if (!EntitiesToRemove.empty()) {
- // Make a new list of CU's 'imports'.
- SmallVector<Metadata *> NewImports;
- for (Metadata *Op : CU->getImportedEntities()->operands()) {
- if (!EntitiesToRemove.contains(cast<DIImportedEntity>(Op))) {
+ if (!MetadataToRemove.empty()) {
+ // Make a new list of CU's 'imports'.
+ SmallVector<Metadata *> NewImports;
+ if (CU->getRawImportedEntities())
+ for (Metadata *Op : CU->getImportedEntities()->operands())
+ if (!MetadataToRemove.contains(Op))
NewImports.push_back(Op);
- }
- }
- // Find DISubprogram corresponding to each entity.
- std::map<DISubprogram *, SmallVector<Metadata *>> SPToEntities;
- for (auto *I : EntitiesToRemove) {
- auto *Entity = cast<DIImportedEntity>(I);
- if (auto *SP = findEnclosingSubprogram(
- cast<DILocalScope>(Entity->getScope()))) {
- SPToEntities[SP].push_back(Entity);
- }
+ // Make a new list of CU's 'enums'.
+ SmallVector<Metadata *> NewEnums;
+ if (CU->getRawEnumTypes())
+ for (Metadata *Op : CU->getEnumTypes()->operands())
+ if (!MetadataToRemove.contains(Op))
+ NewEnums.push_back(Op);
+
+ // Find DISubprogram corresponding to each entity.
+ std::map<DISubprogram *, SmallVector<Metadata *>> SPToEntities;
+ for (auto *I : MetadataToRemove) {
+ DILocalScope *Scope = nullptr;
+ if (auto *Entity = dyn_cast<DIImportedEntity>(I))
+ Scope = cast<DILocalScope>(Entity->getScope());
+ else if (auto *Enum = dyn_cast<DICompositeType>(I))
+ Scope = cast<DILocalScope>(Enum->getScope());
+
+ if (auto *SP = findEnclosingSubprogram(Scope)) {
+ SPToEntities[SP].push_back(I);
}
+ }
- // Update DISubprograms' retainedNodes.
- for (auto I = SPToEntities.begin(); I != SPToEntities.end(); ++I) {
- auto *SP = I->first;
- auto RetainedNodes = SP->getRetainedNodes();
- SmallVector<Metadata *> MDs(RetainedNodes.begin(),
- RetainedNodes.end());
- MDs.append(I->second);
- SP->replaceRetainedNodes(MDNode::get(Context, MDs));
- }
+ // Update DISubprograms' retainedNodes.
+ for (auto I = SPToEntities.begin(); I != SPToEntities.end(); ++I) {
+ auto *SP = I->first;
+ auto RetainedNodes = SP->getRetainedNodes();
+ SmallVector<Metadata *> MDs(RetainedNodes.begin(),
+ RetainedNodes.end());
+ MDs.append(I->second);
+ SP->replaceRetainedNodes(MDNode::get(Context, MDs));
+ }
- // Remove entities with local scope from CU.
+ // Remove entities with local scope from CU.
+ if (CU->getRawImportedEntities())
CU->replaceImportedEntities(MDTuple::get(Context, NewImports));
- }
+ // Remove enums with local scope from CU.
+ if (CU->getRawEnumTypes())
+ CU->replaceEnumTypes(MDTuple::get(Context, NewEnums));
}
}
}