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
4target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
5target triple = "nvptx64"
6
7; CHECK-REMARKS: remark: remove_globalization.c:4:2: Could not move globalized variable to the stack. Variable is potentially captured.
8; CHECK-REMARKS: remark: remove_globalization.c:2:2: Moving globalized variable to the stack.
9
10@S = external local_unnamed_addr global i8*
11
12define void @kernel() {
13; CHECK-LABEL: define {{[^@]+}}@kernel() {
14; CHECK-NEXT:  entry:
15; CHECK-NEXT:    call void @foo() #[[ATTR0:[0-9]+]]
16; CHECK-NEXT:    call void @bar() #[[ATTR0]]
17; CHECK-NEXT:    ret void
18;
19entry:
20  call void @foo()
21  call void @bar()
22  ret void
23}
24
25define internal void @foo() {
26; CHECK-LABEL: define {{[^@]+}}@foo
27; CHECK-SAME: () #[[ATTR0]] {
28; CHECK-NEXT:  entry:
29; CHECK-NEXT:    [[TMP0:%.*]] = alloca i8, i64 4, align 1
30; CHECK-NEXT:    ret void
31;
32entry:
33  %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !11
34  call void @use(i8* %0)
35  call void @__kmpc_free_shared(i8* %0)
36  ret void
37}
38
39define internal void @bar() {
40; CHECK-LABEL: define {{[^@]+}}@bar
41; CHECK-SAME: () #[[ATTR0]] {
42; CHECK-NEXT:  entry:
43; CHECK-NEXT:    [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 noundef 4) #[[ATTR0]]
44; CHECK-NEXT:    call void @share(i8* nofree writeonly [[TMP0]]) #[[ATTR2:[0-9]+]]
45; CHECK-NEXT:    call void @__kmpc_free_shared(i8* [[TMP0]]) #[[ATTR0]]
46; CHECK-NEXT:    ret void
47;
48entry:
49  %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !12
50  call void @share(i8* %0)
51  call void @__kmpc_free_shared(i8* %0)
52  ret void
53}
54
55define internal void @use(i8* %x) {
56entry:
57  ret void
58}
59
60define internal void @share(i8* %x) {
61; CHECK-LABEL: define {{[^@]+}}@share
62; CHECK-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR1:[0-9]+]] {
63; CHECK-NEXT:  entry:
64; CHECK-NEXT:    store i8* [[X]], i8** @S, align 8
65; CHECK-NEXT:    ret void
66;
67entry:
68  store i8* %x, i8** @S
69  ret void
70}
71
72; CHECK: declare i8* @__kmpc_alloc_shared(i64)
73declare i8* @__kmpc_alloc_shared(i64)
74
75; CHECK: declare void @__kmpc_free_shared(i8* nocapture)
76declare void @__kmpc_free_shared(i8*)
77
78!llvm.dbg.cu = !{!0}
79!llvm.module.flags = !{!3, !4, !6, !7}
80!nvvm.annotations = !{!5}
81
82!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)
83!1 = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c")
84!2 = !{}
85!3 = !{i32 2, !"Debug Info Version", i32 3}
86!4 = !{i32 1, !"wchar_size", i32 4}
87!5 = !{void ()* @kernel, !"kernel", i32 1}
88!6 = !{i32 7, !"openmp", i32 50}
89!7 = !{i32 7, !"openmp-device", i32 50}
90!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
91!9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
92!10 = !DISubroutineType(types: !2)
93!11 = !DILocation(line: 2, column: 2, scope: !8)
94!12 = !DILocation(line: 4, column: 2, scope: !9)
95