1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals --include-generated-funcs
2; RUN: opt -S -passes='openmp-opt' < %s | FileCheck %s
3; RUN: opt -passes=openmp-opt -pass-remarks=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; UTC_ARGS: --disable
8; CHECK-REMARKS: remark: replace_globalization.c:5:7: Replaced globalized variable with 16 bytes of shared memory
9; CHECK-REMARKS: remark: replace_globalization.c:5:14: Replaced globalized variable with 4 bytes of shared memory
10; CHECK-REMARKS-NOT: 6 bytes
11; UTC_ARGS: --enable
12
13%struct.ident_t = type { i32, i32, i32, i32, i8* }
14
15@S = external local_unnamed_addr global i8*
16@0 = private unnamed_addr constant [113 x i8] c";llvm/test/Transforms/OpenMP/custom_state_machines_remarks.c;__omp_offloading_2a_d80d3d_test_fallback_l11;11;1;;\00", align 1
17@1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([113 x i8], [113 x i8]* @0, i32 0, i32 0) }, align 8
18
19
20define dso_local void @foo() {
21entry:
22  %c = call i32 @__kmpc_target_init(%struct.ident_t* @1, i8 1, i1 true, i1 true)
23  %x = call i8* @__kmpc_alloc_shared(i64 4)
24  call void @unknown_no_openmp()
25  %x_on_stack = bitcast i8* %x to i32*
26  %0 = bitcast i32* %x_on_stack to i8*
27  call void @use(i8* %0)
28  call void @__kmpc_free_shared(i8* %x, i64 4)
29  call void @__kmpc_target_deinit(%struct.ident_t* @1, i8 1, i1 true)
30  ret void
31}
32
33define void @bar() {
34  %c = call i32 @__kmpc_target_init(%struct.ident_t* @1, i8 1, i1 true, i1 true)
35  call void @unknown_no_openmp()
36  %cmp = icmp eq i32 %c, -1
37  br i1 %cmp, label %master1, label %exit
38master1:
39  %x = call i8* @__kmpc_alloc_shared(i64 16), !dbg !11
40  %x_on_stack = bitcast i8* %x to [4 x i32]*
41  %a0 = bitcast [4 x i32]* %x_on_stack to i8*
42  call void @use(i8* %a0)
43  call void @__kmpc_free_shared(i8* %x, i64 16)
44  br label %next
45next:
46  call void @unknown_no_openmp()
47  %b0 = icmp eq i32 %c, -1
48  br i1 %b0, label %master2, label %exit
49master2:
50  %y = call i8* @__kmpc_alloc_shared(i64 4), !dbg !12
51  %y_on_stack = bitcast i8* %y to [4 x i32]*
52  %b1 = bitcast [4 x i32]* %y_on_stack to i8*
53  call void @use(i8* %b1)
54  call void @__kmpc_free_shared(i8* %y, i64 4)
55  br label %exit
56exit:
57  call void @__kmpc_target_deinit(%struct.ident_t* @1, i8 1, i1 true)
58  ret void
59}
60
61define void @baz_spmd() {
62  %c = call i32 @__kmpc_target_init(%struct.ident_t* @1, i8 2, i1 true, i1 true)
63  call void @unknown_no_openmp()
64  %c0 = icmp eq i32 %c, -1
65  br i1 %c0, label %master3, label %exit
66master3:
67  %z = call i8* @__kmpc_alloc_shared(i64 24), !dbg !12
68  %z_on_stack = bitcast i8* %z to [6 x i32]*
69  %c1 = bitcast [6 x i32]* %z_on_stack to i8*
70  call void @use(i8* %c1)
71  call void @__kmpc_free_shared(i8* %z, i64 24)
72  br label %exit
73exit:
74  call void @__kmpc_target_deinit(%struct.ident_t* @1, i8 2, i1 true)
75  ret void
76}
77
78define void @use(i8* %x) {
79entry:
80  store i8* %x, i8** @S
81  ret void
82}
83
84declare i8* @__kmpc_alloc_shared(i64)
85
86declare void @__kmpc_free_shared(i8*, i64)
87
88declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
89
90declare i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
91
92declare i32 @llvm.nvvm.read.ptx.sreg.warpsize()
93
94declare i32 @__kmpc_target_init(%struct.ident_t*, i8, i1, i1)
95
96declare void @__kmpc_target_deinit(%struct.ident_t*, i8, i1)
97
98declare void @unknown_no_openmp() "llvm.assume"="omp_no_openmp"
99
100!llvm.dbg.cu = !{!0}
101!llvm.module.flags = !{!3, !4, !5, !6}
102!nvvm.annotations = !{!7, !8}
103
104!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)
105!1 = !DIFile(filename: "replace_globalization.c", directory: "/tmp/replace_globalization.c")
106!2 = !{}
107!3 = !{i32 2, !"Debug Info Version", i32 3}
108!4 = !{i32 1, !"wchar_size", i32 4}
109!5 = !{i32 7, !"openmp", i32 50}
110!6 = !{i32 7, !"openmp-device", i32 50}
111!7 = !{void ()* @foo, !"kernel", i32 1}
112!8 = !{void ()* @bar, !"kernel", i32 1}
113!13 = !{void ()* @baz_spmd, !"kernel", i32 1}
114!9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
115!10 = !DISubroutineType(types: !2)
116!11 = !DILocation(line: 5, column: 7, scope: !9)
117!12 = !DILocation(line: 5, column: 14, scope: !9)
118;.
119; CHECK: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external local_unnamed_addr global i8*
120; CHECK: @[[GLOB0:[0-9]+]] = private unnamed_addr constant [113 x i8] c"
121; CHECK: @[[GLOB1:[0-9]+]] = private unnamed_addr constant [[STRUCT_IDENT_T:%.*]] { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([113 x i8], [113 x i8]* @[[GLOB0]], i32 0, i32 0) }, align 8
122; CHECK: @[[X:[a-zA-Z0-9_$"\\.-]+]] = internal addrspace(3) global [16 x i8] undef, align 32
123; CHECK: @[[Y:[a-zA-Z0-9_$"\\.-]+]] = internal addrspace(3) global [4 x i8] undef, align 32
124;.
125; CHECK-LABEL: define {{[^@]+}}@foo() {
126; CHECK-NEXT:  entry:
127; CHECK-NEXT:    [[C:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i8 1, i1 false, i1 true)
128; CHECK-NEXT:    [[X:%.*]] = call i8* @__kmpc_alloc_shared(i64 4) #[[ATTR4:[0-9]+]]
129; CHECK-NEXT:    call void @unknown_no_openmp()
130; CHECK-NEXT:    call void @use.internalized(i8* nofree writeonly [[X]]) #[[ATTR5:[0-9]+]]
131; CHECK-NEXT:    call void @__kmpc_free_shared(i8* [[X]], i64 4) #[[ATTR4]]
132; CHECK-NEXT:    call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i8 1, i1 true)
133; CHECK-NEXT:    ret void
134;
135;
136; CHECK-LABEL: define {{[^@]+}}@bar() {
137; CHECK-NEXT:    [[C:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i8 1, i1 false, i1 true)
138; CHECK-NEXT:    call void @unknown_no_openmp()
139; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i32 [[C]], -1
140; CHECK-NEXT:    br i1 [[CMP]], label [[MASTER1:%.*]], label [[EXIT:%.*]]
141; CHECK:       master1:
142; CHECK-NEXT:    call void @use.internalized(i8* nofree addrspacecast (i8 addrspace(3)* getelementptr inbounds ([16 x i8], [16 x i8] addrspace(3)* @x, i32 0, i32 0) to i8*)) #[[ATTR5]]
143; CHECK-NEXT:    br label [[NEXT:%.*]]
144; CHECK:       next:
145; CHECK-NEXT:    call void @unknown_no_openmp()
146; CHECK-NEXT:    br label [[MASTER2:%.*]]
147; CHECK:       master2:
148; CHECK-NEXT:    call void @use.internalized(i8* nofree addrspacecast (i8 addrspace(3)* getelementptr inbounds ([4 x i8], [4 x i8] addrspace(3)* @y, i32 0, i32 0) to i8*)) #[[ATTR5]]
149; CHECK-NEXT:    br label [[EXIT]]
150; CHECK:       exit:
151; CHECK-NEXT:    call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i8 1, i1 true)
152; CHECK-NEXT:    ret void
153;
154;
155; CHECK-LABEL: define {{[^@]+}}@baz_spmd() {
156; CHECK-NEXT:    [[C:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* @[[GLOB1]], i8 2, i1 true, i1 true)
157; CHECK-NEXT:    call void @unknown_no_openmp()
158; CHECK-NEXT:    [[C0:%.*]] = icmp eq i32 [[C]], -1
159; CHECK-NEXT:    br i1 [[C0]], label [[MASTER3:%.*]], label [[EXIT:%.*]]
160; CHECK:       master3:
161; CHECK-NEXT:    [[Z:%.*]] = call i8* @__kmpc_alloc_shared(i64 24) #[[ATTR4]], !dbg [[DBG9:![0-9]+]]
162; CHECK-NEXT:    call void @use.internalized(i8* nofree [[Z]]) #[[ATTR5]]
163; CHECK-NEXT:    call void @__kmpc_free_shared(i8* [[Z]], i64 24) #[[ATTR4]]
164; CHECK-NEXT:    br label [[EXIT]]
165; CHECK:       exit:
166; CHECK-NEXT:    call void @__kmpc_target_deinit(%struct.ident_t* @[[GLOB1]], i8 2, i1 true)
167; CHECK-NEXT:    ret void
168;
169;
170; CHECK: Function Attrs: nofree nosync nounwind willreturn writeonly
171; CHECK-LABEL: define {{[^@]+}}@use.internalized
172; CHECK-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR0:[0-9]+]] {
173; CHECK-NEXT:  entry:
174; CHECK-NEXT:    store i8* [[X]], i8** @S, align 8
175; CHECK-NEXT:    ret void
176;
177;
178; CHECK-LABEL: define {{[^@]+}}@use
179; CHECK-SAME: (i8* [[X:%.*]]) {
180; CHECK-NEXT:  entry:
181; CHECK-NEXT:    store i8* [[X]], i8** @S, align 8
182; CHECK-NEXT:    ret void
183;
184;.
185; CHECK: attributes #[[ATTR0]] = { nofree nosync nounwind willreturn writeonly }
186; CHECK: attributes #[[ATTR1:[0-9]+]] = { nosync nounwind }
187; CHECK: attributes #[[ATTR2:[0-9]+]] = { nounwind readnone }
188; CHECK: attributes #[[ATTR3:[0-9]+]] = { "llvm.assume"="omp_no_openmp" }
189; CHECK: attributes #[[ATTR4]] = { nounwind }
190; CHECK: attributes #[[ATTR5]] = { nounwind writeonly }
191;.
192; CHECK: [[META0:![0-9]+]] = 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)
193; CHECK: [[META1:![0-9]+]] = !DIFile(filename: "replace_globalization.c", directory: "/tmp/replace_globalization.c")
194; CHECK: [[META2:![0-9]+]] = !{}
195; CHECK: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3}
196; CHECK: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
197; CHECK: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50}
198; CHECK: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
199; CHECK: [[META7:![0-9]+]] = !{void ()* @foo, !"kernel", i32 1}
200; CHECK: [[META8:![0-9]+]] = !{void ()* @bar, !"kernel", i32 1}
201; CHECK: [[DBG9]] = !DILocation(line: 5, column: 14, scope: !10)
202; CHECK: [[META10:![0-9]+]] = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
203; CHECK: [[META11:![0-9]+]] = !DISubroutineType(types: !2)
204;.
205