[llvm] [IR] Do not track metadata uses of ConstantData (PR #223303)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 23:14:39 PDT 2026
================
@@ -551,56 +558,44 @@ void ValueAsMetadata::handleRAUW(Value *From, Value *To) {
assert(From != To && "Expected changed value");
assert(&From->getContext() == &To->getContext() && "Expected same context");
- LLVMContext &Context = From->getType()->getContext();
- auto &Store = Context.pImpl->ValuesAsMetadata;
+ auto &Store = From->getContext().pImpl->ValuesAsMetadata;
auto I = Store.find(From);
if (I == Store.end()) {
assert(!From->IsUsedByMD && "Expected From not to be used by metadata");
return;
}
- // Remove old entry from the map.
assert(From->IsUsedByMD && "Expected From to be used by metadata");
From->IsUsedByMD = false;
ValueAsMetadata *MD = I->second;
assert(MD && "Expected valid metadata");
assert(MD->getValue() == From && "Expected valid mapping");
Store.erase(I);
- if (isa<LocalAsMetadata>(MD)) {
- if (auto *C = dyn_cast<Constant>(To)) {
- // Local became a constant.
- MD->replaceAllUsesWith(ConstantAsMetadata::get(C));
- delete MD;
- return;
- }
- if (getLocalFunctionMetadata(From) && getLocalFunctionMetadata(To) &&
- getLocalFunctionMetadata(From) != getLocalFunctionMetadata(To)) {
- // DISubprogram changed.
- MD->replaceAllUsesWith(nullptr);
- delete MD;
- return;
- }
- } else if (!isa<Constant>(To)) {
- // Changed to function-local value.
- MD->replaceAllUsesWith(nullptr);
- delete MD;
+ // The uses of a ConstantData node are not tracked, so the node can only be
+ // retyped in place.
+ if (isa<ConstantData>(From)) {
----------------
MaskRay wrote:
The most common scenario is in `~Instruction() { ... ValueAsMetadata::handleRAUW(this, PoisonValue::get(getType())); }`
When an instruction referenced by `#dbg_value` is replaced with a PoisonValue (a ConstantData).
https://github.com/llvm/llvm-project/pull/223303
More information about the llvm-commits
mailing list