[llvm] [RemoveDIs] Make verify-uselistorder preserve the input debug info format (PR #87789)
Stephen Tozer via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 04:12:50 PDT 2024
https://github.com/SLTozer updated https://github.com/llvm/llvm-project/pull/87789
>From 3a205158ad39c67001eb5b08fadb973e663f1ae2 Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Thu, 28 Mar 2024 20:34:46 +0000
Subject: [PATCH 1/3] verify-uselistorder things
---
llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp | 4 ++++
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 2 ++
llvm/tools/llvm-as/llvm-as.cpp | 4 +++-
llvm/tools/llvm-dis/llvm-dis.cpp | 2 ++
.../verify-uselistorder/verify-uselistorder.cpp | 16 ++--------------
5 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
index 4f2486c963e987..048c72bce7c0f3 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
@@ -23,6 +23,8 @@ extern bool WriteNewDbgInfoFormatToBitcode;
PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat &&
WriteNewDbgInfoFormatToBitcode);
+ if (M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode)
+ M.removeDebugIntrinsicDeclarations();
const ModuleSummaryIndex *Index =
EmitSummaryIndex ? &(AM.getResult<ModuleSummaryIndexAnalysis>(M))
@@ -54,6 +56,8 @@ namespace {
bool runOnModule(Module &M) override {
ScopedDbgInfoFormatSetter FormatSetter(
M, M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode);
+ if (M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode)
+ M.removeDebugIntrinsicDeclarations();
WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
/*EmitModuleHash=*/false);
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index 4df18c8249277f..777c1984555335 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -585,6 +585,8 @@ llvm::ThinLTOBitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
// debug-info, convert to dbg.values before writing out.
ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat &&
WriteNewDbgInfoFormatToBitcode);
+ if (M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode)
+ M.removeDebugIntrinsicDeclarations();
bool Changed = writeThinLTOBitcode(
OS, ThinLinkOS,
diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp
index fd852563838f37..e48e3f4d22c123 100644
--- a/llvm/tools/llvm-as/llvm-as.cpp
+++ b/llvm/tools/llvm-as/llvm-as.cpp
@@ -143,8 +143,10 @@ int main(int argc, char **argv) {
// Convert to new debug format if requested.
assert(!M->IsNewDbgInfoFormat && "Unexpectedly in new debug mode");
- if (UseNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode)
+ if (UseNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode) {
M->convertToNewDbgValues();
+ M->removeDebugIntrinsicDeclarations();
+ }
std::unique_ptr<ModuleSummaryIndex> Index = std::move(ModuleAndIndex.Index);
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp
index 6ad1c99568e4a5..fbbb5506e43e05 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -259,6 +259,8 @@ int main(int argc, char **argv) {
if (!DontPrint) {
if (M) {
ScopedDbgInfoFormatSetter FormatSetter(*M, WriteNewDbgInfoFormat);
+ if (WriteNewDbgInfoFormat)
+ M->removeDebugIntrinsicDeclarations();
M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder);
}
if (Index)
diff --git a/llvm/tools/verify-uselistorder/verify-uselistorder.cpp b/llvm/tools/verify-uselistorder/verify-uselistorder.cpp
index cb07dede1d1374..b239190e4dec09 100644
--- a/llvm/tools/verify-uselistorder/verify-uselistorder.cpp
+++ b/llvm/tools/verify-uselistorder/verify-uselistorder.cpp
@@ -68,7 +68,7 @@ static cl::opt<unsigned>
cl::desc("Number of times to shuffle and verify use-lists"),
cl::init(1), cl::cat(Cat));
-extern cl::opt<cl::boolOrDefault> LoadBitcodeIntoNewDbgInfoFormat;
+extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;
namespace {
@@ -169,9 +169,6 @@ std::unique_ptr<Module> TempFile::readBitcode(LLVMContext &Context) const {
return nullptr;
}
- // verify-uselistoder currently only supports old-style debug info mode.
- // FIXME: Update mapping code for RemoveDIs.
- ModuleOr.get()->setIsNewDbgInfoFormat(false);
return std::move(ModuleOr.get());
}
@@ -181,9 +178,6 @@ std::unique_ptr<Module> TempFile::readAssembly(LLVMContext &Context) const {
std::unique_ptr<Module> M = parseAssemblyFile(Filename, Err, Context);
if (!M.get())
Err.print("verify-uselistorder", errs());
- // verify-uselistoder currently only supports old-style debug info mode.
- // FIXME: Update mapping code for RemoveDIs.
- M->setIsNewDbgInfoFormat(false);
return M;
}
@@ -536,6 +530,7 @@ static void reverseUseLists(Module &M) {
}
int main(int argc, char **argv) {
+ PreserveInputDbgFormat = cl::boolOrDefault::BOU_TRUE;
InitLLVM X(argc, argv);
// Enable debug stream buffering.
@@ -545,18 +540,11 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv,
"llvm tool to verify use-list order\n");
- // Do not load bitcode into the new debug info format by default.
- if (LoadBitcodeIntoNewDbgInfoFormat == cl::boolOrDefault::BOU_UNSET)
- LoadBitcodeIntoNewDbgInfoFormat = cl::boolOrDefault::BOU_FALSE;
-
LLVMContext Context;
SMDiagnostic Err;
// Load the input module...
std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);
- // verify-uselistoder currently only supports old-style debug info mode.
- // FIXME: Update mapping code for RemoveDIs.
- M->setIsNewDbgInfoFormat(false);
if (!M.get()) {
Err.print(argv[0], errs());
>From 2ac013f0a55be7459012989f7a2f89d490e558f1 Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Thu, 18 Apr 2024 11:52:32 +0100
Subject: [PATCH 2/3] Enumerate values used by debug records in
verify-uselistorder
---
.../verify-uselistorder/verify-uselistorder.cpp | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/llvm/tools/verify-uselistorder/verify-uselistorder.cpp b/llvm/tools/verify-uselistorder/verify-uselistorder.cpp
index b239190e4dec09..84fc777e1fdff1 100644
--- a/llvm/tools/verify-uselistorder/verify-uselistorder.cpp
+++ b/llvm/tools/verify-uselistorder/verify-uselistorder.cpp
@@ -222,8 +222,15 @@ ValueMapping::ValueMapping(const Module &M) {
map(&I);
// Constants used by instructions.
- for (const BasicBlock &BB : F)
- for (const Instruction &I : BB)
+ for (const BasicBlock &BB : F) {
+ for (const Instruction &I : BB) {
+ for (const DbgVariableRecord &DVR :
+ filterDbgVars(I.getDbgRecordRange())) {
+ for (Value *Op : DVR.location_ops())
+ map(Op);
+ if (DVR.isDbgAssign())
+ map(DVR.getAddress());
+ }
for (const Value *Op : I.operands()) {
// Look through a metadata wrapper.
if (const auto *MAV = dyn_cast<MetadataAsValue>(Op))
@@ -234,6 +241,8 @@ ValueMapping::ValueMapping(const Module &M) {
isa<InlineAsm>(Op))
map(Op);
}
+ }
+ }
}
}
>From 59fd7f091f06c7091f68ccf9dae13539b4bed872 Mon Sep 17 00:00:00 2001
From: Stephen Tozer <stephen.tozer at sony.com>
Date: Thu, 18 Apr 2024 12:12:35 +0100
Subject: [PATCH 3/3] Add intrinsic-decl removal to llvm-link
---
llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp | 4 ++--
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp | 4 +---
llvm/tools/llvm-link/llvm-link.cpp | 12 +++++++++++-
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
index 048c72bce7c0f3..5f66e1ea0a8352 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriterPass.cpp
@@ -23,7 +23,7 @@ extern bool WriteNewDbgInfoFormatToBitcode;
PreservedAnalyses BitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat &&
WriteNewDbgInfoFormatToBitcode);
- if (M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode)
+ if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
const ModuleSummaryIndex *Index =
@@ -56,7 +56,7 @@ namespace {
bool runOnModule(Module &M) override {
ScopedDbgInfoFormatSetter FormatSetter(
M, M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode);
- if (M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode)
+ if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
WriteBitcodeToFile(M, OS, ShouldPreserveUseListOrder, /*Index=*/nullptr,
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index 777c1984555335..9bf29c46938eba 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -581,11 +581,9 @@ llvm::ThinLTOBitcodeWriterPass::run(Module &M, ModuleAnalysisManager &AM) {
FunctionAnalysisManager &FAM =
AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
- // RemoveDIs: there's no bitcode representation of the DbgVariableRecord
- // debug-info, convert to dbg.values before writing out.
ScopedDbgInfoFormatSetter FormatSetter(M, M.IsNewDbgInfoFormat &&
WriteNewDbgInfoFormatToBitcode);
- if (M.IsNewDbgInfoFormat && WriteNewDbgInfoFormatToBitcode)
+ if (M.IsNewDbgInfoFormat)
M.removeDebugIntrinsicDeclarations();
bool Changed = writeThinLTOBitcode(
diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index 8f80cc26f3166f..7794f2d81ed064 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -136,6 +136,8 @@ static cl::opt<bool> TryUseNewDbgInfoFormat(
extern cl::opt<bool> UseNewDbgInfoFormat;
extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;
+extern cl::opt<bool> WriteNewDbgInfoFormat;
+extern bool WriteNewDbgInfoFormatToBitcode;
extern cl::opt<cl::boolOrDefault> LoadBitcodeIntoNewDbgInfoFormat;
@@ -545,10 +547,18 @@ int main(int argc, char **argv) {
if (Verbose)
errs() << "Writing bitcode...\n";
+ auto SetFormat = [&](bool NewFormat) {
+ Composite->setIsNewDbgInfoFormat(NewFormat);
+ if (NewFormat)
+ Composite->removeDebugIntrinsicDeclarations();
+ };
if (OutputAssembly) {
+ SetFormat(WriteNewDbgInfoFormat);
Composite->print(Out.os(), nullptr, PreserveAssemblyUseListOrder);
- } else if (Force || !CheckBitcodeOutputToConsole(Out.os()))
+ } else if (Force || !CheckBitcodeOutputToConsole(Out.os())) {
+ SetFormat(WriteNewDbgInfoFormatToBitcode);
WriteBitcodeToFile(*Composite, Out.os(), PreserveBitcodeUseListOrder);
+ }
// Declare success.
Out.keep();
More information about the llvm-commits
mailing list