diff options
author | Stephen Tozer <Stephen.Tozer@Sony.com> | 2023-11-17 17:52:24 +0000 |
---|---|---|
committer | Stephen Tozer <Stephen.Tozer@Sony.com> | 2023-11-17 17:55:41 +0000 |
commit | f99a02005970cdcb0aad0de80fa4e5b546c6546b (patch) | |
tree | 100118629abadf627aee772fd0deedfdce9191e8 /llvm/lib/IR/DebugInfoMetadata.cpp | |
parent | e2fb816c4f0286ddf8b1030148a343d5efc14e01 (diff) | |
download | llvm-f99a02005970cdcb0aad0de80fa4e5b546c6546b.zip llvm-f99a02005970cdcb0aad0de80fa4e5b546c6546b.tar.gz llvm-f99a02005970cdcb0aad0de80fa4e5b546c6546b.tar.bz2 |
Reapply "[DebugInfo] Make DIArgList inherit from Metadata and always unique"
This reverts commit 0fd5dc94380d5fe666dc6c603b4bb782cef743e7.
The original commit removed DIArgLists from being in an MDNode map, but did
not insert a new `delete` in the LLVMContextImpl destructor. This
reapply adds that call to delete, preventing a memory leak.
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 62 |
1 files changed, 27 insertions, 35 deletions
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index 927aefb..c507346 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -2115,11 +2115,14 @@ DIMacroFile *DIMacroFile::getImpl(LLVMContext &Context, unsigned MIType, DEFINE_GETIMPL_STORE(DIMacroFile, (MIType, Line), Ops); } -DIArgList *DIArgList::getImpl(LLVMContext &Context, - ArrayRef<ValueAsMetadata *> Args, - StorageType Storage, bool ShouldCreate) { - DEFINE_GETIMPL_LOOKUP(DIArgList, (Args)); - DEFINE_GETIMPL_STORE_NO_OPS(DIArgList, (Args)); +DIArgList *DIArgList::get(LLVMContext &Context, + ArrayRef<ValueAsMetadata *> Args) { + auto ExistingIt = Context.pImpl->DIArgLists.find_as(DIArgListKeyInfo(Args)); + if (ExistingIt != Context.pImpl->DIArgLists.end()) + return *ExistingIt; + DIArgList *NewArgList = new DIArgList(Context, Args); + Context.pImpl->DIArgLists.insert(NewArgList); + return NewArgList; } void DIArgList::handleChangedOperand(void *Ref, Metadata *New) { @@ -2127,12 +2130,9 @@ void DIArgList::handleChangedOperand(void *Ref, Metadata *New) { assert((!New || isa<ValueAsMetadata>(New)) && "DIArgList must be passed a ValueAsMetadata"); untrack(); - bool Uniq = isUniqued(); - if (Uniq) { - // We need to update the uniqueness once the Args are updated since they - // form the key to the DIArgLists store. - eraseFromStore(); - } + // We need to update the set storage once the Args are updated since they + // form the key to the DIArgLists store. + getContext().pImpl->DIArgLists.erase(this); ValueAsMetadata *NewVM = cast_or_null<ValueAsMetadata>(New); for (ValueAsMetadata *&VM : Args) { if (&VM == OldVMPtr) { @@ -2142,28 +2142,19 @@ void DIArgList::handleChangedOperand(void *Ref, Metadata *New) { VM = ValueAsMetadata::get(PoisonValue::get(VM->getValue()->getType())); } } - if (Uniq) { - // In the RemoveDIs project (eliminating debug-info-intrinsics), DIArgLists - // can be referred to by DebugValueUser objects, which necessitates them - // being unique and replaceable metadata. This causes a slight - // performance regression that's to be avoided during the early stages of - // the RemoveDIs prototype, see D154080. -#ifdef EXPERIMENTAL_DEBUGINFO_ITERATORS - MDNode *UniqueArgList = uniquify(); - if (UniqueArgList != this) { - replaceAllUsesWith(UniqueArgList); - // Clear this here so we don't try to untrack in the destructor. - Args.clear(); - delete this; - return; - } -#else - // Otherwise, don't fully unique, become distinct instead. See D108968, - // there's a latent bug that presents here as nondeterminism otherwise. - if (uniquify() != this) - storeDistinctInContext(); -#endif + // We've changed the contents of this DIArgList, and the set storage may + // already contain a DIArgList with our new set of args; if it does, then we + // must RAUW this with the existing DIArgList, otherwise we simply insert this + // back into the set storage. + DIArgList *ExistingArgList = getUniqued(getContext().pImpl->DIArgLists, this); + if (ExistingArgList) { + replaceAllUsesWith(ExistingArgList); + // Clear this here so we don't try to untrack in the destructor. + Args.clear(); + delete this; + return; } + getContext().pImpl->DIArgLists.insert(this); track(); } void DIArgList::track() { @@ -2176,8 +2167,9 @@ void DIArgList::untrack() { if (VAM) MetadataTracking::untrack(&VAM, *VAM); } -void DIArgList::dropAllReferences() { - untrack(); +void DIArgList::dropAllReferences(bool Untrack) { + if (Untrack) + untrack(); Args.clear(); - MDNode::dropAllReferences(); + ReplaceableMetadataImpl::resolveAllUses(/* ResolveUsers */ false); } |