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, i1 false, i1 false, i1 false)
18  %cmp = icmp eq i32 %call, -1
19  br i1 %cmp, label %if.then, label %if.else
20if.then:
21  call void @nvptx()
22  call void @amdgcn()
23  br label %if.end
24if.else:
25  br label %if.end
26if.end:
27  call void @__kmpc_target_deinit(%struct.ident_t* null, i1 false, i1 true)
28  ret void
29}
30
31; REMARKS: remark: single_threaded_execution.c:1:0: Could not internalize function. Some optimizations may not be possible.
32; REMARKS-NOT: remark: single_threaded_execution.c:1:0: Could not internalize function. Some optimizations may not be possible.
33
34; CHECK-DAG: [openmp-opt] Basic block @nvptx entry is executed by a single thread.
35; CHECK-DAG: [openmp-opt] Basic block @nvptx if.then is executed by a single thread.
36; CHECK-DAG: [openmp-opt] Basic block @nvptx if.end is executed by a single thread.
37; Function Attrs: noinline
38define internal void @nvptx() {
39entry:
40  br i1 true, 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-DAG: [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-DAG: [openmp-opt] Basic block @amdgcn if.end is executed by a single thread.
56; Function Attrs: noinline
57define internal void @amdgcn() {
58entry:
59  br i1 false, label %if.then, label %if.end
60
61if.then:
62  call void @foo()
63  call void @bar()
64  call void @baz()
65  call void @cold()
66  br label %if.end
67
68if.end:
69  ret void
70}
71
72; CHECK: [openmp-opt] Basic block @foo entry is executed by a single thread.
73; Function Attrs: noinline
74define internal void @foo() {
75entry:
76  ret void
77}
78
79; CHECK: [openmp-opt] Basic block @bar.internalized entry is executed by a single thread.
80; Function Attrs: noinline
81define void @bar() {
82entry:
83  ret void
84}
85
86; CHECK-NOT: [openmp-opt] Basic block @baz entry is executed by a single thread.
87; Function Attrs: noinline
88define weak void @baz() !dbg !8 {
89entry:
90  ret void
91}
92
93; CHECK-NOT: [openmp-opt] Basic block @cold entry is executed by a single thread.
94; Function Attrs: cold convergent noinline nounwind optnone mustprogress
95define weak void @cold() #0 !dbg !9 {
96entry:
97  ret void
98}
99
100declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
101
102declare i32 @llvm.amdgcn.workitem.id.x()
103
104declare void @__kmpc_kernel_prepare_parallel(i8*)
105
106declare i32 @__kmpc_target_init(%struct.ident_t*, i1, i1, i1)
107declare void @__kmpc_target_deinit(%struct.ident_t*, i1, i1)
108
109attributes #0 = { cold noinline }
110
111!llvm.dbg.cu = !{!0}
112!llvm.module.flags = !{!3, !4, !5, !6}
113!nvvm.annotations = !{!7}
114
115!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)
116!1 = !DIFile(filename: "single_threaded_execution.c", directory: "/tmp/single_threaded_execution.c")
117!2 = !{}
118!3 = !{i32 2, !"Debug Info Version", i32 3}
119!4 = !{i32 1, !"wchar_size", i32 4}
120!5 = !{i32 7, !"openmp", i32 50}
121!6 = !{i32 7, !"openmp-device", i32 50}
122!7 = !{void ()* @kernel, !"kernel", i32 1}
123!8 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 8, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
124!9 = distinct !DISubprogram(name: "cold", scope: !1, file: !1, line: 8, type: !10, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
125!10 = !DISubroutineType(types: !2)
126