aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Debugify.cpp
diff options
context:
space:
mode:
authorJeremy Morse <jeremy.morse@sony.com>2024-02-06 18:30:20 +0000
committerGitHub <noreply@github.com>2024-02-06 18:30:20 +0000
commita4531108da358500939af95b53794591432aaf74 (patch)
treec7dffdb7cfb582ca194828f39ba642e2c12785b5 /llvm/lib/Transforms/Utils/Debugify.cpp
parentc7d181cc67a7af122835bc51159baa0eb6c5ac7c (diff)
downloadllvm-a4531108da358500939af95b53794591432aaf74.zip
llvm-a4531108da358500939af95b53794591432aaf74.tar.gz
llvm-a4531108da358500939af95b53794591432aaf74.tar.bz2
[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!
Diffstat (limited to 'llvm/lib/Transforms/Utils/Debugify.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Debugify.cpp73
1 files changed, 35 insertions, 38 deletions
diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp b/llvm/lib/Transforms/Utils/Debugify.cpp
index d0cc603..200bad2 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -87,6 +87,10 @@ bool llvm::applyDebugifyMetadata(
return false;
}
+ bool NewDebugMode = M.IsNewDbgInfoFormat;
+ if (NewDebugMode)
+ M.convertFromNewDbgValues();
+
DIBuilder DIB(M);
LLVMContext &Ctx = M.getContext();
auto *Int32Ty = Type::getInt32Ty(Ctx);
@@ -210,6 +214,9 @@ bool llvm::applyDebugifyMetadata(
if (!M.getModuleFlag(DIVersionKey))
M.addModuleFlag(Module::Warning, DIVersionKey, DEBUG_METADATA_VERSION);
+ if (NewDebugMode)
+ M.convertToNewDbgValues();
+
return true;
}
@@ -304,6 +311,10 @@ bool llvm::collectDebugInfoMetadata(Module &M,
return false;
}
+ bool NewDebugMode = M.IsNewDbgInfoFormat;
+ if (NewDebugMode)
+ M.convertFromNewDbgValues();
+
uint64_t FunctionsCnt = DebugInfoBeforePass.DIFunctions.size();
// Visit each instruction.
for (Function &F : Functions) {
@@ -368,6 +379,9 @@ bool llvm::collectDebugInfoMetadata(Module &M,
}
}
+ if (NewDebugMode)
+ M.convertToNewDbgValues();
+
return true;
}
@@ -547,6 +561,10 @@ bool llvm::checkDebugInfoMetadata(Module &M,
return false;
}
+ bool NewDebugMode = M.IsNewDbgInfoFormat;
+ if (NewDebugMode)
+ M.convertFromNewDbgValues();
+
// Map the debug info holding DIs after a pass.
DebugInfoPerPass DebugInfoAfterPass;
@@ -657,6 +675,9 @@ bool llvm::checkDebugInfoMetadata(Module &M,
// the debugging information from the previous pass.
DebugInfoBeforePass = DebugInfoAfterPass;
+ if (NewDebugMode)
+ M.convertToNewDbgValues();
+
LLVM_DEBUG(dbgs() << "\n\n");
return Result;
}
@@ -714,6 +735,10 @@ bool checkDebugifyMetadata(Module &M,
return false;
}
+ bool NewDebugMode = M.IsNewDbgInfoFormat;
+ if (NewDebugMode)
+ M.convertFromNewDbgValues();
+
auto getDebugifyOperand = [&](unsigned Idx) -> unsigned {
return mdconst::extract<ConstantInt>(NMD->getOperand(Idx)->getOperand(0))
->getZExtValue();
@@ -791,24 +816,22 @@ bool checkDebugifyMetadata(Module &M,
dbg() << ": " << (HasErrors ? "FAIL" : "PASS") << '\n';
// Strip debugify metadata if required.
+ bool Ret = false;
if (Strip)
- return stripDebugifyMetadata(M);
+ Ret = stripDebugifyMetadata(M);
+
+ if (NewDebugMode)
+ M.convertToNewDbgValues();
- return false;
+ return Ret;
}
/// ModulePass for attaching synthetic debug info to everything, used with the
/// legacy module pass manager.
struct DebugifyModulePass : public ModulePass {
bool runOnModule(Module &M) override {
- bool NewDebugMode = M.IsNewDbgInfoFormat;
- if (NewDebugMode)
- M.convertFromNewDbgValues();
-
- bool Result = applyDebugify(M, Mode, DebugInfoBeforePass, NameOfWrappedPass);
-
- if (NewDebugMode)
- M.convertToNewDbgValues();
+ bool Result =
+ applyDebugify(M, Mode, DebugInfoBeforePass, NameOfWrappedPass);
return Result;
}
@@ -834,14 +857,8 @@ private:
/// single function, used with the legacy module pass manager.
struct DebugifyFunctionPass : public FunctionPass {
bool runOnFunction(Function &F) override {
- bool NewDebugMode = F.IsNewDbgInfoFormat;
- if (NewDebugMode)
- F.convertFromNewDbgValues();
-
- bool Result = applyDebugify(F, Mode, DebugInfoBeforePass, NameOfWrappedPass);
-
- if (NewDebugMode)
- F.convertToNewDbgValues();
+ bool Result =
+ applyDebugify(F, Mode, DebugInfoBeforePass, NameOfWrappedPass);
return Result;
}
@@ -868,10 +885,6 @@ private:
/// legacy module pass manager.
struct CheckDebugifyModulePass : public ModulePass {
bool runOnModule(Module &M) override {
- bool NewDebugMode = M.IsNewDbgInfoFormat;
- if (NewDebugMode)
- M.convertFromNewDbgValues();
-
bool Result;
if (Mode == DebugifyMode::SyntheticDebugInfo)
Result = checkDebugifyMetadata(M, M.functions(), NameOfWrappedPass,
@@ -882,9 +895,6 @@ struct CheckDebugifyModulePass : public ModulePass {
"CheckModuleDebugify (original debuginfo)", NameOfWrappedPass,
OrigDIVerifyBugsReportFilePath);
- if (NewDebugMode)
- M.convertToNewDbgValues();
-
return Result;
}
@@ -918,10 +928,6 @@ private:
/// with the legacy module pass manager.
struct CheckDebugifyFunctionPass : public FunctionPass {
bool runOnFunction(Function &F) override {
- bool NewDebugMode = F.IsNewDbgInfoFormat;
- if (NewDebugMode)
- F.convertFromNewDbgValues();
-
Module &M = *F.getParent();
auto FuncIt = F.getIterator();
bool Result;
@@ -935,8 +941,6 @@ struct CheckDebugifyFunctionPass : public FunctionPass {
"CheckFunctionDebugify (original debuginfo)", NameOfWrappedPass,
OrigDIVerifyBugsReportFilePath);
- if (NewDebugMode)
- F.convertToNewDbgValues();
return Result;
}
@@ -1009,10 +1013,6 @@ createDebugifyFunctionPass(enum DebugifyMode Mode,
}
PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
- bool NewDebugMode = M.IsNewDbgInfoFormat;
- if (NewDebugMode)
- M.convertFromNewDbgValues();
-
if (Mode == DebugifyMode::SyntheticDebugInfo)
applyDebugifyMetadata(M, M.functions(),
"ModuleDebugify: ", /*ApplyToMF*/ nullptr);
@@ -1021,9 +1021,6 @@ PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
"ModuleDebugify (original debuginfo)",
NameOfWrappedPass);
- if (NewDebugMode)
- M.convertToNewDbgValues();
-
PreservedAnalyses PA;
PA.preserveSet<CFGAnalyses>();
return PA;