2013-05-01 01:08:16 +08:00
; RUN: opt -inline -S < %s | FileCheck %s
;
; A hand-edited version of inline-debug-info.ll to test inlining of a
; function with multiple returns.
;
; Make sure the branch instructions created during inlining has a debug location,
; so the range of the inlined function is correct.
; CHECK: br label %_Z4testi.exit, !dbg ![[MD:[0-9]+]]
; CHECK: br label %_Z4testi.exit, !dbg ![[MD]]
; CHECK: br label %invoke.cont, !dbg ![[MD]]
; The branch instruction has the source location of line 9 and its inlined location
; has the source location of line 14.
2015-04-30 00:38:44 +08:00
; CHECK: ![[INL:[0-9]+]] = distinct !DILocation(line: 14, scope: {{.*}})
; CHECK: ![[MD]] = !DILocation(line: 9, scope: {{.*}}, inlinedAt: ![[INL]])
2013-05-01 01:08:16 +08:00
; ModuleID = 'test.cpp'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin12.0.0"
@_ZTIi = external constant i8 *
@global_var = external global i32
; copy of above function with multiple returns
2015-11-06 06:03:56 +08:00
define i32 @_Z4testi ( i32 %k ) !dbg !4 {
2013-05-01 01:08:16 +08:00
entry:
%retval = alloca i32 , align 4
%k.addr = alloca i32 , align 4
%k2 = alloca i32 , align 4
store i32 %k , i32 * %k.addr , align 4
2015-04-30 00:38:44 +08:00
call void @llvm.dbg.declare ( metadata i32 * %k.addr , metadata !13 , metadata !DIExpression ( ) ) , !dbg !14
call void @llvm.dbg.declare ( metadata i32 * %k2 , metadata !15 , metadata !DIExpression ( ) ) , !dbg !16
2015-02-28 05:17:42 +08:00
%0 = load i32 , i32 * %k.addr , align 4 , !dbg !16
2013-05-01 01:08:16 +08:00
%call = call i32 @_Z8test_exti ( i32 %0 ) , !dbg !16
store i32 %call , i32 * %k2 , align 4 , !dbg !16
2015-02-28 05:17:42 +08:00
%1 = load i32 , i32 * %k2 , align 4 , !dbg !17
2013-05-01 01:08:16 +08:00
%cmp = icmp sgt i32 %1 , 100 , !dbg !17
br i1 %cmp , label %if.then , label %if.end , !dbg !17
if.then: ; preds = %entry
2015-02-28 05:17:42 +08:00
%2 = load i32 , i32 * %k2 , align 4 , !dbg !18
2013-05-01 01:08:16 +08:00
store i32 %2 , i32 * %retval , !dbg !18
br label %return , !dbg !18
if.end: ; preds = %entry
store i32 0 , i32 * %retval , !dbg !19
2015-02-28 05:17:42 +08:00
%3 = load i32 , i32 * %retval , !dbg !20 ; hand-edited
2013-05-01 01:08:16 +08:00
ret i32 %3 , !dbg !20 ; hand-edited
return: ; preds = %if.end, %if.then
2015-02-28 05:17:42 +08:00
%4 = load i32 , i32 * %retval , !dbg !20
2013-05-01 01:08:16 +08:00
ret i32 %4 , !dbg !20
}
; Function Attrs: nounwind readnone
Move the complex address expression out of DIVariable and into an extra
argument of the llvm.dbg.declare/llvm.dbg.value intrinsics.
Previously, DIVariable was a variable-length field that has an optional
reference to a Metadata array consisting of a variable number of
complex address expressions. In the case of OpPiece expressions this is
wasting a lot of storage in IR, because when an aggregate type is, e.g.,
SROA'd into all of its n individual members, the IR will contain n copies
of the DIVariable, all alike, only differing in the complex address
reference at the end.
By making the complex address into an extra argument of the
dbg.value/dbg.declare intrinsics, all of the pieces can reference the
same variable and the complex address expressions can be uniqued across
the CU, too.
Down the road, this will allow us to move other flags, such as
"indirection" out of the DIVariable, too.
The new intrinsics look like this:
declare void @llvm.dbg.declare(metadata %storage, metadata %var, metadata %expr)
declare void @llvm.dbg.value(metadata %storage, i64 %offset, metadata %var, metadata %expr)
This patch adds a new LLVM-local tag to DIExpressions, so we can detect
and pretty-print DIExpression metadata nodes.
What this patch doesn't do:
This patch does not touch the "Indirect" field in DIVariable; but moving
that into the expression would be a natural next step.
http://reviews.llvm.org/D4919
rdar://problem/17994491
Thanks to dblaikie and dexonsmith for reviewing this patch!
Note: I accidentally committed a bogus older version of this patch previously.
llvm-svn: 218787
2014-10-02 02:55:02 +08:00
declare void @llvm.dbg.declare ( metadata , metadata , metadata ) #1
2013-05-01 01:08:16 +08:00
declare i32 @_Z8test_exti ( i32 )
2015-11-06 06:03:56 +08:00
define i32 @_Z5test2v ( ) personality i8 * bitcast ( i32 ( . . . ) * @__gxx_personality_v0 to i8 * ) !dbg !10 {
2013-05-01 01:08:16 +08:00
entry:
%exn.slot = alloca i8 *
%ehselector.slot = alloca i32
%e = alloca i32 , align 4
2015-02-28 05:17:42 +08:00
%0 = load i32 , i32 * @global_var , align 4 , !dbg !21
2013-05-01 01:08:16 +08:00
%call = invoke i32 @_Z4testi ( i32 %0 )
to label %invoke.cont unwind label %lpad , !dbg !21
invoke.cont: ; preds = %entry
br label %try.cont , !dbg !23
lpad: ; preds = %entry
2015-06-18 04:52:32 +08:00
%1 = landingpad { i8 * , i32 }
2013-05-01 01:08:16 +08:00
catch i8 * bitcast ( i8 * * @_ZTIi to i8 * ) , !dbg !21
%2 = extractvalue { i8 * , i32 } %1 , 0 , !dbg !21
store i8 * %2 , i8 * * %exn.slot , !dbg !21
%3 = extractvalue { i8 * , i32 } %1 , 1 , !dbg !21
store i32 %3 , i32 * %ehselector.slot , !dbg !21
br label %catch.dispatch , !dbg !21
catch.dispatch: ; preds = %lpad
2015-02-28 05:17:42 +08:00
%sel = load i32 , i32 * %ehselector.slot , !dbg !23
2013-05-01 01:08:16 +08:00
%4 = call i32 @llvm.eh.typeid.for ( i8 * bitcast ( i8 * * @_ZTIi to i8 * ) ) #2 , !dbg !23
%matches = icmp eq i32 %sel , %4 , !dbg !23
br i1 %matches , label %catch , label %eh.resume , !dbg !23
catch: ; preds = %catch.dispatch
2015-04-30 00:38:44 +08:00
call void @llvm.dbg.declare ( metadata i32 * %e , metadata !24 , metadata !DIExpression ( ) ) , !dbg !25
2015-02-28 05:17:42 +08:00
%exn = load i8 * , i8 * * %exn.slot , !dbg !23
2013-05-01 01:08:16 +08:00
%5 = call i8 * @__cxa_begin_catch ( i8 * %exn ) #2 , !dbg !23
%6 = bitcast i8 * %5 to i32 * , !dbg !23
2015-02-28 05:17:42 +08:00
%7 = load i32 , i32 * %6 , align 4 , !dbg !23
2013-05-01 01:08:16 +08:00
store i32 %7 , i32 * %e , align 4 , !dbg !23
store i32 0 , i32 * @global_var , align 4 , !dbg !26
call void @__cxa_end_catch ( ) #2 , !dbg !28
br label %try.cont , !dbg !28
try.cont: ; preds = %catch, %invoke.cont
store i32 1 , i32 * @global_var , align 4 , !dbg !29
ret i32 0 , !dbg !30
eh.resume: ; preds = %catch.dispatch
2015-02-28 05:17:42 +08:00
%exn1 = load i8 * , i8 * * %exn.slot , !dbg !23
%sel2 = load i32 , i32 * %ehselector.slot , !dbg !23
2013-05-01 01:08:16 +08:00
%lpad.val = insertvalue { i8 * , i32 } undef , i8 * %exn1 , 0 , !dbg !23
%lpad.val3 = insertvalue { i8 * , i32 } %lpad.val , i32 %sel2 , 1 , !dbg !23
resume { i8 * , i32 } %lpad.val3 , !dbg !23
}
declare i32 @__gxx_personality_v0 ( . . . )
; Function Attrs: nounwind readnone
declare i32 @llvm.eh.typeid.for ( i8 * ) #1
declare i8 * @__cxa_begin_catch ( i8 * )
declare void @__cxa_end_catch ( )
attributes #1 = { nounwind readnone }
attributes #2 = { nounwind }
!llvm.dbg.cu = ! { !0 }
2013-11-23 05:49:45 +08:00
!llvm.module.flags = ! { !31 }
2013-05-01 01:08:16 +08:00
2016-04-15 23:57:41 +08:00
!0 = distinct !DICompileUnit ( language: D W _ L A N G _ C _ p l u s _ p l u s , producer: "clang version 3.3 " , isOptimized: false , emissionKind: F u l l D e b u g , file: !1 , enums: !2 , retainedTypes: !2 , globals: !2 , imports: !2 )
2015-04-30 00:38:44 +08:00
!1 = !DIFile ( filename: "<unknown>" , directory: "" )
2015-03-28 04:46:33 +08:00
!2 = ! { }
[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 10:40:45 +08:00
!4 = distinct !DISubprogram ( name: "test" , linkageName: "_Z4testi" , line: 4 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , unit: !0 , scopeLine: 4 , file: !5 , scope: !6 , type: !7 , retainedNodes: !2 )
2015-04-30 00:38:44 +08:00
!5 = !DIFile ( filename: "test.cpp" , directory: "" )
!6 = !DIFile ( filename: "test.cpp" , directory: "" )
!7 = !DISubroutineType ( types: !8 )
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
llvm-svn: 224257
2014-12-16 03:07:53 +08:00
!8 = ! { !9 , !9 }
2015-04-30 00:38:44 +08:00
!9 = !DIBasicType ( tag: D W _ T A G _ b a s e _ type , name: "int" , size: 32 , align: 32 , encoding: D W _ A T E _ s i g n e d )
[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 10:40:45 +08:00
!10 = distinct !DISubprogram ( name: "test2" , linkageName: "_Z5test2v" , line: 11 , isLocal: false , isDefinition: true , virtualIndex: 6 , flags: D I F l a g P r o t o t y p e d , isOptimized: false , unit: !0 , scopeLine: 11 , file: !5 , scope: !6 , type: !11 , retainedNodes: !2 )
2015-04-30 00:38:44 +08:00
!11 = !DISubroutineType ( types: !12 )
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
llvm-svn: 224257
2014-12-16 03:07:53 +08:00
!12 = ! { !9 }
2015-08-01 02:58:39 +08:00
!13 = !DILocalVariable ( name: "k" , line: 4 , arg: 1 , scope: !4 , file: !6 , type: !9 )
2015-04-30 00:38:44 +08:00
!14 = !DILocation ( line: 4 , scope: !4 )
2015-08-01 02:58:39 +08:00
!15 = !DILocalVariable ( name: "k2" , line: 5 , scope: !4 , file: !6 , type: !9 )
2015-04-30 00:38:44 +08:00
!16 = !DILocation ( line: 5 , scope: !4 )
!17 = !DILocation ( line: 6 , scope: !4 )
!18 = !DILocation ( line: 7 , scope: !4 )
!19 = !DILocation ( line: 8 , scope: !4 )
!20 = !DILocation ( line: 9 , scope: !4 )
!21 = !DILocation ( line: 14 , scope: !22 )
!22 = distinct !DILexicalBlock ( line: 13 , column: 0 , file: !5 , scope: !10 )
!23 = !DILocation ( line: 15 , scope: !22 )
2015-08-01 02:58:39 +08:00
!24 = !DILocalVariable ( name: "e" , line: 16 , scope: !10 , file: !6 , type: !9 )
2015-04-30 00:38:44 +08:00
!25 = !DILocation ( line: 16 , scope: !10 )
!26 = !DILocation ( line: 17 , scope: !27 )
!27 = distinct !DILexicalBlock ( line: 16 , column: 0 , file: !5 , scope: !10 )
!28 = !DILocation ( line: 18 , scope: !27 )
!29 = !DILocation ( line: 19 , scope: !10 )
!30 = !DILocation ( line: 20 , scope: !10 )
2015-03-04 01:24:31 +08:00
!31 = ! { i32 1 , !"Debug Info Version" , i32 3 }