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

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 4 03:24:42 PST 2024


https://github.com/SLTozer created https://github.com/llvm/llvm-project/pull/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.

>From 2fa90885de389a2ec4e5bc0922f87b7b1af31e35 Mon Sep 17 00:00:00 2001
From: Stephen Tozer <Stephen.Tozer at Sony.com>
Date: Thu, 4 Jan 2024 11:20:33 +0000
Subject: [PATCH] [DebugInfo] Correctly track metadata slots for DPValues

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.
---
 llvm/lib/IR/AsmWriter.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

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