aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/DebugInfoMetadata.cpp
diff options
context:
space:
mode:
authorStephen Tozer <stephen.tozer@sony.com>2023-11-17 14:04:54 +0000
committerGitHub <noreply@github.com>2023-11-17 14:04:54 +0000
commite77af7e1b07ac648c026922e4a0b07e9af35f714 (patch)
treeaeb3a356b3541261c5423766766799826abffbcb /llvm/lib/IR/DebugInfoMetadata.cpp
parente5e71affb72178ccfedae2083c686999d9fa4941 (diff)
downloadllvm-e77af7e1b07ac648c026922e4a0b07e9af35f714.zip
llvm-e77af7e1b07ac648c026922e4a0b07e9af35f714.tar.gz
llvm-e77af7e1b07ac648c026922e4a0b07e9af35f714.tar.bz2
[DebugInfo] Make DIArgList inherit from Metadata and always unique (#72147)
This patch changes the `DIArgList` class's inheritance from `MDNode` to `Metadata, ReplaceableMetadataImpl`, and ensures that it is always unique, i.e. a distinct DIArgList should never be produced. This should not result in any changes to IR or bitcode parsing and printing, as the format for DIArgList is unchanged, and the order in which it appears should also be identical. As a minor note, this patch also fixes a gap in the verifier, where the ValueAsMetadata operands to a DIArgList would not be visited.
Diffstat (limited to 'llvm/lib/IR/DebugInfoMetadata.cpp')
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp62
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);
}