diff options
author | Vladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com> | 2023-06-12 16:01:18 +0200 |
---|---|---|
committer | Vladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com> | 2023-06-12 18:38:47 +0200 |
commit | ed506dd6cecd9653cf9202bfe195891a33482852 (patch) | |
tree | 43dc0a282e40806dbb8826daedbaac1c34fab39c /llvm/lib/IR/DIBuilder.cpp | |
parent | 11e5a0d290bac87f3290547fa2b0aaffc98a798e (diff) | |
download | llvm-ed506dd6cecd9653cf9202bfe195891a33482852.zip llvm-ed506dd6cecd9653cf9202bfe195891a33482852.tar.gz llvm-ed506dd6cecd9653cf9202bfe195891a33482852.tar.bz2 |
[DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/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
Currently, `retainedNodes` tracks function-local variables and labels.
To support function-local import, types and static variables (which are globals
in LLVM IR), subsequent patches use the same field. So this patch makes
preliminary refactoring of the code tracking local entities to apply future
functional changes lucidly and cleanly.
No functional changes intended.
Differential Revision: https://reviews.llvm.org/D143984
Authored-by: Kristina Bessonova <kbessonova@accesssoftek.com>
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r-- | llvm/lib/IR/DIBuilder.cpp | 75 |
1 files changed, 28 insertions, 47 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp index 1428ceb..4fa61b8 100644 --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -52,23 +52,11 @@ void DIBuilder::trackIfUnresolved(MDNode *N) { } void DIBuilder::finalizeSubprogram(DISubprogram *SP) { - MDTuple *Temp = SP->getRetainedNodes().get(); - if (!Temp || !Temp->isTemporary()) - return; - - SmallVector<Metadata *, 16> RetainedNodes; - - auto PV = PreservedVariables.find(SP); - if (PV != PreservedVariables.end()) - RetainedNodes.append(PV->second.begin(), PV->second.end()); - - auto PL = PreservedLabels.find(SP); - if (PL != PreservedLabels.end()) - RetainedNodes.append(PL->second.begin(), PL->second.end()); - - DINodeArray Node = getOrCreateArray(RetainedNodes); - - TempMDTuple(Temp)->replaceAllUsesWith(Node.get()); + auto PN = SubprogramTrackedNodes.find(SP); + if (PN != SubprogramTrackedNodes.end()) + SP->replaceRetainedNodes( + MDTuple::get(VMContext, SmallVector<Metadata *, 16>(PN->second.begin(), + PN->second.end()))); } void DIBuilder::finalize() { @@ -766,26 +754,20 @@ DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( static DILocalVariable *createLocalVariable( LLVMContext &VMContext, - DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, - DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, + SmallVectorImpl<TrackingMDNodeRef> &PreservedNodes, + DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, uint32_t AlignInBits, DINodeArray Annotations = nullptr) { - // FIXME: Why getNonCompileUnitScope()? - // FIXME: Why is "!Context" okay here? // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT // the only valid scopes)? - DIScope *Context = getNonCompileUnitScope(Scope); - - auto *Node = DILocalVariable::get( - VMContext, cast_or_null<DILocalScope>(Context), Name, File, LineNo, Ty, - ArgNo, Flags, AlignInBits, Annotations); + auto *Scope = cast<DILocalScope>(Context); + auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty, + ArgNo, Flags, AlignInBits, Annotations); if (AlwaysPreserve) { // The optimizer may remove local variables. If there is an interest // to preserve variable info in such situation then stash it in a // named mdnode. - DISubprogram *Fn = getDISubprogram(Scope); - assert(Fn && "Missing subprogram for local variable"); - PreservedVariables[Fn].emplace_back(Node); + PreservedNodes.emplace_back(Node); } return Node; } @@ -795,9 +777,11 @@ DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, uint32_t AlignInBits) { - return createLocalVariable(VMContext, PreservedVariables, Scope, Name, - /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, - Flags, AlignInBits); + assert(Scope && isa<DILocalScope>(Scope) && + "Unexpected scope for a local variable."); + return createLocalVariable( + VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, + /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, Flags, AlignInBits); } DILocalVariable *DIBuilder::createParameterVariable( @@ -805,25 +789,23 @@ DILocalVariable *DIBuilder::createParameterVariable( unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, DINodeArray Annotations) { assert(ArgNo && "Expected non-zero argument number for parameter"); - return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, - File, LineNo, Ty, AlwaysPreserve, Flags, - /*AlignInBits=*/0, Annotations); + assert(Scope && isa<DILocalScope>(Scope) && + "Unexpected scope for a local variable."); + return createLocalVariable( + VMContext, getSubprogramNodesTrackingVector(Scope), Scope, Name, ArgNo, + File, LineNo, Ty, AlwaysPreserve, Flags, /*AlignInBits=*/0, Annotations); } -DILabel *DIBuilder::createLabel(DIScope *Scope, StringRef Name, DIFile *File, - unsigned LineNo, bool AlwaysPreserve) { - DIScope *Context = getNonCompileUnitScope(Scope); - - auto *Node = DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), - Name, File, LineNo); +DILabel *DIBuilder::createLabel(DIScope *Context, StringRef Name, DIFile *File, + unsigned LineNo, bool AlwaysPreserve) { + auto *Scope = cast<DILocalScope>(Context); + auto *Node = DILabel::get(VMContext, Scope, Name, File, LineNo); if (AlwaysPreserve) { /// The optimizer may remove labels. If there is an interest /// to preserve label info in such situation then append it to /// the list of retained nodes of the DISubprogram. - DISubprogram *Fn = getDISubprogram(Scope); - assert(Fn && "Missing subprogram for label"); - PreservedLabels[Fn].emplace_back(Node); + getSubprogramNodesTrackingVector(Scope).emplace_back(Node); } return Node; } @@ -850,9 +832,8 @@ DISubprogram *DIBuilder::createFunction( auto *Node = getSubprogram( /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context), Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags, - SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, - MDTuple::getTemporary(VMContext, std::nullopt).release(), ThrownTypes, - Annotations, TargetFuncName); + SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, nullptr, + ThrownTypes, Annotations, TargetFuncName); if (IsDefinition) AllSubprograms.push_back(Node); |