1; RUN: opt -passes=openmp-opt -debug-only=openmp-opt -disable-output < %s 2>&1 | FileCheck %s
2; RUN: opt -passes=openmp-opt -pass-remarks-analysis=openmp-opt -disable-output < %s 2>&1 | FileCheck %s --check-prefix=REMARKS
3; REQUIRES: asserts
4; ModuleID = 'single_threaded_exeuction.c'
5
6%struct.ident_t = type { i32, i32, i32, i32, i8* }
7
8@0 = private unnamed_addr constant [1 x i8] c"\00", align 1
9@1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @0, i32 0, i32 0) }, align 8
10
11
12; CHECK-NOT: [openmp-opt] Basic block @kernel entry is executed by a single thread.
13; CHECK: [openmp-opt] Basic block @kernel if.then is executed by a single thread.
14; CHECK-NOT: [openmp-opt] Basic block @kernel if.else is executed by a single thread.
15; CHECK-NOT: [openmp-opt] Basic block @kernel if.end is executed by a single thread.
16define void @kernel() {
17  %call = call i32 @__kmpc_target_init(%struct.ident_t* nonnull @1, i8 1, i1 false, i1 false)
18  %cmp = icmp eq i32 %call, -1
19  br i1 %cmp, label %if.then, label %if.else
20if.then:
21  br label %if.end
22if.else:
23  br label %if.end
24if.end:
25  call void @__kmpc_target_deinit(%struct.ident_t* null, i8 1, i1 true)
26  ret void
27}
28
29; REMARKS: remark: single_threaded_execution.c:1:0: Could not internalize function. Some optimizations may not be possible.
30; REMARKS-NOT: remark: single_threaded_execution.c:1:0: Could not internalize function. Some optimizations may not be possible.
31
32; CHECK-NOT: [openmp-opt] Basic block @nvptx entry is executed by a single thread.
33; CHECK-DAG: [openmp-opt] Basic block @nvptx if.then is executed by a single thread.
34; CHECK-NOT: [openmp-opt] Basic block @nvptx if.end is executed by a single thread.
35; Function Attrs: noinline
36define void @nvptx() {
37entry:
38  %call = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
39  %cmp = icmp eq i32 %call, 0
40  br i1 %cmp, label %if.then, label %if.end
41
42if.then:
43  call void @foo()
44  call void @bar()
45  call void @baz()
46  call void @cold()
47  br label %if.end
48
49if.end:
50  ret void
51}
52
53; CHECK-NOT: [openmp-opt] Basic block @amdgcn entry is executed by a single thread.
54; CHECK-DAG: [openmp-opt] Basic block @amdgcn if.then is executed by a single thread.
55; CHECK-NOT: [openmp-opt] Basic block @amdgcn if.end is executed by a single thread.
56; Function Attrs: noinline
57define void @amdgcn() {
58entry:
59  %call = call i32 @llvm.amdgcn.workitem.id.x()
60  %cmp = icmp eq i32 %call, 0
61  br i1 %cmp, label %if.then, label %if.end
62
63if.then:
64  call void @foo()
65  call void @bar()
66  call void @baz()
67  call void @cold()
68  br label %if.end
69
70if.end:
71  ret void
72}
73
74; CHECK: [openmp-opt] Basic block @foo entry is executed by a single thread.
75; Function Attrs: noinline
76define internal void @foo() {
77entry:
78  ret void
79}
80
81; CHECK: [openmp-opt] Basic block @bar.internalized entry is executed by a single thread.
82; Function Attrs: noinline
83define void @bar() {
84entry:
85  ret void
86}
87
88; CHECK-NOT: [openmp-opt] Basic block @baz entry is executed by a single thread.
89; Function Attrs: noinline
90define weak void @baz() !dbg !8 {
91entry:
92  ret void
93}
94
95; CHECK-NOT: [openmp-opt] Basic block @cold entry is executed by a single thread.
96; Function Attrs: cold convergent noinline nounwind optnone mustprogress
97define weak void @cold() #0 !dbg !9 {
98entry:
99  ret void
100}
101
102declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
103
104declare i32 @llvm.amdgcn.workitem.id.x()
105
106declare void @__kmpc_kernel_prepare_parallel(i8*)
107
108declare i32 @__kmpc_target_init(%struct.ident_t*, i8, i1, i1)
109
110declare void @__kmpc_target_deinit(%struct.ident_t*, i8, i1)
111
112attributes #0 = { cold noinline }
113
114!llvm.dbg.cu = !{!0}
115!llvm.module.flags = !{!3, !4, !5, !6}
116!nvvm.annotations = !{!7}
117
118!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 12.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
119!1 = !DIFile(filename: "single_threaded_execution.c", directory: "/tmp/single_threaded_execution.c")
120!2 = !{}
121!3 = !{i32 2, !"Debug Info Version", i32 3}
122!4 = !{i32 1, !"wchar_size", i32 4}
123!5 = !{i32 7, !"openmp", i32 50}
124!6 = !{i32 7, !"openmp-device", i32 50}
125!7 = !{void ()* @kernel, !"kernel", i32 1}
126!8 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 8, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
127!9 = distinct !DISubprogram(name: "cold", scope: !1, file: !1, line: 8, type: !10, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
128!10 = !DISubroutineType(types: !2)
129