[llvm] a776740 - [DebugInfo] Correctly track metadata slots for DPValues (#76941)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 06:08:58 PST 2024


Author: Stephen Tozer
Date: 2024-01-05T14:08:53Z
New Revision: a776740d6296520b8bde156aa3f8d9ecb32cddd9

URL: https://github.com/llvm/llvm-project/commit/a776740d6296520b8bde156aa3f8d9ecb32cddd9
DIFF: https://github.com/llvm/llvm-project/commit/a776740d6296520b8bde156aa3f8d9ecb32cddd9.diff

LOG: [DebugInfo] Correctly track metadata slots for DPValues (#76941)

Currently, the AsmWriter can print DPValues, but does not consider them
when creating slots for metadata, which can result in erroneous output
where metadata is numbered incorrectly. This patch modifies the
ModuleSlotTracker to correctly track slots for metadata that appears in
DPValues.

Added: 
    

Modified: 
    llvm/lib/IR/AsmWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 95cdec722062e3..278cdfce411050 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -859,6 +859,9 @@ class SlotTracker : public AbstractSlotTrackerStorage {
 
   /// Add all of the metadata from an instruction.
   void processInstructionMetadata(const Instruction &I);
+
+  /// Add all of the metadata from an instruction.
+  void processDPValueMetadata(const DPValue &DPV);
 };
 
 } // end namespace llvm
@@ -1126,11 +1129,19 @@ void SlotTracker::processGlobalObjectMetadata(const GlobalObject &GO) {
 void SlotTracker::processFunctionMetadata(const Function &F) {
   processGlobalObjectMetadata(F);
   for (auto &BB : F) {
-    for (auto &I : BB)
+    for (auto &I : BB) {
+      for (const DPValue &DPV : I.getDbgValueRange())
+        processDPValueMetadata(DPV);
       processInstructionMetadata(I);
+    }
   }
 }
 
+void SlotTracker::processDPValueMetadata(const DPValue &DPV) {
+  CreateMetadataSlot(DPV.getVariable());
+  CreateMetadataSlot(DPV.getDebugLoc());
+}
+
 void SlotTracker::processInstructionMetadata(const Instruction &I) {
   // Process metadata used directly by intrinsics.
   if (const CallInst *CI = dyn_cast<CallInst>(&I))


        


More information about the llvm-commits mailing list