[Assignment Tracking][9/*] Don't drop DIAssignID in dropUnknownNonDebugMetadata
authorOCHyams <orlando.hyams@sony.com>
Wed, 9 Nov 2022 10:49:55 +0000 (10:49 +0000)
committerOCHyams <orlando.hyams@sony.com>
Wed, 9 Nov 2022 10:49:55 +0000 (10:49 +0000)
The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

A DIAssignID attachment is debug metadata, so don't drop it.

Reviewed By: jmorse

Differential Revision: https://reviews.llvm.org/D133292

llvm/lib/IR/Metadata.cpp
llvm/unittests/IR/DebugInfoTest.cpp

index 5336902..bde8371 100644 (file)
@@ -1403,15 +1403,12 @@ void Instruction::dropUnknownNonDebugMetadata(ArrayRef<unsigned> KnownIDs) {
   if (!Value::hasMetadata())
     return; // Nothing to remove!
 
-  if (KnownIDs.empty()) {
-    // Just drop our entry at the store.
-    clearMetadata();
-    return;
-  }
-
   SmallSet<unsigned, 4> KnownSet;
   KnownSet.insert(KnownIDs.begin(), KnownIDs.end());
 
+  // A DIAssignID attachment is debug metadata, don't drop it.
+  KnownSet.insert(LLVMContext::MD_DIAssignID);
+
   auto &MetadataStore = getContext().pImpl->ValueMetadata;
   auto &Info = MetadataStore[this];
   assert(!Info.empty() && "bit out of sync with hash table");
index 970de06..bf676f9 100644 (file)
@@ -665,6 +665,17 @@ TEST(AssignmentTrackingTest, InstrMethods) {
     EXPECT_EQ(NewID0, NewID1);
     EXPECT_EQ(Markers[0]->getAssignID(), NewID0);
   }
+
+  // Test 5 - dropUnknownNonDebugMetadata.
+  //
+  // Input            store0->dropUnknownNonDebugMetadata()
+  // -----            -------------------------
+  // store0 !x        store0 !x
+  {
+    Stores[0]->dropUnknownNonDebugMetadata();
+    Metadata *NewID0 = Stores[0]->getMetadata(LLVMContext::MD_DIAssignID);
+    EXPECT_NE(NewID0, nullptr);
+  }
 }
 
 } // end namespace