[llvm] [DebugInfo][RemoveDIs] Support finding DPValues as well as dbg.values in findDbgValues (PR #71952)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 18 15:26:42 PST 2023


================
@@ -78,31 +80,53 @@ static void findDbgIntrinsics(SmallVectorImpl<IntrinsicT *> &Result, Value *V) {
   // V will also appear twice in a dbg.assign if its used in the both the value
   // and address components.
   SmallPtrSet<IntrinsicT *, 4> EncounteredIntrinsics;
+  SmallPtrSet<DPValue *, 4> EncounteredDPValues;
 
   /// Append IntrinsicT users of MetadataAsValue(MD).
-  auto AppendUsers = [&Ctx, &EncounteredIntrinsics, &Result](Metadata *MD) {
+  auto AppendUsers = [&Ctx, &EncounteredIntrinsics, &Result,
+                      DPValues](Metadata *MD) {
     if (auto *MDV = MetadataAsValue::getIfExists(Ctx, MD)) {
       for (User *U : MDV->users())
         if (IntrinsicT *DVI = dyn_cast<IntrinsicT>(U))
           if (EncounteredIntrinsics.insert(DVI).second)
             Result.push_back(DVI);
     }
+    if (!DPValues)
+      return;
+    // Get DPValues that use this as a single value.
+    if (LocalAsMetadata *L = dyn_cast<LocalAsMetadata>(MD)) {
+      for (DPValue *DPV : L->getAllDPValueUsers()) {
+        if (DPV->getType() == DPValue::LocationType::Value)
+          DPValues->push_back(DPV);
+      }
+    }
   };
 
   if (auto *L = LocalAsMetadata::getIfExists(V)) {
     AppendUsers(L);
-    for (Metadata *AL : L->getAllArgListUsers())
+    for (Metadata *AL : L->getAllArgListUsers()) {
       AppendUsers(AL);
+      if (!DPValues)
+        continue;
+      DIArgList *DI = cast<DIArgList>(AL);
+      if (auto *Replaceable = DI->getReplaceableUses()) {
+        for (DPValue *DPV : Replaceable->getAllDPValueUsers())
+          if (DPV->getType() == DPValue::LocationType::Value)
----------------
jmorse wrote:

Hhhrrmmm. This is awkward because the intrinsics have an inherent hierarchy due to the instruction hierachy, i.e. DbgInfoIntrinsic -> DbgValueInst -> DbgAssignInst. We haven't yet created that for DPValues because we're focusing only on dbg.value replacement for the moment... but conceptually we'll end up replicating that hierarchy in the future. I'd prefer to wait until we implement that as it should line up with the instruction hierarchy perfectly (TM).  

https://github.com/llvm/llvm-project/pull/71952


More information about the llvm-commits mailing list