[llvm] [IR] Allow type change in ValueAsMetadata::handleRAUW (PR #76969)
Jannik Silvanus via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 4 08:12:24 PST 2024
https://github.com/jasilvanus created https://github.com/llvm/llvm-project/pull/76969
`ValueAsMetadata::handleRAUW` is a mechanism to replace all metadata referring to one value by a different value.
Relax an assert that used to enforce the old and new value to have the same type.
This seems to be a sanity plausibility assert only, as the implementation actually supports mismatching types.
This is motivated by a downstream mechanism where we use poison ValueAsMetadata values to annotate pointee types of opaque pointer function arguments.
When replacing one type with a different one to work around DXIL vs LLVM incompatibilities, we need to update type annotations, and handleRAUW is more efficient than creating new MD nodes.
>From 100133e19932cf083b8a55f938bbb813b57fa28a Mon Sep 17 00:00:00 2001
From: Jannik Silvanus <jannik.silvanus at amd.com>
Date: Thu, 4 Jan 2024 16:58:06 +0100
Subject: [PATCH] [IR] Allow type change in ValueAsMetadata::handleRAUW
ValueAsMetadata::handleRAUW is a mechanism to replace all metadata
referring to one value by a different value.
Relax an assert that used to enforce the old and new value
to have the same type.
This seems to be a sanity checking assert only, and the implementation
actually supports mismatching types.
This is motivated by a downstream mechanism where we use poison
ValueAsMetadata values to annotate pointee types of opaque pointer
function arguments.
When replacing one type with a different one to work around DXIL
vs LLVM incompatibilities, we need to update type annotations,
and handleRAUW is more efficient than creating new MD nodes.
---
llvm/lib/IR/Metadata.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 515893d079b8cb..bdfbd8829186d9 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -503,7 +503,7 @@ void ValueAsMetadata::handleRAUW(Value *From, Value *To) {
assert(From && "Expected valid value");
assert(To && "Expected valid value");
assert(From != To && "Expected changed value");
- assert(From->getType() == To->getType() && "Unexpected type change");
+ assert(&From->getContext() == &To->getContext() && "Expected same context");
LLVMContext &Context = From->getType()->getContext();
auto &Store = Context.pImpl->ValuesAsMetadata;
More information about the llvm-commits
mailing list