From a1bbe8a4e2e50e7100dc17d9ddd1bfc3bfe44977 Mon Sep 17 00:00:00 2001 From: Anton Sidorenko Date: Fri, 28 Oct 2022 16:47:44 +0300 Subject: [Debugify] Accumulate the number of variables in debugify metadata When a module contains more than one function, we should update debugify metadata by increasing the number of variables in the function rather than overwritting it. Differential Revision: https://reviews.llvm.org/D136949 --- llvm/lib/CodeGen/MachineDebugify.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'llvm/lib/CodeGen/MachineDebugify.cpp') diff --git a/llvm/lib/CodeGen/MachineDebugify.cpp b/llvm/lib/CodeGen/MachineDebugify.cpp index b726a032ca18..adf1b51a950d 100644 --- a/llvm/lib/CodeGen/MachineDebugify.cpp +++ b/llvm/lib/CodeGen/MachineDebugify.cpp @@ -153,10 +153,15 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI, NMD->setOperand(Idx, MDNode::get(Ctx, ValueAsMetadata::getConstant( ConstantInt::get(Int32Ty, N)))); }; + auto getDebugifyOperand = [&](unsigned Idx) { + return mdconst::extract(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 @@ bool applyDebugifyMetadataToMachineFunction(MachineModuleInfo &MMI, /// legacy module pass manager. struct DebugifyMachineModule : public ModulePass { bool runOnModule(Module &M) override { + // We will insert new debugify metadata, so erasing the old one. + assert(!M.getNamedMetadata("llvm.mir.debugify") && + "llvm.mir.debugify metadata already exists! Strip it first"); MachineModuleInfo &MMI = getAnalysis().getMMI(); return applyDebugifyMetadata( -- cgit v1.2.3