Add copyMD to copy metadata from one instruction to another instruction.
authorDevang Patel <dpatel@apple.com>
Wed, 14 Oct 2009 17:02:49 +0000 (17:02 +0000)
committerDevang Patel <dpatel@apple.com>
Wed, 14 Oct 2009 17:02:49 +0000 (17:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84113 91177308-0d34-0410-b5e6-96231b3b80d8

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

index dd79ac09a2dbfe98fce9e128471d7d8b7b5b08d0..63c2da2e7dfd228cbaf9c2ebbd487ead5e793ad2 100644 (file)
@@ -351,6 +351,10 @@ public:
   /// removeMDs - Remove all metadata attached with an instruction.
   void removeMDs(const Instruction *Inst);
 
+  /// copyMD - If metadata is attached with Instruction In1 then attach
+  /// the same metadata to In2.
+  void copyMD(Instruction *In1, Instruction *In2);
+
   /// getHandlerNames - Get handler names. This is used by bitcode
   /// writer.
   const StringMap<unsigned> *getHandlerNames();
index f3601cbdf5c97cb7b68f3f184add9270b426c286..110c5e38fac3da48b1c7224bdd9c741a7fd30d72 100644 (file)
@@ -359,6 +359,20 @@ void MetadataContext::removeMDs(const Instruction *Inst) {
   MetadataStore.erase(I);
 }
 
+/// copyMD - If metadata is attached with Instruction In1 then attach
+/// the same metadata to In2.
+void MetadataContext::copyMD(Instruction *In1, Instruction *In2) {
+  assert (In1 && In2 && "Invalid instruction!");
+   MDStoreTy::iterator I = MetadataStore.find(In1);
+  if (I == MetadataStore.end())
+    return;
+
+  MDMapTy &In1Info = I->second;
+  MDMapTy In2Info;
+  for (MDMapTy::iterator I = In1Info.begin(), E = In1Info.end(); I != E; ++I)
+    if (MDNode *MD = dyn_cast_or_null<MDNode>(I->second))
+      addMD(I->first, MD, In2);
+}
 
 /// getMD - Get the metadata of given kind attached with an Instruction.
 /// If the metadata is not found then return 0.
@@ -416,3 +430,4 @@ void MetadataContext::ValueIsRAUWd(Value *V1, Value *V2) {
   // FIXME : Give custom handlers a chance to override this.
   ValueIsCloned(I1, I2);
 }
+