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