@@ -87,6 +87,10 @@ bool llvm::applyDebugifyMetadata(
8787 return false ;
8888 }
8989
90+ bool NewDebugMode = M.IsNewDbgInfoFormat ;
91+ if (NewDebugMode)
92+ M.convertFromNewDbgValues ();
93+
9094 DIBuilder DIB (M);
9195 LLVMContext &Ctx = M.getContext ();
9296 auto *Int32Ty = Type::getInt32Ty (Ctx);
@@ -210,6 +214,9 @@ bool llvm::applyDebugifyMetadata(
210214 if (!M.getModuleFlag (DIVersionKey))
211215 M.addModuleFlag (Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
212216
217+ if (NewDebugMode)
218+ M.convertToNewDbgValues ();
219+
213220 return true ;
214221}
215222
@@ -304,6 +311,10 @@ bool llvm::collectDebugInfoMetadata(Module &M,
304311 return false ;
305312 }
306313
314+ bool NewDebugMode = M.IsNewDbgInfoFormat ;
315+ if (NewDebugMode)
316+ M.convertFromNewDbgValues ();
317+
307318 uint64_t FunctionsCnt = DebugInfoBeforePass.DIFunctions .size ();
308319 // Visit each instruction.
309320 for (Function &F : Functions) {
@@ -368,6 +379,9 @@ bool llvm::collectDebugInfoMetadata(Module &M,
368379 }
369380 }
370381
382+ if (NewDebugMode)
383+ M.convertToNewDbgValues ();
384+
371385 return true ;
372386}
373387
@@ -547,6 +561,10 @@ bool llvm::checkDebugInfoMetadata(Module &M,
547561 return false ;
548562 }
549563
564+ bool NewDebugMode = M.IsNewDbgInfoFormat ;
565+ if (NewDebugMode)
566+ M.convertFromNewDbgValues ();
567+
550568 // Map the debug info holding DIs after a pass.
551569 DebugInfoPerPass DebugInfoAfterPass;
552570
@@ -657,6 +675,9 @@ bool llvm::checkDebugInfoMetadata(Module &M,
657675 // the debugging information from the previous pass.
658676 DebugInfoBeforePass = DebugInfoAfterPass;
659677
678+ if (NewDebugMode)
679+ M.convertToNewDbgValues ();
680+
660681 LLVM_DEBUG (dbgs () << " \n\n " );
661682 return Result;
662683}
@@ -714,6 +735,10 @@ bool checkDebugifyMetadata(Module &M,
714735 return false ;
715736 }
716737
738+ bool NewDebugMode = M.IsNewDbgInfoFormat ;
739+ if (NewDebugMode)
740+ M.convertFromNewDbgValues ();
741+
717742 auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
718743 return mdconst::extract<ConstantInt>(NMD->getOperand (Idx)->getOperand (0 ))
719744 ->getZExtValue ();
@@ -791,24 +816,22 @@ bool checkDebugifyMetadata(Module &M,
791816 dbg () << " : " << (HasErrors ? " FAIL" : " PASS" ) << ' \n ' ;
792817
793818 // Strip debugify metadata if required.
819+ bool Ret = false ;
794820 if (Strip)
795- return stripDebugifyMetadata (M);
821+ Ret = stripDebugifyMetadata (M);
822+
823+ if (NewDebugMode)
824+ M.convertToNewDbgValues ();
796825
797- return false ;
826+ return Ret ;
798827}
799828
800829// / ModulePass for attaching synthetic debug info to everything, used with the
801830// / legacy module pass manager.
802831struct DebugifyModulePass : public ModulePass {
803832 bool runOnModule (Module &M) override {
804- bool NewDebugMode = M.IsNewDbgInfoFormat ;
805- if (NewDebugMode)
806- M.convertFromNewDbgValues ();
807-
808- bool Result = applyDebugify (M, Mode, DebugInfoBeforePass, NameOfWrappedPass);
809-
810- if (NewDebugMode)
811- M.convertToNewDbgValues ();
833+ bool Result =
834+ applyDebugify (M, Mode, DebugInfoBeforePass, NameOfWrappedPass);
812835 return Result;
813836 }
814837
@@ -834,14 +857,8 @@ struct DebugifyModulePass : public ModulePass {
834857// / single function, used with the legacy module pass manager.
835858struct DebugifyFunctionPass : public FunctionPass {
836859 bool runOnFunction (Function &F) override {
837- bool NewDebugMode = F.IsNewDbgInfoFormat ;
838- if (NewDebugMode)
839- F.convertFromNewDbgValues ();
840-
841- bool Result = applyDebugify (F, Mode, DebugInfoBeforePass, NameOfWrappedPass);
842-
843- if (NewDebugMode)
844- F.convertToNewDbgValues ();
860+ bool Result =
861+ applyDebugify (F, Mode, DebugInfoBeforePass, NameOfWrappedPass);
845862 return Result;
846863 }
847864
@@ -868,10 +885,6 @@ struct DebugifyFunctionPass : public FunctionPass {
868885// / legacy module pass manager.
869886struct CheckDebugifyModulePass : public ModulePass {
870887 bool runOnModule (Module &M) override {
871- bool NewDebugMode = M.IsNewDbgInfoFormat ;
872- if (NewDebugMode)
873- M.convertFromNewDbgValues ();
874-
875888 bool Result;
876889 if (Mode == DebugifyMode::SyntheticDebugInfo)
877890 Result = checkDebugifyMetadata (M, M.functions (), NameOfWrappedPass,
@@ -882,9 +895,6 @@ struct CheckDebugifyModulePass : public ModulePass {
882895 " CheckModuleDebugify (original debuginfo)" , NameOfWrappedPass,
883896 OrigDIVerifyBugsReportFilePath);
884897
885- if (NewDebugMode)
886- M.convertToNewDbgValues ();
887-
888898 return Result;
889899 }
890900
@@ -918,10 +928,6 @@ struct CheckDebugifyModulePass : public ModulePass {
918928// / with the legacy module pass manager.
919929struct CheckDebugifyFunctionPass : public FunctionPass {
920930 bool runOnFunction (Function &F) override {
921- bool NewDebugMode = F.IsNewDbgInfoFormat ;
922- if (NewDebugMode)
923- F.convertFromNewDbgValues ();
924-
925931 Module &M = *F.getParent ();
926932 auto FuncIt = F.getIterator ();
927933 bool Result;
@@ -935,8 +941,6 @@ struct CheckDebugifyFunctionPass : public FunctionPass {
935941 " CheckFunctionDebugify (original debuginfo)" , NameOfWrappedPass,
936942 OrigDIVerifyBugsReportFilePath);
937943
938- if (NewDebugMode)
939- F.convertToNewDbgValues ();
940944 return Result;
941945 }
942946
@@ -1009,10 +1013,6 @@ createDebugifyFunctionPass(enum DebugifyMode Mode,
10091013}
10101014
10111015PreservedAnalyses NewPMDebugifyPass::run (Module &M, ModuleAnalysisManager &) {
1012- bool NewDebugMode = M.IsNewDbgInfoFormat ;
1013- if (NewDebugMode)
1014- M.convertFromNewDbgValues ();
1015-
10161016 if (Mode == DebugifyMode::SyntheticDebugInfo)
10171017 applyDebugifyMetadata (M, M.functions (),
10181018 " ModuleDebugify: " , /* ApplyToMF*/ nullptr );
@@ -1021,9 +1021,6 @@ PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
10211021 " ModuleDebugify (original debuginfo)" ,
10221022 NameOfWrappedPass);
10231023
1024- if (NewDebugMode)
1025- M.convertToNewDbgValues ();
1026-
10271024 PreservedAnalyses PA;
10281025 PA.preserveSet <CFGAnalyses>();
10291026 return PA;
0 commit comments