[PATCH] D136949: [Debugify] Accumulate the number of variables in debugify metadata

Anton Sidorenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 07:41:06 PDT 2022


asi-sc updated this revision to Diff 471549.
asi-sc added a comment.

Erase old debugify metadata before revisiting the module


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136949/new/

https://reviews.llvm.org/D136949

Files:
  llvm/lib/CodeGen/MachineDebugify.cpp


Index: llvm/lib/CodeGen/MachineDebugify.cpp
===================================================================
--- llvm/lib/CodeGen/MachineDebugify.cpp
+++ llvm/lib/CodeGen/MachineDebugify.cpp
@@ -153,10 +153,15 @@
       NMD->setOperand(Idx, MDNode::get(Ctx, ValueAsMetadata::getConstant(
                                                 ConstantInt::get(Int32Ty, N))));
     };
+    auto getDebugifyOperand = [&](unsigned Idx) {
+      return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
+          ->getZExtValue();
+    };
     // Set number of lines.
     setDebugifyOperand(0, NextLine - 1);
     // Set number of variables.
-    setDebugifyOperand(1, VarSet.size());
+    auto OldNumVars = getDebugifyOperand(1);
+    setDebugifyOperand(1, OldNumVars + VarSet.size());
   }
 
   return true;
@@ -166,6 +171,9 @@
 /// legacy module pass manager.
 struct DebugifyMachineModule : public ModulePass {
   bool runOnModule(Module &M) override {
+    // We will insert new debugify metadata, so erasing the old one.
+    if (auto *NMD = M.getNamedMetadata("llvm.mir.debugify"))
+      M.eraseNamedMetadata(NMD);
     MachineModuleInfo &MMI =
         getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
     return applyDebugifyMetadata(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136949.471549.patch
Type: text/x-patch
Size: 1263 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221028/b6dd8d66/attachment.bin>


More information about the llvm-commits mailing list