1 ; RUN: opt -passes=hotcoldsplit -hotcoldsplit-threshold=0 -S < %s | FileCheck %s
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.14.0"
6 ; The block "if.end" in @foo is extracted into a new function, @foo.cold.1.
9 ; CHECK-LABEL: define {{.*}}@foo.cold.1
11 ; - The llvm.dbg.value intrinsic pointing to an argument in @foo (%arg1) is
13 ; CHECK-NOT: #dbg_value
15 ; - Instructions without locations in the original function have no
16 ; location in the new function
17 ; CHECK: [[ADD1:%.*]] = add i32 %{{.*}}, 1{{$}}
19 ; - Ditto (see above), calls are not special
20 ; CHECK-NEXT: call void @sink(i32 [[ADD1]])
22 ; - Line locations are preserved
23 ; CHECK-NEXT: call void @sink(i32 [[ADD1]]), !dbg [[LINE1:![0-9]+]]
25 ; - llvm.dbg.value intrinsics for values local to @foo.cold.1 are preserved
26 ; CHECK-NEXT: #dbg_value(i32 [[ADD1]], [[VAR1:![0-9]+]], !DIExpression(), [[LINE1]]
28 ; - Expressions inside of dbg.value intrinsics are preserved
29 ; CHECK-NEXT: #dbg_value(i32 [[ADD1]], [[VAR1]], !DIExpression(DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value)
31 ; CHECK-NEXT: call void @sink(i32 [[ADD1]]), !dbg [[LINE2:![0-9]+]]
32 ; CHECK-NEXT: call void @sink(i32 [[ADD1]]), !dbg [[LINE3:![0-9]+]]
34 ; CHECK-NEXT: #dbg_value(i32 [[ADD1]]
35 ; CHECK-SAME: [[VAR_FROM_INLINE_ME:![0-9]+]]
36 ; CHECK-SAME: [[LINE2]]
38 ; CHECK-NEXT: #dbg_value(i32 [[ADD1]]
39 ; CHECK-SAME: [[VAR2:![0-9]+]]
40 ; CHECK-SAME: [[LINE4:![0-9]+]]
43 ; - The DISubprogram for @foo.cold.1 has an empty DISubroutineType
44 ; CHECK: [[FILE:![0-9]+]] = !DIFile(filename: "<stdin>"
45 ; CHECK: [[EMPTY_MD:![0-9]+]] = !{}
46 ; CHECK: [[EMPTY_TYPE:![0-9]+]] = !DISubroutineType(types: [[EMPTY_MD]])
47 ; CHECK: [[INLINE_ME_SCOPE:![0-9]+]] = distinct !DISubprogram(name: "inline_me"
48 ; CHECK: [[NEWSCOPE:![0-9]+]] = distinct !DISubprogram(name: "foo.cold.1", linkageName: "foo.cold.1", scope: null, file: [[FILE]], type: [[EMPTY_TYPE]], spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized
50 ; - Line locations in @foo.cold.1 point to the new scope for @foo.cold.1
51 ; CHECK: [[LINE1]] = !DILocation(line: 1, column: 1, scope: [[NEWSCOPE]])
53 ; CHECK: [[LINE2]] = !DILocation(line: 2, column: 2, scope: [[INLINE_ME_SCOPE]]
54 ; CHECK-SAME: inlinedAt: [[LINE3]]
55 ; CHECK: [[LINE3]] = !DILocation(line: 3, column: 3, scope: [[INLINED_SCOPE1:![0-9]*]]
56 ; CHECK: [[INLINED_SCOPE1]] = !DILexicalBlock(scope: [[INLINED_SCOPE2:![0-9]*]], file: [[FILE]], line: 4, column: 4)
57 ; CHECK: [[INLINED_SCOPE2]] = !DILexicalBlock(scope: [[NEWSCOPE]], file: [[FILE]], line: 5, column: 5)
59 ; CHECK: [[VAR_FROM_INLINE_ME]] = !DILocalVariable(name: "var_from_inline_me",
60 ; CHECK-SAME: scope: [[INLINE_ME_SCOPE]]
62 ; CHECK: [[VAR2]] = !DILocalVariable(name: "var_from_scope_in_foo",
63 ; CHECK-SAME: scope: [[NEWSCOPE2:![0-9]+]]
64 ; CHECK: [[NEWSCOPE2]] = !DILexicalBlock(scope: [[NEWSCOPE]], file: [[FILE]], line: 7, column: 7)
65 ; CHECK: [[LINE4]] = !DILocation(line: 6, column: 6, scope: [[NEWSCOPE2]]
67 define void @foo(i32 %arg1) !dbg !6 {
69 %var = add i32 0, 0, !dbg !11
70 br i1 undef, label %if.then, label %if.end
72 if.then: ; preds = %entry
75 if.end: ; preds = %entry
76 call void @llvm.dbg.value(metadata i32 %arg1, metadata !9, metadata !DIExpression()), !dbg !11
77 %add1 = add i32 %arg1, 1
78 call void @sink(i32 %add1)
79 call void @sink(i32 %add1), !dbg !11
80 call void @llvm.dbg.value(metadata i32 %add1, metadata !9, metadata !DIExpression()), !dbg !11
81 call void @llvm.dbg.value(metadata i32 %add1, metadata !9, metadata !DIExpression(DW_OP_constu, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !11
82 call void @sink(i32 %add1), !dbg !13 ; inlined from @inline_me
83 call void @sink(i32 %add1), !dbg !14 ; not inlined, but inside some scope of foo
84 call void @llvm.dbg.value(metadata i32 %add1, metadata !17, metadata !DIExpression()), !dbg !13 ; variable from @inline_me, should preserve scope in !17.
85 call void @llvm.dbg.value(metadata i32 %add1, metadata !18, metadata !DIExpression()), !dbg !19 ; variable not inlined, but inside some scope of foo
89 declare void @llvm.dbg.value(metadata, metadata, metadata)
91 declare void @sink(i32) cold
93 define void @inline_me() !dbg !12{
98 !llvm.debugify = !{!3, !4}
99 !llvm.module.flags = !{!5}
101 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
102 !1 = !DIFile(filename: "<stdin>", directory: "/")
106 !5 = !{i32 2, !"Debug Info Version", i32 3}
107 !6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8)
108 !7 = !DISubroutineType(types: !2)
110 !9 = !DILocalVariable(name: "1", scope: !6, file: !1, line: 1, type: !10)
111 !10 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
112 !11 = !DILocation(line: 1, column: 1, scope: !6)
113 !12 = distinct !DISubprogram(name: "inline_me", linkageName: "inline_me", scope: null, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !8)
114 !13 = !DILocation(line: 2, column: 2, scope: !12, inlinedAt: !14)
115 !14 = !DILocation(line: 3, column: 3, scope: !15)
116 !15 = distinct !DILexicalBlock(scope: !16, file: !1, line: 4, column: 4)
117 !16 = distinct !DILexicalBlock(scope: !6, file: !1, line: 5, column: 5)
118 !17 = !DILocalVariable(name: "var_from_inline_me", scope: !12, file: !1, line: 1, type: !10)
119 !18 = !DILocalVariable(name: "var_from_scope_in_foo", scope: !20, file: !1, line: 1, type: !10)
120 !19 = !DILocation(line: 6, column: 6, scope: !20)
121 !20 = distinct !DILexicalBlock(scope: !6, file: !1, line: 7, column: 7)