1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature
2 ; RUN: opt -S -passes=openmp-opt < %s | FileCheck %s
3 ; RUN: opt -passes=openmp-opt -pass-remarks=openmp-opt -pass-remarks-missed=openmp-opt -disable-output < %s 2>&1 | FileCheck %s -check-prefix=CHECK-REMARKS
4 ; RUN: opt -openmp-opt-disable-deglobalization -S -passes=openmp-opt < %s | FileCheck %s --check-prefix=CHECK-DISABLED
5 target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
6 target triple = "nvptx64"
8 ; CHECK-REMARKS: remark: remove_globalization.c:4:2: Could not move globalized variable to the stack. Variable is potentially captured in call. Mark parameter as `__attribute__((noescape))` to override.
9 ; CHECK-REMARKS: remark: remove_globalization.c:2:2: Moving globalized variable to the stack.
10 ; CHECK-REMARKS: remark: remove_globalization.c:6:2: Moving globalized variable to the stack.
11 ; CHECK-REMARKS: remark: remove_globalization.c:4:2: Found thread data sharing on the GPU. Expect degraded performance due to data globalization.
13 @S = external local_unnamed_addr global i8*
15 %struct.ident_t = type { i32, i32, i32, i32, i8* }
17 declare i32 @__kmpc_target_init(%struct.ident_t*, i1, i1, i1)
18 declare void @__kmpc_target_deinit(%struct.ident_t*, i1, i1)
20 define void @kernel() {
21 ; CHECK-LABEL: define {{[^@]+}}@kernel() {
23 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i1 false, i1 false, i1 true)
24 ; CHECK-NEXT: call void @foo() #[[ATTR0:[0-9]+]]
25 ; CHECK-NEXT: call void @bar() #[[ATTR0]]
26 ; CHECK-NEXT: call void @unknown_no_openmp()
27 ; CHECK-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i1 false, i1 true)
28 ; CHECK-NEXT: ret void
30 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@kernel() {
31 ; CHECK-DISABLED-NEXT: entry:
32 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i1 false, i1 false, i1 true)
33 ; CHECK-DISABLED-NEXT: call void @foo() #[[ATTR0:[0-9]+]]
34 ; CHECK-DISABLED-NEXT: call void @bar() #[[ATTR0]]
35 ; CHECK-DISABLED-NEXT: call void @unknown_no_openmp()
36 ; CHECK-DISABLED-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i1 false, i1 true)
37 ; CHECK-DISABLED-NEXT: ret void
40 %0 = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i1 false, i1 true, i1 true)
43 call void @unknown_no_openmp()
44 call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i1 false, i1 true)
48 define internal void @foo() {
49 ; CHECK-LABEL: define {{[^@]+}}@foo
50 ; CHECK-SAME: () #[[ATTR0]] {
52 ; CHECK-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1
53 ; CHECK-NEXT: ret void
55 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@foo
56 ; CHECK-DISABLED-SAME: () #[[ATTR0]] {
57 ; CHECK-DISABLED-NEXT: entry:
58 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1
59 ; CHECK-DISABLED-NEXT: ret void
62 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !12
63 call void @use(i8* %0)
64 call void @__kmpc_free_shared(i8* %0, i64 4)
68 define internal void @bar() {
69 ; CHECK-LABEL: define {{[^@]+}}@bar
70 ; CHECK-SAME: () #[[ATTR0]] {
72 ; CHECK-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 noundef 4) #[[ATTR0]], !dbg [[DBG8:![0-9]+]]
73 ; CHECK-NEXT: call void @share(i8* nofree writeonly [[TMP0]]) #[[ATTR4:[0-9]+]]
74 ; CHECK-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 noundef 4) #[[ATTR0]]
75 ; CHECK-NEXT: ret void
77 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@bar
78 ; CHECK-DISABLED-SAME: () #[[ATTR0]] {
79 ; CHECK-DISABLED-NEXT: entry:
80 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 noundef 4) #[[ATTR0]], !dbg [[DBG8:![0-9]+]]
81 ; CHECK-DISABLED-NEXT: call void @share(i8* nofree writeonly [[TMP0]]) #[[ATTR4:[0-9]+]]
82 ; CHECK-DISABLED-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 noundef 4) #[[ATTR0]]
83 ; CHECK-DISABLED-NEXT: ret void
86 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !13
87 call void @share(i8* %0)
88 call void @__kmpc_free_shared(i8* %0, i64 4)
92 define internal void @use(i8* %x) {
93 ; CHECK-LABEL: define {{[^@]+}}@use
94 ; CHECK-SAME: (i8* noalias nocapture nofree readnone [[X:%.*]]) #[[ATTR1:[0-9]+]] {
96 ; CHECK-NEXT: ret void
98 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@use
99 ; CHECK-DISABLED-SAME: (i8* noalias nocapture nofree readnone [[X:%.*]]) #[[ATTR1:[0-9]+]] {
100 ; CHECK-DISABLED-NEXT: entry:
101 ; CHECK-DISABLED-NEXT: ret void
107 define internal void @share(i8* %x) {
108 ; CHECK-LABEL: define {{[^@]+}}@share
109 ; CHECK-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR2:[0-9]+]] {
111 ; CHECK-NEXT: store i8* [[X]], i8** @S, align 8
112 ; CHECK-NEXT: ret void
114 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@share
115 ; CHECK-DISABLED-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR2:[0-9]+]] {
116 ; CHECK-DISABLED-NEXT: entry:
117 ; CHECK-DISABLED-NEXT: store i8* [[X]], i8** @S, align 8
118 ; CHECK-DISABLED-NEXT: ret void
121 store i8* %x, i8** @S
125 define void @unused() {
126 ; CHECK-LABEL: define {{[^@]+}}@unused() {
128 ; CHECK-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1
129 ; CHECK-NEXT: call void @use(i8* noalias readnone undef)
130 ; CHECK-NEXT: ret void
132 ; CHECK-DISABLED-LABEL: define {{[^@]+}}@unused() {
133 ; CHECK-DISABLED-NEXT: entry:
134 ; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 4), !dbg [[DBG11:![0-9]+]]
135 ; CHECK-DISABLED-NEXT: call void @use(i8* noalias readnone [[TMP0]])
136 ; CHECK-DISABLED-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 4)
137 ; CHECK-DISABLED-NEXT: ret void
140 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !14
141 call void @use(i8* %0)
142 call void @__kmpc_free_shared(i8* %0, i64 4)
146 ; CHECK: declare i8* @__kmpc_alloc_shared(i64)
147 declare i8* @__kmpc_alloc_shared(i64)
149 ; CHECK: declare void @__kmpc_free_shared(i8* nocapture, i64)
150 declare void @__kmpc_free_shared(i8*, i64)
152 declare void @unknown_no_openmp() "llvm.assume"="omp_no_openmp"
155 !llvm.module.flags = !{!3, !4, !6, !7}
156 !nvvm.annotations = !{!5}
158 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
159 !1 = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c")
161 !3 = !{i32 2, !"Debug Info Version", i32 3}
162 !4 = !{i32 1, !"wchar_size", i32 4}
163 !5 = !{void ()* @kernel, !"kernel", i32 1}
164 !6 = !{i32 7, !"openmp", i32 50}
165 !7 = !{i32 7, !"openmp-device", i32 50}
166 !8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
167 !9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
168 !10 = distinct !DISubprogram(name: "unused", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
169 !11 = !DISubroutineType(types: !2)
170 !12 = !DILocation(line: 2, column: 2, scope: !8)
171 !13 = !DILocation(line: 4, column: 2, scope: !9)
172 !14 = !DILocation(line: 6, column: 2, scope: !9)