aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DIBuilder.cpp
diff options
context:
space:
mode:
authorVladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com>2023-06-08 17:36:30 +0200
committerVladislav Dzhidzhoev <vdzhidzhoev@accesssoftek.com>2023-06-08 17:36:30 +0200
commit7815166b476b4184a1171ef56eed35726c1ab132 (patch)
tree5d98fa24eb72fe97282136f8d0db8e29432d5e25 /llvm/lib/IR/DIBuilder.cpp
parent891b09a57737f3576dc2e9d2d26e0262d71c8e3e (diff)
downloadllvm-7815166b476b4184a1171ef56eed35726c1ab132.zip
llvm-7815166b476b4184a1171ef56eed35726c1ab132.tar.gz
llvm-7815166b476b4184a1171ef56eed35726c1ab132.tar.bz2
Revert "[DebugMetadata] Simplify handling subprogram's retainedNodes field. NFCI (1/7)"
This reverts commit 4418434c6de7a861e241ba2448ea4a12080cf08f. Reverted because it breaks tests of OCaml bindings.
Diffstat (limited to 'llvm/lib/IR/DIBuilder.cpp')
-rw-r--r--llvm/lib/IR/DIBuilder.cpp75
1 files changed, 47 insertions, 28 deletions
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 4fa61b8..1428ceb 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -52,11 +52,23 @@ void DIBuilder::trackIfUnresolved(MDNode *N) {
}
void DIBuilder::finalizeSubprogram(DISubprogram *SP) {
- auto PN = SubprogramTrackedNodes.find(SP);
- if (PN != SubprogramTrackedNodes.end())
- SP->replaceRetainedNodes(
- MDTuple::get(VMContext, SmallVector<Metadata *, 16>(PN->second.begin(),
- PN->second.end())));
+ 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());
}
void DIBuilder::finalize() {
@@ -754,20 +766,26 @@ DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
static DILocalVariable *createLocalVariable(
LLVMContext &VMContext,
- SmallVectorImpl<TrackingMDNodeRef> &PreservedNodes,
- DIScope *Context, StringRef Name, unsigned ArgNo, DIFile *File,
+ DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
+ DIScope *Scope, 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)?
- auto *Scope = cast<DILocalScope>(Context);
- auto *Node = DILocalVariable::get(VMContext, Scope, Name, File, LineNo, Ty,
- ArgNo, Flags, AlignInBits, Annotations);
+ DIScope *Context = getNonCompileUnitScope(Scope);
+
+ auto *Node = DILocalVariable::get(
+ VMContext, cast_or_null<DILocalScope>(Context), 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.
- PreservedNodes.emplace_back(Node);
+ DISubprogram *Fn = getDISubprogram(Scope);
+ assert(Fn && "Missing subprogram for local variable");
+ PreservedVariables[Fn].emplace_back(Node);
}
return Node;
}
@@ -777,11 +795,9 @@ DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
DIType *Ty, bool AlwaysPreserve,
DINode::DIFlags Flags,
uint32_t 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);
+ return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
+ /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
+ Flags, AlignInBits);
}
DILocalVariable *DIBuilder::createParameterVariable(
@@ -789,23 +805,25 @@ DILocalVariable *DIBuilder::createParameterVariable(
unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
DINodeArray Annotations) {
assert(ArgNo && "Expected non-zero argument number for parameter");
- 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);
+ return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
+ File, LineNo, Ty, AlwaysPreserve, Flags,
+ /*AlignInBits=*/0, Annotations);
}
-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);
+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);
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.
- getSubprogramNodesTrackingVector(Scope).emplace_back(Node);
+ DISubprogram *Fn = getDISubprogram(Scope);
+ assert(Fn && "Missing subprogram for label");
+ PreservedLabels[Fn].emplace_back(Node);
}
return Node;
}
@@ -832,8 +850,9 @@ 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, nullptr,
- ThrownTypes, Annotations, TargetFuncName);
+ SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl,
+ MDTuple::getTemporary(VMContext, std::nullopt).release(), ThrownTypes,
+ Annotations, TargetFuncName);
if (IsDefinition)
AllSubprograms.push_back(Node);