diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2025-05-06 17:23:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-06 17:23:59 +0200 |
commit | 51a3bd919d68a8fb1b026377d6e86b1523d37433 (patch) | |
tree | d91abafdcc9b31d730a28fbbc5d4a33b5f57d6ac /llvm/lib/IR/Value.cpp | |
parent | 87f312aad6ede636cd2de5d18f3058bf2caf5651 (diff) | |
download | llvm-51a3bd919d68a8fb1b026377d6e86b1523d37433.zip llvm-51a3bd919d68a8fb1b026377d6e86b1523d37433.tar.gz llvm-51a3bd919d68a8fb1b026377d6e86b1523d37433.tar.bz2 |
IR: Remove reference counts from ConstantData (#137314)
This is a follow up change to eliminating uselists for ConstantData.
In the previous revision, ConstantData had a replacement reference count
instead of a uselist. This reference count was misleading, and not useful
in the same way as it would be for another value. The references may not
have even been in the current module, since these are shared throughout
the LLVMContext.
This doesn't space leak any more than we previously did; nothing was
attempting to garbage collect unused constants.
Previously the use_empty, and hasNUses type of APIs were supported through
the reference count. These now behave as if the uses are always empty.
Ideally it would be illegal to inspect these, but this forces API complexity
into quite a few places. It may be doable to make it illegal to check these
counts, but I would like there to be a targeted fuzzing effort to make sure
every transform properly deals with a constant in every operand position.
All tests pass if I turn the hasNUses* and getNumUses queries into assertions,
only hasOneUse in particular appears to hit in some set of contexts. I've
added unit tests to ensure logical consistency between these cases
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 74a9605..d6cb65d 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -148,14 +148,18 @@ void Value::destroyValueName() { } bool Value::hasNUses(unsigned N) const { - if (!hasUseList()) - return Uses.Count == N; + if (!UseList) + return N == 0; + + // TODO: Disallow for ConstantData and remove !UseList check? return hasNItems(use_begin(), use_end(), N); } bool Value::hasNUsesOrMore(unsigned N) const { - if (!hasUseList()) - return Uses.Count >= N; + // TODO: Disallow for ConstantData and remove !UseList check? + if (!UseList) + return N == 0; + return hasNItemsOrMore(use_begin(), use_end(), N); } @@ -259,9 +263,9 @@ bool Value::isUsedInBasicBlock(const BasicBlock *BB) const { } unsigned Value::getNumUses() const { - if (!hasUseList()) - return Uses.Count; - + // TODO: Disallow for ConstantData and remove !UseList check? + if (!UseList) + return 0; return (unsigned)std::distance(use_begin(), use_end()); } @@ -522,7 +526,7 @@ void Value::doRAUW(Value *New, ReplaceMetadataUses ReplaceMetaUses) { ValueAsMetadata::handleRAUW(this, New); while (!materialized_use_empty()) { - Use &U = *Uses.List; + Use &U = *UseList; // Must handle Constants specially, we cannot call replaceUsesOfWith on a // constant because they are uniqued. if (auto *C = dyn_cast<Constant>(U.getUser())) { @@ -1102,12 +1106,12 @@ const Value *Value::DoPHITranslation(const BasicBlock *CurBB, LLVMContext &Value::getContext() const { return VTy->getContext(); } void Value::reverseUseList() { - if (!Uses.List || !Uses.List->Next || !hasUseList()) + if (!UseList || !UseList->Next) // No need to reverse 0 or 1 uses. return; - Use *Head = Uses.List; - Use *Current = Uses.List->Next; + Use *Head = UseList; + Use *Current = UseList->Next; Head->Next = nullptr; while (Current) { Use *Next = Current->Next; @@ -1116,8 +1120,8 @@ void Value::reverseUseList() { Head = Current; Current = Next; } - Uses.List = Head; - Head->Prev = &Uses.List; + UseList = Head; + Head->Prev = &UseList; } bool Value::isSwiftError() const { |