Copy metadata when value is RAUW'd. It is debatable whether this is the right approac...
authorDevang Patel <dpatel@apple.com>
Tue, 13 Oct 2009 17:00:54 +0000 (17:00 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 13 Oct 2009 17:00:54 +0000 (17:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83977 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Metadata.h
lib/VMCore/Metadata.cpp
lib/VMCore/Value.cpp

index e4414817ca0007f7117a1d266999bf3dc3ecff1b..dd79ac09a2dbfe98fce9e128471d7d8b7b5b08d0 100644 (file)
@@ -361,6 +361,7 @@ public:
   void ValueIsDeleted(const Instruction *Inst) {
     removeMDs(Inst);
   }
+  void ValueIsRAUWd(Value *V1, Value *V2);
 
   /// ValueIsCloned - This handler is used to update metadata store
   /// when In1 is cloned to create In2.
index 2f2345f55ef150f5888b069214391c96bba847bc..f3601cbdf5c97cb7b68f3f184add9270b426c286 100644 (file)
@@ -404,3 +404,15 @@ void MetadataContext::ValueIsCloned(const Instruction *In1, Instruction *In2) {
     if (MDNode *MD = dyn_cast_or_null<MDNode>(I->second))
       addMD(I->first, MD, In2);
 }
+
+/// ValueIsRAUWd - This handler is used when V1's all uses are replaced by
+/// V2.
+void MetadataContext::ValueIsRAUWd(Value *V1, Value *V2) {
+  Instruction *I1 = dyn_cast<Instruction>(V1);
+  Instruction *I2 = dyn_cast<Instruction>(V2);
+  if (!I1 || !I2)
+    return;
+
+  // FIXME : Give custom handlers a chance to override this.
+  ValueIsCloned(I1, I2);
+}
index 03b0e6f172e3561c505e746566ff20eab5f142b4..ba72af635cdcb5fa8154431ac25619fecab70afd 100644 (file)
@@ -309,6 +309,10 @@ void Value::uncheckedReplaceAllUsesWith(Value *New) {
   // Notify all ValueHandles (if present) that this value is going away.
   if (HasValueHandle)
     ValueHandleBase::ValueIsRAUWd(this, New);
+  if (HasMetadata) {
+    LLVMContext &Context = getContext();
+    Context.pImpl->TheMetadata.ValueIsRAUWd(this, New);
+  }
 
   while (!use_empty()) {
     Use &U = *UseList;