Skip to content

Commit a453110

Browse files
authored
[DebugInfo][RemoveDIs] Extend intrinsic-conversion in debugify (#80861)
A while back the entry/exit points of debugify were instrumented with conversion functions to/from non-intrinsic-form debug-info. This is the path of least resistance to incrementally converting parts of LLVM to use the new format. However, it turns out that debugify registers callbacks with the pass manager and can be fed non-intrinsic form debug-info. Thus: this patch wraps each of the four major debugify functions with the convertion utilities, and extends test coverage to a test that exposes this problem. (An alternative would be to put this code in the callback lambdas, but then it would be fighting pass manager abstractions of what type the IR has). Handily debugify has been designed to record the /meaning/ of debug-info rather than take pointers to intrinsics and the like, so the storage mechanism for debug-info is transparent to it!
1 parent c7d181c commit a453110

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

llvm/lib/Transforms/Utils/Debugify.cpp

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
802831
struct 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.
835858
struct 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.
869886
struct 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.
919929
struct 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

10111015
PreservedAnalyses 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;

llvm/test/Transforms/Util/Debugify/loc-only-original-mode.ll

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
; RUN: -verify-each-debuginfo-preserve \
1515
; RUN: -debugify-func-limit=2 -S 2>&1 | FileCheck %s --check-prefix=CHECK-DROP
1616

17+
;; Add some runlines that use RemoveDIs non-intrinsic debug-info, to check that
18+
;; variable preservation checking works.
19+
; RUN: opt < %s -passes=deadargelim --try-experimental-debuginfo-iterators \
20+
; RUN: -verify-each-debuginfo-preserve \
21+
; RUN: -debugify-level=location+variables -S 2>&1 | FileCheck %s --check-prefix=CHECK-DROP
1722

1823
; CHECK-NOT: drops dbg.value()/dbg.declare()
1924
; CHECK-DROP: drops dbg.value()/dbg.declare()
@@ -22,21 +27,21 @@ target triple = "x86_64-unknown-linux-gnu"
2227

2328
define dso_local i32 @fn2(i32 %l, i32 %k) !dbg !7 {
2429
entry:
25-
call void @llvm.dbg.value(metadata i32 %l, metadata !12, metadata !DIExpression()), !dbg !15
26-
call void @llvm.dbg.value(metadata i32 %k, metadata !13, metadata !DIExpression()), !dbg !15
30+
tail call void @llvm.dbg.value(metadata i32 %l, metadata !12, metadata !DIExpression()), !dbg !15
31+
tail call void @llvm.dbg.value(metadata i32 %k, metadata !13, metadata !DIExpression()), !dbg !15
2732
%call = call i32 (...) @fn3(), !dbg !16
28-
call void @llvm.dbg.value(metadata i32 %call, metadata !14, metadata !DIExpression()), !dbg !15
33+
tail call void @llvm.dbg.value(metadata i32 %call, metadata !14, metadata !DIExpression()), !dbg !15
2934
ret i32 %call, !dbg !17
3035
}
3136

3237
declare !dbg !18 dso_local i32 @fn3(...)
3338

3439
define dso_local i32 @fn(i32 %x, i32 %y) !dbg !22 {
3540
entry:
36-
call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !27
37-
call void @llvm.dbg.value(metadata i32 %y, metadata !25, metadata !DIExpression()), !dbg !27
41+
tail call void @llvm.dbg.value(metadata i32 %x, metadata !24, metadata !DIExpression()), !dbg !27
42+
tail call void @llvm.dbg.value(metadata i32 %y, metadata !25, metadata !DIExpression()), !dbg !27
3843
%call = call i32 @fn2(i32 %x, i32 %y), !dbg !27
39-
call void @llvm.dbg.value(metadata i32 %call, metadata !26, metadata !DIExpression()), !dbg !27
44+
tail call void @llvm.dbg.value(metadata i32 %call, metadata !26, metadata !DIExpression()), !dbg !27
4045
%add = add nsw i32 %call, %x, !dbg !27
4146
%add1 = add nsw i32 %add, %y, !dbg !27
4247
ret i32 %add1, !dbg !27

0 commit comments

Comments
 (0)