Files
clang-p2996/llvm/test/CodeGen/MIR/X86/instructions-debug-location.mir
Shiva Chen 2c864551df [DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is

!DILabel(scope: !1, name: "foo", file: !2, line: 3)

We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is

llvm.dbg.label(metadata !1)

It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.

We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.

Differential Revision: https://reviews.llvm.org/D45024

Patch by Hsiangkai Wang.

llvm-svn: 331841
2018-05-09 02:40:45 +00:00

95 lines
3.3 KiB
YAML

# RUN: llc -march=x86-64 -run-pass none -o - %s | FileCheck %s
# This test ensures that the MIR parser parses the machine instruction's
# debug location metadata correctly.
--- |
define i32 @test(i32 %x) #0 !dbg !4 {
entry:
%x.addr = alloca i32, align 4
store i32 %x, i32* %x.addr, align 4
call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !12, metadata !DIExpression()), !dbg !13
%0 = load i32, i32* %x.addr, align 4, !dbg !14
ret i32 %0, !dbg !14
}
define i32 @test_typed_immediates(i32 %x) #0 {
entry:
%x.addr = alloca i32, align 4
store i32 %x, i32* %x.addr, align 4
call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !12, metadata !DIExpression()), !dbg !13
%0 = load i32, i32* %x.addr, align 4, !dbg !14
ret i32 %0, !dbg !14
}
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
attributes #0 = { nounwind "no-frame-pointer-elim"="false" }
attributes #1 = { nounwind readnone }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!9, !10}
!llvm.ident = !{!11}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
!1 = !DIFile(filename: "test.ll", directory: "")
!2 = !{}
!4 = distinct !DISubprogram(name: "test", scope: !5, file: !5, line: 4, type: !6, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
!5 = !DIFile(filename: "test.c", directory: "")
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !8}
!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!9 = !{i32 2, !"Dwarf Version", i32 4}
!10 = !{i32 2, !"Debug Info Version", i32 3}
!11 = !{!"clang version 3.7.0"}
!12 = !DILocalVariable(name: "x", arg: 1, scope: !4, file: !5, line: 4, type: !8)
!13 = !DILocation(line: 4, scope: !4)
!14 = !DILocation(line: 8, scope: !4)
...
---
name: test
tracksRegLiveness: true
registers:
- { id: 0, class: gr32 }
frameInfo:
maxAlignment: 4
stack:
- { id: 0, name: x.addr, size: 4, alignment: 4 }
body: |
bb.0.entry:
liveins: $edi
; CHECK: DBG_VALUE debug-use $noreg, 0, !11, !DIExpression(), debug-location !12
; CHECK: $eax = COPY %0, debug-location !13
; CHECK: RETQ $eax, debug-location !13
%0 = COPY $edi
DBG_VALUE debug-use _, 0, !12, !DIExpression(), debug-location !13
MOV32mr %stack.0.x.addr, 1, _, 0, _, %0
$eax = COPY %0, debug-location !14
RETQ $eax, debug-location !14
...
---
name: test_typed_immediates
tracksRegLiveness: true
registers:
- { id: 0, class: gr32 }
frameInfo:
maxAlignment: 4
stack:
- { id: 0, name: x.addr, size: 4, alignment: 4 }
body: |
bb.0.entry:
liveins: $edi
%0 = COPY $edi
; CHECK: DBG_VALUE $noreg, i32 0, !DIExpression(), !12
; CHECK-NEXT: DBG_VALUE $noreg, i64 -22, !DIExpression(), !12
; CHECK-NEXT: DBG_VALUE $noreg, i128 123492148938512984928424384934328985928, !DIExpression(), !12
DBG_VALUE _, i32 0, !DIExpression(), !13
DBG_VALUE _, i64 -22, !DIExpression(), !13
DBG_VALUE _, i128 123492148938512984928424384934328985928, !DIExpression(), !13
MOV32mr %stack.0.x.addr, 1, _, 0, _, %0
$eax = COPY %0
RETQ $eax
...