Skip to content
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

[RemoveDIs] Enable llvm.dbg.label conversion to DbgLabelRecord [4/4] #5

Open
wants to merge 7 commits into
base: ddd/labels-upstream-3
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions llvm/include/llvm/IR/DebugProgramInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class DbgRecord : public ilist_node<DbgRecord> {
~DbgRecord() = default;
};

inline raw_ostream &operator<<(raw_ostream &OS, const DbgRecord &R) {
R.print(OS);
return OS;
}

/// Records a position in IR for a source label (DILabel). Corresponds to the
/// llvm.dbg.label intrinsic.
class DbgLabelRecord : public DbgRecord {
Expand Down
13 changes: 13 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,19 @@ void FastISel::handleDbgInfo(const Instruction *II) {
flushLocalValueMap();
recomputeInsertPt();

if (DbgLabelRecord *DPL = dyn_cast<DbgLabelRecord>(&DPR)) {
assert(DPL->getLabel() && "Missing label");
if (!FuncInfo.MF->getMMI().hasDebugInfo()) {
LLVM_DEBUG(dbgs() << "Dropping debug info for " << *DPL << "\n");
continue;
}

BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DPL->getDebugLoc(),
TII.get(TargetOpcode::DBG_LABEL))
.addMetadata(DPL->getLabel());
continue;
}

DbgVariableRecord &DPV = cast<DbgVariableRecord>(DPR);

Value *V = nullptr;
Expand Down
8 changes: 8 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,14 @@ void SelectionDAGBuilder::visitDbgInfo(const Instruction &I) {
// Is there is any debug-info attached to this instruction, in the form of
// DbgRecord non-instruction debug-info records.
for (DbgRecord &DPR : I.getDbgRecordRange()) {
if (DbgLabelRecord *DLR = dyn_cast<DbgLabelRecord>(&DPR)) {
assert(DLR->getLabel() && "Missing label");
SDDbgLabel *SDV =
DAG.getDbgLabel(DLR->getLabel(), DLR->getDebugLoc(), SDNodeOrder);
DAG.AddDbgLabel(SDV);
continue;
}

DbgVariableRecord &DPV = cast<DbgVariableRecord>(DPR);
DILocalVariable *Variable = DPV.getVariable();
DIExpression *Expression = DPV.getExpression();
Expand Down
23 changes: 20 additions & 3 deletions llvm/lib/IR/BasicBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ void BasicBlock::convertToNewDbgFormat() {
continue;
}

if (DbgLabelInst *DLI = dyn_cast<DbgLabelInst>(&I)) {
DPVals.push_back(new DbgLabelRecord(DLI->getLabel(), DLI->getDebugLoc()));
DLI->eraseFromParent();
continue;
}

// Create a marker to store records in. Technically we don't need to store
// one marker per instruction, but that's a future optimisation.
createMarker(&I);
Expand All @@ -110,15 +116,26 @@ void BasicBlock::convertFromNewDbgFormat() {

DbgMarker &Marker = *Inst.DbgRecordMarker;
for (DbgRecord &DR : Marker.getDbgRecordRange()) {
if (auto *DPV = dyn_cast<DbgVariableRecord>(&DR))
if (auto *DPV = dyn_cast<DbgVariableRecord>(&DR)) {
InstList.insert(Inst.getIterator(),
DPV->createDebugIntrinsic(getModule(), nullptr));
else
} else if (auto *DPL = dyn_cast<DbgLabelRecord>(&DR)) {
auto *LabelFn =
Intrinsic::getDeclaration(getModule(), Intrinsic::dbg_label);
Value *Args[] = {
MetadataAsValue::get(getModule()->getContext(), DPL->getLabel())};
DbgLabelInst *DbgLabel = cast<DbgLabelInst>(
CallInst::Create(LabelFn->getFunctionType(), LabelFn, Args));
DbgLabel->setTailCall();
DbgLabel->setDebugLoc(DPL->getDebugLoc());
InstList.insert(Inst.getIterator(), DbgLabel);
} else {
llvm_unreachable("unsupported entity kind");
}
}

Marker.eraseFromParent();
};
}

// Assume no trailing records: we could technically create them at the end
// of the block, after a terminator, but this would be non-cannonical and
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/IR/DebugProgramInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ DbgVariableRecord *DbgVariableRecord::clone() const {
return new DbgVariableRecord(*this);
}

DbgLabelRecord *DbgLabelRecord::clone() const {
return new DbgLabelRecord(Label, getDebugLoc());
}

DbgVariableIntrinsic *
DbgVariableRecord::createDebugIntrinsic(Module *M,
Instruction *InsertBefore) const {
Expand Down
21 changes: 19 additions & 2 deletions llvm/lib/Transforms/Utils/CodeExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,25 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,

auto UpdateDbgRecordsOnInst = [&](Instruction &I) -> void {
for (DbgRecord &DR : I.getDbgRecordRange()) {
DR.setDebugLoc(DebugLoc::replaceInlinedAtSubprogram(DR.getDebugLoc(),
*NewSP, Ctx, Cache));
if (DbgLabelRecord *DLR = cast<DbgLabelRecord>(&DR)) {
// Point the intrinsic to a fresh label within the new function if the
// intrinsic was not inlined from some other function.
if (DLR->getDebugLoc().getInlinedAt())
continue;
DILabel *OldLabel = DLR->getLabel();
DINode *&NewLabel = RemappedMetadata[OldLabel];
if (!NewLabel) {
DILocalScope *NewScope = DILocalScope::cloneScopeForSubprogram(
*OldLabel->getScope(), *NewSP, Ctx, Cache);
NewLabel = DILabel::get(Ctx, NewScope, OldLabel->getName(),
OldLabel->getFile(), OldLabel->getLine());
}
DLR->setLabel(cast<DILabel>(NewLabel));
continue;
}

DbgVariableRecord &DVR = cast<DbgVariableRecord>(DR);
// Apply the two updates that dbg.values get: invalid operands, and
// variable metadata fixup.
Expand All @@ -1597,8 +1616,6 @@ static void fixupDebugInfoPostExtraction(Function &OldFunc, Function &NewFunc,
}
if (!DVR.getDebugLoc().getInlinedAt())
DVR.setVariable(GetUpdatedDIVariable(DVR.getVariable()));
DVR.setDebugLoc(DebugLoc::replaceInlinedAtSubprogram(DVR.getDebugLoc(),
*NewSP, Ctx, Cache));
}
};

Expand Down
1 change: 1 addition & 0 deletions llvm/test/Assembler/debug-label-bitcode.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; Test bitcode writer/reader for DILabel metadata.
;; FIXME: Add --try-experimental-debuginfo-iterators to more tools?
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
; RUN: verify-uselistorder %s
;
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/CodeGen/Generic/live-debug-label.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; RUN: llc < %s -stop-after=virtregrewriter -o - | FileCheck %s
;
; RUN: llc --try-experimental-debuginfo-iterators < %s -stop-after=virtregrewriter -o - | FileCheck %s

; NVPTX produces a different order of the BBs
; XFAIL: target=nvptx{{.*}}

Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/MIR/X86/branch-folder-with-label.mir
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# }
#
# RUN: llc -o - %s -mtriple=x86_64-- -run-pass=branch-folder | FileCheck %s
# RUN: llc --try-experimental-debuginfo-iterators -o - %s -mtriple=x86_64-- -run-pass=branch-folder | FileCheck %s
--- |
; ModuleID = 'test.ll'
source_filename = "test.ll"
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/debug-label-fast-isel.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: llc < %s -mtriple powerpc64-ibm-aix-xcoff | FileCheck %s --check-prefix=CHECKASM

; RUN: llc --try-experimental-debuginfo-iterators < %s -mtriple powerpc64-ibm-aix-xcoff | FileCheck %s --check-prefix=CHECKASM
; This is a case copied from test/DebugInfo/Generic/debug-label-mi.ll. This test
; is to explicitly check that fast isel for XCOFF works as expected for debug
; related intrinsics.
Expand Down
1 change: 1 addition & 0 deletions llvm/test/DebugInfo/Generic/PR37395.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt -passes=lcssa -S %s | FileCheck %s
; RUN: opt --try-experimental-debuginfo-iterators -passes=lcssa -S %s | FileCheck %s
source_filename = "small.c"

@a = common dso_local global i32 0, align 4, !dbg !0
Expand Down
1 change: 1 addition & 0 deletions llvm/test/DebugInfo/Generic/debug-label-inline.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: llc -O0 -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s
; RUN: llc --try-experimental-debuginfo-iterators -O0 -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s
;
; Bug 47129
; XFAIL: target=sparc{{.*}}
Expand Down
9 changes: 8 additions & 1 deletion llvm/test/DebugInfo/Generic/debug-label-mi.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
; REQUIRES: asserts
; RUN: llc -debug-only=isel %s -o /dev/null 2> %t.debug
; RUN: cat %t.debug | FileCheck %s --check-prefix=CHECKMI
;
;; FIXME: RemoveDIs debug output is slightly different, e.g.:
;; - DBG_LABEL "top", debug-location !9; debug-label-mi.c:4:1
;; + DBG_LABEL "top", debug-location !DILocation(line: 4, column: 1, scope: !4); debug-label-mi.c:4:1
;; Disable these run lines until that is understood/fixed.
; run: llc --try-experimental-debuginfo-iterators -debug-only=isel %s -o /dev/null 2> %t.debug
; run: cat %t.debug | FileCheck %s --check-prefix=CHECKMI

; CHECKMI: DBG_LABEL "top", debug-location !9
; CHECKMI: DBG_LABEL "done", debug-location !11
;
; RUN: llc %s -o - | FileCheck %s --check-prefix=CHECKASM
; RUN: llc --try-experimental-debuginfo-iterators %s -o - | FileCheck %s --check-prefix=CHECKASM
;
; CHECKASM: DEBUG_LABEL: foo:top
; CHECKASM: DEBUG_LABEL: foo:done
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/DebugInfo/Generic/debug-label-opt.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
; REQUIRES: asserts
; RUN: llc -debug-only=isel %s -o /dev/null 2> %t.debug
; RUN: cat %t.debug | FileCheck %s --check-prefix=CHECKMI
;; FIXME: RemoveDIs debug output is slightly different, e.g.:
;; - DBG_LABEL "top", debug-location !9; debug-label-mi.c:4:1
;; + DBG_LABEL "top", debug-location !DILocation(line: 4, column: 1, scope: !4); debug-label-mi.c:4:1
;; Disable these run lines until that is understood/fixed.
; run: llc --try-experimental-debuginfo-iterators -debug-only=isel %s -o /dev/null 2> %t.debug
; run: cat %t.debug | FileCheck %s --check-prefix=CHECKMI
;
; CHECKMI: DBG_LABEL "end_sum", debug-location !17
; CHECKMI: DBG_LABEL "end", debug-location !19
Expand Down
4 changes: 3 additions & 1 deletion llvm/test/DebugInfo/Generic/debug-label.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; RUN: llc -O0 -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s
;
; RUN: llc --try-experimental-debuginfo-iterators -O0 -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s

; CHECK: .debug_info contents:
; CHECK: DW_TAG_label
; CHECK-NEXT: DW_AT_name {{.*}}"top"
Expand All @@ -14,6 +15,7 @@
; CHECK-NOT: DW_AT_name {{.*}}"top"
;
; RUN: llc -O0 -o - %s | FileCheck %s -check-prefix=ASM
; RUN: llc --try-experimental-debuginfo-iterators -O0 -o - %s | FileCheck %s -check-prefix=ASM
;
; ASM: [[TOP_LOW_PC:[.0-9a-zA-Z]+]]:{{[[:space:]].*}}DEBUG_LABEL: foo:top
; ASM: [[DONE_LOW_PC:[.0-9a-zA-Z]+]]:{{[[:space:]].*}}DEBUG_LABEL: foo:done
Expand Down
1 change: 1 addition & 0 deletions llvm/test/DebugInfo/X86/debug-label-unreached.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; Test unreachable llvm.dbg.label
;
; RUN: llc -filetype=obj -split-dwarf-file debug.dwo -mtriple=x86_64-unknown-linux-gnu -o - %s | llvm-dwarfdump -v - | FileCheck %s
; RUN: llc --try-experimental-debuginfo-iterators -filetype=obj -split-dwarf-file debug.dwo -mtriple=x86_64-unknown-linux-gnu -o - %s | llvm-dwarfdump -v - | FileCheck %s
;
; CHECK: .debug_info.dwo contents:
; CHECK: DW_TAG_label
Expand Down
12 changes: 12 additions & 0 deletions llvm/test/DebugInfo/X86/live-debug-vars-nodebug.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
; RUN: -experimental-debug-variable-locations \
; RUN: | FileCheck %s --check-prefix=EXPER-INPUT

; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \
; RUN: --try-experimental-debuginfo-iterators \
; RUN: | FileCheck %s --check-prefix=EXPER-INPUT

; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-after=livedebugvars \
; RUN: | FileCheck %s --check-prefix=OUTPUT

; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-after=livedebugvars \
; RUN: -experimental-debug-variable-locations \
; RUN: | FileCheck %s --check-prefix=OUTPUT

; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-after=livedebugvars \
; RUN: --try-experimental-debuginfo-iterators \
; RUN: | FileCheck %s --check-prefix=OUTPUT

; This test checks that LiveDebugVariables strips all debug instructions
; from nodebug functions. Such instructions occur when a function with debug
; info is inlined into a nodebug function.
Expand All @@ -25,6 +33,10 @@
; verifies that a DBG_INSTR_REF is emitted by the option, and that it is also
; stripped.

; Repeat the test with --try-experimental-debuginfo-iterators, which tells
; llvm to use non-instruction representation for debug info that is currently
; tracked using debug intrinsics.

; Generated from:
;
; extern int foobar();
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/HotColdSplit/split-out-dbg-label.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt -passes=hotcoldsplit -hotcoldsplit-threshold=0 -S < %s | FileCheck %s
; RUN: opt --try-experimental-debuginfo-iterators -passes=hotcoldsplit -hotcoldsplit-threshold=0 -S < %s | FileCheck %s

; When an llvm.dbg.label intrinsic is extracted into a new function, make sure
; that its metadata argument is a DILabel that points to a scope within the new
Expand Down
1 change: 1 addition & 0 deletions llvm/test/Transforms/SimplifyCFG/bbi-23595.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s
; RUN: opt --try-experimental-debuginfo-iterators < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s

; In 'simplifycfg', during the flattening of a 'br', the instructions for the
; 'true' and 'false' parts, are moved out from their respective basic blocks.
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/Transforms/SpeculativeExecution/PR46267.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
; RUN: opt < %s -S -passes='speculative-execution' | FileCheck %s
;; FXIME: RemoveDIs not supported in speculative-execution
; run: opt --try-experimental-debuginfo-iterators < %s -S -passes='speculative-execution' | FileCheck %s

%class.B = type { ptr }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
; RUN: opt -S -passes=strip-nonlinetable-debuginfo %s -o - | FileCheck %s
; RUN: opt --try-experimental-debuginfo-iterators -S -passes=strip-nonlinetable-debuginfo %s -o - | FileCheck %s
; CHECK: define void @f()
define void @f() !dbg !4 {
entry:
Expand Down