Skip to content

[DebugInfo][RemoveDIs] Eliminate another debug-info variation flag #133917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ static cl::opt<bool> AllowIncompleteIR(
"metadata will be dropped)"));

extern llvm::cl::opt<bool> UseNewDbgInfoFormat;
extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;

static std::string getTypeString(Type *T) {
std::string Result;
Expand Down Expand Up @@ -209,10 +208,6 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
// records in this IR.
assert(!(SeenNewDbgInfoFormat && SeenOldDbgInfoFormat) &&
"Mixed debug intrinsics/records seen without a parsing error?");
if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
UseNewDbgInfoFormat = SeenNewDbgInfoFormat;
M->setNewDbgInfoFormatFlag(SeenNewDbgInfoFormat);
}

// Handle any function attribute group forward references.
for (const auto &RAG : ForwardRefAttrGroups) {
Expand Down Expand Up @@ -447,8 +442,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
UpgradeNVVMAnnotations(*M);
UpgradeSectionAttributes(*M);

if (PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE)
M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);
M->setIsNewDbgInfoFormat(UseNewDbgInfoFormat);

if (!Slots)
return false;
Expand Down
37 changes: 2 additions & 35 deletions llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static cl::opt<bool> ExpandConstantExprs(
"Expand constant expressions to instructions for testing purposes"));

extern cl::opt<bool> UseNewDbgInfoFormat;
extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;

namespace {

Expand Down Expand Up @@ -3953,11 +3952,7 @@ Error BitcodeReader::globalCleanup() {
for (Function &F : *TheModule) {
MDLoader->upgradeDebugIntrinsics(F);
Function *NewFn;
// If PreserveInputDbgFormat=true, then we don't know whether we want
// intrinsics or records, and we won't perform any conversions in either
// case, so don't upgrade intrinsics to records.
if (UpgradeIntrinsicFunction(
&F, NewFn, PreserveInputDbgFormat != cl::boolOrDefault::BOU_TRUE))
if (UpgradeIntrinsicFunction(&F, NewFn))
UpgradedIntrinsics[&F] = NewFn;
// Look for functions that rely on old function attribute behavior.
UpgradeFunctionAttributes(F);
Expand Down Expand Up @@ -7002,37 +6997,9 @@ Error BitcodeReader::materialize(GlobalValue *GV) {
F->setIsMaterializable(false);

// All parsed Functions should load into the debug info format dictated by the
// Module, unless we're attempting to preserve the input debug info format.
// Module.
if (SeenDebugIntrinsic && SeenDebugRecord)
return error("Mixed debug intrinsics and debug records in bitcode module!");
if (PreserveInputDbgFormat == cl::boolOrDefault::BOU_TRUE) {
bool SeenAnyDebugInfo = SeenDebugIntrinsic || SeenDebugRecord;
bool NewDbgInfoFormatDesired =
SeenAnyDebugInfo ? SeenDebugRecord : F->getParent()->IsNewDbgInfoFormat;
if (SeenAnyDebugInfo) {
UseNewDbgInfoFormat = SeenDebugRecord;
}
// If the module's debug info format doesn't match the observed input
// format, then set its format now; we don't need to call the conversion
// function because there must be no existing intrinsics to convert.
// Otherwise, just set the format on this function now.
if (NewDbgInfoFormatDesired != F->getParent()->IsNewDbgInfoFormat)
F->getParent()->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
else
F->setNewDbgInfoFormatFlag(NewDbgInfoFormatDesired);
} else {
// If we aren't preserving formats, we use the Module flag to get our
// desired format instead of reading flags, in case we are lazy-loading and
// the format of the module has been changed since it was set by the flags.
// We only need to convert debug info here if we have debug records but
// desire the intrinsic format; everything else is a no-op or handled by the
// autoupgrader.
bool ModuleIsNewDbgInfoFormat = F->getParent()->IsNewDbgInfoFormat;
if (ModuleIsNewDbgInfoFormat || !SeenDebugRecord)
F->setNewDbgInfoFormatFlag(ModuleIsNewDbgInfoFormat);
else
F->setIsNewDbgInfoFormat(ModuleIsNewDbgInfoFormat);
}

if (StripDebugInfo)
stripDebugInfo(*F);
Expand Down
24 changes: 24 additions & 0 deletions llvm/lib/IR/AsmWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ static void orderValue(const Value *V, OrderMap &OM) {
static OrderMap orderModule(const Module *M) {
OrderMap OM;

auto orderConstantValue = [&OM](const Value *V) {
if (isa<Constant>(V) || isa<InlineAsm>(V))
orderValue(V, OM);
};

auto OrderConstantFromMetadata = [&](Metadata *MD) {
if (const auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
orderConstantValue(VAM->getValue());
} else if (const auto *AL = dyn_cast<DIArgList>(MD)) {
for (const auto *VAM : AL->getArgs())
orderConstantValue(VAM->getValue());
}
};

for (const GlobalVariable &G : M->globals()) {
if (G.hasInitializer())
if (!isa<GlobalValue>(G.getInitializer()))
Expand Down Expand Up @@ -171,6 +185,16 @@ static OrderMap orderModule(const Module *M) {
for (const BasicBlock &BB : F) {
orderValue(&BB, OM);
for (const Instruction &I : BB) {
// Debug records can contain Value references, that can then contain
// Values disconnected from the rest of the Value hierachy, if wrapped
// in some kind of constant-expression. Find and order any Values that
// are wrapped in debug-info.
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
OrderConstantFromMetadata(DVR.getRawLocation());
if (DVR.isDbgAssign())
OrderConstantFromMetadata(DVR.getRawAddress());
}

for (const Value *Op : I.operands()) {
Op = skipMetadataWrapper(Op);
if ((isa<Constant>(*Op) && !isa<GlobalValue>(*Op)) ||
Expand Down
7 changes: 0 additions & 7 deletions llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ cl::opt<bool> UseNewDbgInfoFormat(
"eliminating intrinsics. Has no effect if "
"--preserve-input-debuginfo-format=true."),
cl::init(true));
cl::opt<cl::boolOrDefault> PreserveInputDbgFormat(
"preserve-input-debuginfo-format", cl::Hidden,
cl::desc("When set to true, IR files will be processed and printed in "
"their current debug info format, regardless of default behaviour "
"or other flags passed. Has no effect if input IR does not "
"contain debug records or intrinsics. Ignored in llvm-link, "
"llvm-lto, and llvm-lto2."));

DbgMarker *BasicBlock::createMarker(Instruction *I) {
assert(IsNewDbgInfoFormat &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ target triple = "x86_64-apple-darwin10.2"
define i32 @main() nounwind readonly !dbg !1 {
%diff1 = alloca i64 ; <ptr> [#uses=2]
; CHECK: #dbg_value(i64 72,
call void @llvm.dbg.declare(metadata ptr %diff1, metadata !0, metadata !DIExpression()), !dbg !DILocation(scope: !1)
#dbg_declare(ptr %diff1, !0, !DIExpression(), !DILocation(scope: !1))
store i64 72, ptr %diff1, align 8
%v1 = load ptr, ptr @TestArrayPtr, align 8 ; <ptr> [#uses=1]
%v2 = ptrtoint ptr %v1 to i64 ; <i64> [#uses=1]
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Assembler/DIDefaultTemplateParam.ll
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ entry:
%f1 = alloca %class.foo, align 1
%f2 = alloca %class.foo.0, align 1
store i32 0, ptr %retval, align 4
call void @llvm.dbg.declare(metadata ptr %f1, metadata !11, metadata !DIExpression()), !dbg !16
call void @llvm.dbg.declare(metadata ptr %f2, metadata !17, metadata !DIExpression()), !dbg !23
#dbg_declare(ptr %f1, !11, !DIExpression(), !16)
#dbg_declare(ptr %f2, !17, !DIExpression(), !23)
ret i32 0, !dbg !24
}
; Function Attrs: nounwind readnone speculatable willreturn
Expand Down
16 changes: 10 additions & 6 deletions llvm/test/Assembler/metadata-use-uselistorder.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
; correctly preserved due to the uses in the dbg.value contant expressions not
; being considered, since they are wrapped in metadata.

; With debug records (i.e., not with intrinsics) there's less chance of
; debug-info affecting use-list order as it exists outside of the Value
; hierachy. However, debug records still use ValueAsMetadata nodes, so this
; test remains worthwhile.

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

Expand All @@ -16,21 +21,19 @@ target triple = "x86_64-unknown-linux-gnu"
define void @foo() local_unnamed_addr !dbg !6 {
entry:
%0 = load i64, ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 4), align 16
call void @llvm.dbg.value(metadata ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 5), metadata !10, metadata !DIExpression()), !dbg !13
#dbg_value(ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 5), !10, !DIExpression(), !13)
%1 = load i64, ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 6), align 16
call void @llvm.dbg.value(metadata ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 6), metadata !10, metadata !DIExpression()), !dbg !14
#dbg_value(ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 6), !10, !DIExpression(), !14)
#dbg_assign(i32 0, !10, !DIExpression(), !19, ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 6), !DIExpression(), !14)
ret void
}

define void @bar() local_unnamed_addr !dbg !15 {
entry:
call void @llvm.dbg.value(metadata ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 7), metadata !17, metadata !DIExpression()), !dbg !18
#dbg_value(ptr getelementptr inbounds ([10 x i64], ptr @global_arr, i64 0, i64 7), !17, !DIExpression(), !18)
ret void
}

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #0

attributes #0 = { nounwind readnone speculatable }

!llvm.dbg.cu = !{!0}
Expand All @@ -56,3 +59,4 @@ attributes #0 = { nounwind readnone speculatable }
!16 = !{!17}
!17 = !DILocalVariable(name: "local2", scope: !15, file: !1, line: 13, type: !11)
!18 = !DILocation(line: 14, column: 1, scope: !15)
!19 = distinct !DIAssignID()
35 changes: 17 additions & 18 deletions llvm/test/Bitcode/dbg-record-roundtrip.ll
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
;; Roundtrip tests.

;; Tests that bitcode can be printed and interpreted by llvm-dis with non-intrinsic
;; debug records -- llvm-as will autoupgrade.
; RUN: llvm-as %s -o - \
; RUN: | llvm-dis \
; RUN: | FileCheck %s --check-prefixes=RECORDS

;; Check that verify-uselistorder passes regardless of input format.
;; Check that verify-uselistorder passes with bitcode and textual IR.
; RUN: llvm-as %s -o - | verify-uselistorder
; RUN: verify-uselistorder %s

Expand All @@ -31,17 +29,18 @@ entry:
; RECORDS-NEXT: dbg_value(![[empty:[0-9]+]], ![[e]], !DIExpression(), ![[dbg]])
; RECORDS-NEXT: dbg_value(i32 poison, ![[e]], !DIExpression(), ![[dbg]])
; RECORDS-NEXT: dbg_value(i32 1, ![[f:[0-9]+]], !DIExpression(), ![[dbg]])
tail call void @llvm.dbg.value(metadata i32 %p, metadata !32, metadata !DIExpression()), !dbg !19
tail call void @llvm.dbg.value(metadata !29, metadata !32, metadata !DIExpression()), !dbg !19
tail call void @llvm.dbg.value(metadata i32 poison, metadata !32, metadata !DIExpression()), !dbg !19
tail call void @llvm.dbg.value(metadata i32 1, metadata !33, metadata !DIExpression()), !dbg !19
#dbg_value(i32 %p, !32, !DIExpression(), !19)
#dbg_value(!29, !32, !DIExpression(), !19)
#dbg_value(i32 poison, !32, !DIExpression(), !19)
#dbg_value(i32 1, !33, !DIExpression(), !19)
;; Arglist with an argument, constant, local use before def, poison.
; RECORDS-NEXT: dbg_value(!DIArgList(i32 %p, i32 0, i32 %0, i32 poison), ![[f]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_LLVM_arg, 2, DW_OP_LLVM_arg, 3, DW_OP_plus, DW_OP_minus), ![[dbg]])
tail call void @llvm.dbg.value(metadata !DIArgList(i32 %p, i32 0, i32 %0, i32 poison), metadata !33, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_LLVM_arg, 2, DW_OP_LLVM_arg, 3, DW_OP_plus, DW_OP_minus)), !dbg !19
#dbg_value(!DIArgList(i32 %p, i32 0, i32 %0, i32 poison), !33, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_LLVM_arg, 2, DW_OP_LLVM_arg, 3, DW_OP_plus, DW_OP_minus), !19)

;; Check dbg.assign use before def (value, addr and ID). Check expression order too.
; RECORDS: dbg_assign(i32 %0, ![[i:[0-9]+]], !DIExpression(DW_OP_plus_uconst, 0),
; RECORDS-SAME: ![[ID:[0-9]+]], ptr %a, !DIExpression(DW_OP_plus_uconst, 1), ![[dbg]])
tail call void @llvm.dbg.assign(metadata i32 %0, metadata !36, metadata !DIExpression(DW_OP_plus_uconst, 0), metadata !37, metadata ptr %a, metadata !DIExpression(DW_OP_plus_uconst, 1)), !dbg !19
#dbg_assign(i32 %0, !36, !DIExpression(DW_OP_plus_uconst, 0), !37, ptr %a, !DIExpression(DW_OP_plus_uconst, 1), !19)
%a = alloca i32, align 4, !DIAssignID !37
; CHECK: %a = alloca i32, align 4, !DIAssignID ![[ID]]
;; Check dbg.declare configurations.
Expand All @@ -51,25 +50,25 @@ entry:
; RECORDS-NEXT: dbg_declare(ptr poison, ![[c:[0-9]+]], !DIExpression(), ![[dbg]])
; RECORDS-NEXT: dbg_declare(ptr null, ![[d:[0-9]+]], !DIExpression(), ![[dbg]])
; RECORDS-NEXT: dbg_declare(ptr @g, ![[h:[0-9]+]], !DIExpression(), ![[dbg]])
tail call void @llvm.dbg.declare(metadata ptr %a, metadata !17, metadata !DIExpression()), !dbg !19
tail call void @llvm.dbg.declare(metadata !29, metadata !28, metadata !DIExpression()), !dbg !19
tail call void @llvm.dbg.declare(metadata ptr poison, metadata !30, metadata !DIExpression()), !dbg !19
tail call void @llvm.dbg.declare(metadata ptr null, metadata !31, metadata !DIExpression()), !dbg !19
tail call void @llvm.dbg.declare(metadata ptr @g, metadata !35, metadata !DIExpression()), !dbg !19
#dbg_declare(ptr %a, !17, !DIExpression(), !19)
#dbg_declare(!29, !28, !DIExpression(), !19)
#dbg_declare(ptr poison, !30, !DIExpression(), !19)
#dbg_declare(ptr null, !31, !DIExpression(), !19)
#dbg_declare(ptr @g, !35, !DIExpression(), !19)
;; Argument value dbg.declare.
; RECORDS: dbg_declare(ptr %storage, ![[g:[0-9]+]], !DIExpression(), ![[dbg]])
tail call void @llvm.dbg.declare(metadata ptr %storage, metadata !34, metadata !DIExpression()), !dbg !19
#dbg_declare(ptr %storage, !34, !DIExpression(), !19)
;; Use before def dbg.value.
; RECORDS: dbg_value(i32 %0, ![[e]], !DIExpression(), ![[dbg]])
tail call void @llvm.dbg.value(metadata i32 %0, metadata !32, metadata !DIExpression()), !dbg !19
#dbg_value(i32 %0, !32, !DIExpression(), !19)
%0 = load i32, ptr @g, align 4, !dbg !20
;; Non-argument local value dbg.value.
; RECORDS: dbg_value(i32 %0, ![[e]], !DIExpression(), ![[dbg]])
tail call void @llvm.dbg.value(metadata i32 %0, metadata !32, metadata !DIExpression()), !dbg !19
#dbg_value(i32 %0, !32, !DIExpression(), !19)
store i32 %0, ptr %a, align 4, !dbg !19
%1 = load i32, ptr %a, align 4, !dbg !25
; RECORDS: dbg_label(![[label:[0-9]+]], ![[dbg]])
tail call void @llvm.dbg.label(metadata !38), !dbg !19
#dbg_label(!38, !19)
ret i32 %1, !dbg !27
}

Expand Down
45 changes: 0 additions & 45 deletions llvm/test/CodeGen/AArch64/fast-isel-branch-uncond-debug.ll

This file was deleted.

2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-reduce/debug-metadata-verifier.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; RUN: llvm-reduce %s -o %t --delta-passes=metadata --test %python --test-arg %p/Inputs/remove-metadata.py --abort-on-invalid-reduction
; RUN: FileCheck %s --input-file %t

; CHECK: call void @llvm.dbg.declare{{.*}}, !dbg
; CHECK: #dbg_declare
; CHECK: !llvm.dbg.cu = !{!0}
; CHECK-NOT: uninteresting

Expand Down
11 changes: 0 additions & 11 deletions llvm/test/tools/llvm-reduce/remove-args-dbg-intrinsics.ll

This file was deleted.

6 changes: 0 additions & 6 deletions llvm/tools/llvm-link/llvm-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ static cl::opt<bool> IgnoreNonBitcode(
cl::Hidden);

extern cl::opt<bool> UseNewDbgInfoFormat;
extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;

static ExitOnError ExitOnErr;

Expand Down Expand Up @@ -479,11 +478,6 @@ int main(int argc, char **argv) {
cl::HideUnrelatedOptions({&LinkCategory, &getColorCategory()});
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");

// Since llvm-link collects multiple IR modules together, for simplicity's
// sake we disable the "PreserveInputDbgFormat" flag to enforce a single
// debug info format.
PreserveInputDbgFormat = cl::boolOrDefault::BOU_FALSE;

LLVMContext Context;
Context.setDiagnosticHandler(std::make_unique<LLVMLinkDiagnosticHandler>(),
true);
Expand Down
7 changes: 0 additions & 7 deletions llvm/tools/llvm-lto/llvm-lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ static cl::opt<bool>
LTOSaveBeforeOpt("lto-save-before-opt", cl::init(false),
cl::desc("Save the IR before running optimizations"));

extern cl::opt<cl::boolOrDefault> PreserveInputDbgFormat;

namespace {

struct ModuleInfo {
Expand Down Expand Up @@ -1001,11 +999,6 @@ int main(int argc, char **argv) {
cl::HideUnrelatedOptions({&LTOCategory, &getColorCategory()});
cl::ParseCommandLineOptions(argc, argv, "llvm LTO linker\n");

// Since llvm-lto collects multiple IR modules together, for simplicity's sake
// we disable the "PreserveInputDbgFormat" flag to enforce a single debug info
// format.
PreserveInputDbgFormat = cl::boolOrDefault::BOU_FALSE;

if (OptLevel < '0' || OptLevel > '3')
error("optimization level must be between 0 and 3");

Expand Down
Loading
Loading