2015-06-10 06:10:29 +08:00
|
|
|
; Check that LoopSimplify creates debug locations in synthesized basic blocks.
|
|
|
|
; RUN: opt -loop-simplify %s -S -o - | FileCheck %s
|
|
|
|
|
|
|
|
%union.anon = type { i32 }
|
|
|
|
%"Length" = type <{ %union.anon, i8, i8, i8, i8 }>
|
|
|
|
declare void @bar(%"Length"*) #3
|
|
|
|
@catchtypeinfo = external unnamed_addr constant { i8*, i8*, i8* }
|
|
|
|
declare i32 @__gxx_personality_v0(...)
|
|
|
|
declare void @f1()
|
|
|
|
declare void @f2()
|
|
|
|
declare void @f3()
|
|
|
|
|
|
|
|
; CHECK-LABEL: @foo
|
|
|
|
; CHECK: for.body.preheader:
|
|
|
|
; CHECK-NEXT: br label %for.body, !dbg [[PREHEADER_LOC:![0-9]+]]
|
|
|
|
; CHECK: for.end.loopexit:
|
|
|
|
; CHECK-NEXT: br label %for.end, !dbg [[LOOPEXIT_LOC:![0-9]+]]
|
|
|
|
|
2015-11-06 06:03:56 +08:00
|
|
|
define linkonce_odr hidden void @foo(%"Length"* %begin, %"Length"* %end) nounwind ssp uwtable align 2 !dbg !6 {
|
2015-06-10 06:10:29 +08:00
|
|
|
entry:
|
|
|
|
%cmp.4 = icmp eq %"Length"* %begin, %end, !dbg !7
|
|
|
|
br i1 %cmp.4, label %for.end, label %for.body, !dbg !8
|
|
|
|
|
|
|
|
for.body: ; preds = %entry, %length.exit
|
|
|
|
%begin.sink5 = phi %"Length"* [ %incdec.ptr, %length.exit ], [ %begin, %entry ]
|
2017-07-29 04:21:02 +08:00
|
|
|
tail call void @llvm.dbg.value(metadata %"Length"* %begin.sink5, metadata !15, metadata !16), !dbg !17
|
2015-06-10 06:10:29 +08:00
|
|
|
%m_type.i.i.i = getelementptr inbounds %"Length", %"Length"* %begin.sink5, i64 0, i32 2, !dbg !9
|
|
|
|
%0 = load i8, i8* %m_type.i.i.i, align 1, !dbg !9
|
|
|
|
%cmp.i.i = icmp eq i8 %0, 9, !dbg !7
|
|
|
|
br i1 %cmp.i.i, label %if.then.i, label %length.exit, !dbg !8
|
|
|
|
|
|
|
|
if.then.i: ; preds = %for.body
|
|
|
|
tail call void @bar(%"Length"* %begin.sink5) #7, !dbg !10
|
|
|
|
br label %length.exit, !dbg !10
|
|
|
|
|
|
|
|
length.exit: ; preds = %for.body, %if.then.i
|
|
|
|
%incdec.ptr = getelementptr inbounds %"Length", %"Length"* %begin.sink5, i64 1, !dbg !11
|
|
|
|
%cmp = icmp eq %"Length"* %incdec.ptr, %end, !dbg !7
|
|
|
|
br i1 %cmp, label %for.end, label %for.body, !dbg !8
|
|
|
|
|
|
|
|
for.end: ; preds = %length.exit, %entry
|
|
|
|
ret void, !dbg !12
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: @with_landingpad
|
|
|
|
; CHECK: catch.preheader:
|
|
|
|
; CHECK: br label %catch, !dbg [[LPAD_PREHEADER_LOC:![0-9]+]]
|
|
|
|
; CHECK: catch.preheader.split-lp:
|
|
|
|
; CHECK: br label %catch, !dbg [[LPAD_PREHEADER_LOC]]
|
|
|
|
|
2015-06-18 04:52:32 +08:00
|
|
|
define void @with_landingpad() uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
|
2015-06-10 06:10:29 +08:00
|
|
|
entry:
|
|
|
|
invoke void @f1() to label %try.cont19 unwind label %catch, !dbg !13
|
|
|
|
|
|
|
|
catch: ; preds = %if.else, %entry
|
2015-06-18 04:52:32 +08:00
|
|
|
%0 = landingpad { i8*, i32 }
|
2015-06-10 06:10:29 +08:00
|
|
|
catch i8* bitcast ({ i8*, i8*, i8* }* @catchtypeinfo to i8*), !dbg !13
|
|
|
|
invoke void @f3() to label %if.else unwind label %eh.resume, !dbg !13
|
|
|
|
|
|
|
|
if.else: ; preds = %catch
|
|
|
|
invoke void @f2() to label %try.cont19 unwind label %catch, !dbg !13
|
|
|
|
|
|
|
|
try.cont19: ; preds = %if.else, %entry
|
|
|
|
ret void, !dbg !13
|
|
|
|
|
|
|
|
eh.resume: ; preds = %catch
|
2015-06-18 04:52:32 +08:00
|
|
|
%1 = landingpad { i8*, i32 }
|
2015-06-10 06:10:29 +08:00
|
|
|
cleanup catch i8* bitcast ({ i8*, i8*, i8* }* @catchtypeinfo to i8*), !dbg !13
|
|
|
|
resume { i8*, i32 } undef, !dbg !13
|
|
|
|
}
|
|
|
|
|
[BasicBlockUtils] Use getFirstNonPHIOrDbg to set debugloc for instructions created in SplitBlockPredecessors
Summary:
When setting debugloc for instructions created in SplitBlockPredecessors, current implementation copies debugloc from the first-non-phi instruction of the original basic block. However, if the first-non-phi instruction is a call for @llvm.dbg.value, the debugloc of the instruction may point the location outside of the block itself. For the example code of
```
1 typedef struct _node_t {
2 struct _node_t *next;
3 } node_t;
4
5 extern node_t *root;
6
7 int foo() {
8 node_t *node, *tmp;
9 int ret = 0;
10
11 node = tmp = root->next;
12 while (node != root) {
13 while (node) {
14 tmp = node;
15 node = node->next;
16 ret++;
17 }
18 }
19
20 return ret;
21 }
```
, below is the basicblock corresponding to line 12 after Reassociate expressions pass:
```
while.cond: ; preds = %while.cond2, %entry
%node.0 = phi %struct._node_t* [ %1, %entry ], [ null, %while.cond2 ]
%ret.0 = phi i32 [ 0, %entry ], [ %ret.1, %while.cond2 ]
tail call void @llvm.dbg.value(metadata i32 %ret.0, i64 0, metadata !19, metadata !20), !dbg !21
tail call void @llvm.dbg.value(metadata %struct._node_t* %node.0, i64 0, metadata !11, metadata !20), !dbg !31
%cmp = icmp eq %struct._node_t* %node.0, %0, !dbg !33
br i1 %cmp, label %while.end5, label %while.cond2, !dbg !35
```
As you can see, the first-non-phi instruction is a call for @llvm.dbg.value, and the debugloc is
```
!21 = !DILocation(line: 9, column: 7, scope: !6)
```
, which is a definition of 'ret' variable and outside of the scope of the basicblock itself. However, current implementation picks up this debugloc for the instructions created in SplitBlockPredecessors. This patch addresses this problem by picking up debugloc from the first-non-phi-non-dbg instruction.
Reviewers: dblaikie, samsonov, eugenis
Reviewed By: eugenis
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29867
llvm-svn: 295106
2017-02-15 05:10:40 +08:00
|
|
|
; Function Attrs: nounwind readnone
|
2017-07-29 04:21:02 +08:00
|
|
|
declare void @llvm.dbg.value(metadata, metadata, metadata)
|
[BasicBlockUtils] Use getFirstNonPHIOrDbg to set debugloc for instructions created in SplitBlockPredecessors
Summary:
When setting debugloc for instructions created in SplitBlockPredecessors, current implementation copies debugloc from the first-non-phi instruction of the original basic block. However, if the first-non-phi instruction is a call for @llvm.dbg.value, the debugloc of the instruction may point the location outside of the block itself. For the example code of
```
1 typedef struct _node_t {
2 struct _node_t *next;
3 } node_t;
4
5 extern node_t *root;
6
7 int foo() {
8 node_t *node, *tmp;
9 int ret = 0;
10
11 node = tmp = root->next;
12 while (node != root) {
13 while (node) {
14 tmp = node;
15 node = node->next;
16 ret++;
17 }
18 }
19
20 return ret;
21 }
```
, below is the basicblock corresponding to line 12 after Reassociate expressions pass:
```
while.cond: ; preds = %while.cond2, %entry
%node.0 = phi %struct._node_t* [ %1, %entry ], [ null, %while.cond2 ]
%ret.0 = phi i32 [ 0, %entry ], [ %ret.1, %while.cond2 ]
tail call void @llvm.dbg.value(metadata i32 %ret.0, i64 0, metadata !19, metadata !20), !dbg !21
tail call void @llvm.dbg.value(metadata %struct._node_t* %node.0, i64 0, metadata !11, metadata !20), !dbg !31
%cmp = icmp eq %struct._node_t* %node.0, %0, !dbg !33
br i1 %cmp, label %while.end5, label %while.cond2, !dbg !35
```
As you can see, the first-non-phi instruction is a call for @llvm.dbg.value, and the debugloc is
```
!21 = !DILocation(line: 9, column: 7, scope: !6)
```
, which is a definition of 'ret' variable and outside of the scope of the basicblock itself. However, current implementation picks up this debugloc for the instructions created in SplitBlockPredecessors. This patch addresses this problem by picking up debugloc from the first-non-phi-non-dbg instruction.
Reviewers: dblaikie, samsonov, eugenis
Reviewed By: eugenis
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29867
llvm-svn: 295106
2017-02-15 05:10:40 +08:00
|
|
|
|
2015-06-10 06:10:29 +08:00
|
|
|
; CHECK-DAG: [[PREHEADER_LOC]] = !DILocation(line: 73, column: 27, scope: !{{[0-9]+}})
|
|
|
|
; CHECK-DAG: [[LOOPEXIT_LOC]] = !DILocation(line: 75, column: 9, scope: !{{[0-9]+}})
|
|
|
|
; CHECK-DAG: [[LPAD_PREHEADER_LOC]] = !DILocation(line: 85, column: 1, scope: !{{[0-9]+}})
|
|
|
|
|
|
|
|
!llvm.module.flags = !{!0, !1, !2}
|
2016-04-06 07:37:08 +08:00
|
|
|
!llvm.dbg.cu = !{!14}
|
2015-06-10 06:10:29 +08:00
|
|
|
!0 = !{i32 2, !"Dwarf Version", i32 4}
|
|
|
|
!1 = !{i32 2, !"Debug Info Version", i32 3}
|
|
|
|
!2 = !{i32 1, !"PIC Level", i32 2}
|
|
|
|
|
|
|
|
!3 = !{}
|
|
|
|
!4 = !DISubroutineType(types: !3)
|
|
|
|
!5 = !DIFile(filename: "Vector.h", directory: "/tmp")
|
[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
|
|
|
!6 = distinct !DISubprogram(name: "destruct", scope: !5, file: !5, line: 71, type: !4, isLocal: false, isDefinition: true, scopeLine: 72, flags: DIFlagPrototyped, isOptimized: false, unit: !14, retainedNodes: !3)
|
2015-06-10 06:10:29 +08:00
|
|
|
!7 = !DILocation(line: 73, column: 38, scope: !6)
|
|
|
|
!8 = !DILocation(line: 73, column: 13, scope: !6)
|
|
|
|
!9 = !DILocation(line: 73, column: 27, scope: !6)
|
|
|
|
!10 = !DILocation(line: 74, column: 17, scope: !6)
|
|
|
|
!11 = !DILocation(line: 73, column: 46, scope: !6)
|
|
|
|
!12 = !DILocation(line: 75, column: 9, scope: !6)
|
|
|
|
!13 = !DILocation(line: 85, column: 1, scope: !6)
|
2016-04-06 07:37:08 +08:00
|
|
|
!14 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
|
|
|
|
file: !5,
|
|
|
|
isOptimized: true, flags: "-O2",
|
2016-04-15 23:57:41 +08:00
|
|
|
splitDebugFilename: "abc.debug", emissionKind: 2)
|
[BasicBlockUtils] Use getFirstNonPHIOrDbg to set debugloc for instructions created in SplitBlockPredecessors
Summary:
When setting debugloc for instructions created in SplitBlockPredecessors, current implementation copies debugloc from the first-non-phi instruction of the original basic block. However, if the first-non-phi instruction is a call for @llvm.dbg.value, the debugloc of the instruction may point the location outside of the block itself. For the example code of
```
1 typedef struct _node_t {
2 struct _node_t *next;
3 } node_t;
4
5 extern node_t *root;
6
7 int foo() {
8 node_t *node, *tmp;
9 int ret = 0;
10
11 node = tmp = root->next;
12 while (node != root) {
13 while (node) {
14 tmp = node;
15 node = node->next;
16 ret++;
17 }
18 }
19
20 return ret;
21 }
```
, below is the basicblock corresponding to line 12 after Reassociate expressions pass:
```
while.cond: ; preds = %while.cond2, %entry
%node.0 = phi %struct._node_t* [ %1, %entry ], [ null, %while.cond2 ]
%ret.0 = phi i32 [ 0, %entry ], [ %ret.1, %while.cond2 ]
tail call void @llvm.dbg.value(metadata i32 %ret.0, i64 0, metadata !19, metadata !20), !dbg !21
tail call void @llvm.dbg.value(metadata %struct._node_t* %node.0, i64 0, metadata !11, metadata !20), !dbg !31
%cmp = icmp eq %struct._node_t* %node.0, %0, !dbg !33
br i1 %cmp, label %while.end5, label %while.cond2, !dbg !35
```
As you can see, the first-non-phi instruction is a call for @llvm.dbg.value, and the debugloc is
```
!21 = !DILocation(line: 9, column: 7, scope: !6)
```
, which is a definition of 'ret' variable and outside of the scope of the basicblock itself. However, current implementation picks up this debugloc for the instructions created in SplitBlockPredecessors. This patch addresses this problem by picking up debugloc from the first-non-phi-non-dbg instruction.
Reviewers: dblaikie, samsonov, eugenis
Reviewed By: eugenis
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D29867
llvm-svn: 295106
2017-02-15 05:10:40 +08:00
|
|
|
!15 = !DILocalVariable(name: "begin", arg: 1, scope: !6, file: !5, line: 71)
|
|
|
|
!16 = !DIExpression()
|
|
|
|
!17 = !DILocation(line: 71, column: 32, scope: !6)
|