1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals 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 5target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64" 6target triple = "nvptx64" 7 8@S = external local_unnamed_addr global ptr 9%struct.KernelEnvironmentTy = type { %struct.ConfigurationEnvironmentTy, ptr, ptr } 10%struct.ConfigurationEnvironmentTy = type { i8, i8, i8, i32, i32, i32, i32, i32, i32 } 11@kernel_kernel_environment = local_unnamed_addr constant %struct.KernelEnvironmentTy { %struct.ConfigurationEnvironmentTy { i8 1, i8 0, i8 1, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0 }, ptr null, ptr null } 12 13 14; UTC_ARGS: --disable 15; 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. 16; CHECK-REMARKS: remark: remove_globalization.c:2:2: Moving globalized variable to the stack. 17; CHECK-REMARKS: remark: remove_globalization.c:4:2: Moving globalized variable to the stack. 18; CHECK-REMARKS: remark: remove_globalization.c:10:2: Moving globalized variable to the stack. 19; CHECK-REMARKS: remark: remove_globalization.c:6:2: Moving globalized variable to the stack. 20; UTC_ARGS: --enable 21 22; Make it a weak definition so we will apply custom state machine rewriting but can't use the body in the reasoning. 23;. 24; CHECK: @S = external local_unnamed_addr global ptr 25; CHECK: @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 null, ptr null } 26;. 27; CHECK-DISABLED: @S = external local_unnamed_addr global ptr 28; CHECK-DISABLED: @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 null, ptr null } 29;. 30define weak i32 @__kmpc_target_init(ptr %0, ptr) { 31; CHECK-LABEL: define {{[^@]+}}@__kmpc_target_init 32; CHECK-SAME: (ptr [[TMP0:%.*]], ptr [[TMP1:%.*]]) { 33; CHECK-NEXT: ret i32 0 34; 35; CHECK-DISABLED-LABEL: define {{[^@]+}}@__kmpc_target_init 36; CHECK-DISABLED-SAME: (ptr [[TMP0:%.*]], ptr [[TMP1:%.*]]) { 37; CHECK-DISABLED-NEXT: ret i32 0 38; 39 ret i32 0 40} 41declare void @__kmpc_target_deinit() 42 43define ptx_kernel void @kernel(ptr %dyn) "kernel" { 44; CHECK-LABEL: define {{[^@]+}}@kernel 45; CHECK-SAME: (ptr [[DYN:%.*]]) #[[ATTR0:[0-9]+]] { 46; CHECK-NEXT: entry: 47; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(ptr @kernel_kernel_environment, ptr [[DYN]]) 48; CHECK-NEXT: call void @foo() #[[ATTR1:[0-9]+]] 49; CHECK-NEXT: call void @bar() #[[ATTR1]] 50; CHECK-NEXT: call void @convert_and_move_alloca() #[[ATTR1]] 51; CHECK-NEXT: call void @unknown_no_openmp() #[[ATTR4:[0-9]+]] 52; CHECK-NEXT: call void @__kmpc_target_deinit() 53; CHECK-NEXT: ret void 54; 55; CHECK-DISABLED-LABEL: define {{[^@]+}}@kernel 56; CHECK-DISABLED-SAME: (ptr [[DYN:%.*]]) #[[ATTR0:[0-9]+]] { 57; CHECK-DISABLED-NEXT: entry: 58; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(ptr @kernel_kernel_environment, ptr [[DYN]]) 59; CHECK-DISABLED-NEXT: call void @foo() #[[ATTR1:[0-9]+]] 60; CHECK-DISABLED-NEXT: call void @bar() #[[ATTR1]] 61; CHECK-DISABLED-NEXT: call void @convert_and_move_alloca() #[[ATTR1]] 62; CHECK-DISABLED-NEXT: call void @unknown_no_openmp() #[[ATTR4:[0-9]+]] 63; CHECK-DISABLED-NEXT: call void @__kmpc_target_deinit() 64; CHECK-DISABLED-NEXT: ret void 65; 66entry: 67 %0 = call i32 @__kmpc_target_init(ptr @kernel_kernel_environment, ptr %dyn) 68 call void @foo() 69 call void @bar() 70 call void @convert_and_move_alloca() 71 call void @unknown_no_openmp() 72 call void @__kmpc_target_deinit() 73 ret void 74} 75 76define internal void @foo() { 77; CHECK-LABEL: define {{[^@]+}}@foo 78; CHECK-SAME: () #[[ATTR1]] { 79; CHECK-NEXT: entry: 80; CHECK-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 4 81; CHECK-NEXT: ret void 82; 83; CHECK-DISABLED-LABEL: define {{[^@]+}}@foo 84; CHECK-DISABLED-SAME: () #[[ATTR1]] { 85; CHECK-DISABLED-NEXT: entry: 86; CHECK-DISABLED-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 4 87; CHECK-DISABLED-NEXT: ret void 88; 89entry: 90 %0 = call align 4 ptr @__kmpc_alloc_shared(i64 4), !dbg !12 91 call void @use(ptr %0) 92 call void @__kmpc_free_shared(ptr %0, i64 4) 93 ret void 94} 95 96define internal void @bar() { 97; CHECK-LABEL: define {{[^@]+}}@bar 98; CHECK-SAME: () #[[ATTR1]] { 99; CHECK-NEXT: entry: 100; CHECK-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 4 101; CHECK-NEXT: call void @share(ptr nofree [[DOTH2S]]) #[[ATTR5:[0-9]+]], !dbg [[DBG7:![0-9]+]] 102; CHECK-NEXT: ret void 103; 104; CHECK-DISABLED-LABEL: define {{[^@]+}}@bar 105; CHECK-DISABLED-SAME: () #[[ATTR1]] { 106; CHECK-DISABLED-NEXT: entry: 107; CHECK-DISABLED-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 4 108; CHECK-DISABLED-NEXT: call void @share(ptr nofree [[DOTH2S]]) #[[ATTR5:[0-9]+]], !dbg [[DBG7:![0-9]+]] 109; CHECK-DISABLED-NEXT: ret void 110; 111entry: 112 %0 = call align 4 ptr @__kmpc_alloc_shared(i64 4), !dbg !13 113 call void @share(ptr %0), !dbg !13 114 call void @__kmpc_free_shared(ptr %0, i64 4) 115 ret void 116} 117 118define internal void @use(ptr %x) { 119entry: 120 ret void 121} 122 123define internal void @share(ptr %x) { 124; CHECK-LABEL: define {{[^@]+}}@share 125; CHECK-SAME: (ptr nofree [[X:%.*]]) #[[ATTR2:[0-9]+]] { 126; CHECK-NEXT: entry: 127; CHECK-NEXT: store ptr [[X]], ptr @S, align 8 128; CHECK-NEXT: ret void 129; 130; CHECK-DISABLED-LABEL: define {{[^@]+}}@share 131; CHECK-DISABLED-SAME: (ptr nofree [[X:%.*]]) #[[ATTR2:[0-9]+]] { 132; CHECK-DISABLED-NEXT: entry: 133; CHECK-DISABLED-NEXT: store ptr [[X]], ptr @S, align 8 134; CHECK-DISABLED-NEXT: ret void 135; 136entry: 137 store ptr %x, ptr @S 138 ret void 139} 140 141define void @unused() { 142; CHECK-LABEL: define {{[^@]+}}@unused() { 143; CHECK-NEXT: entry: 144; CHECK-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 4 145; CHECK-NEXT: ret void 146; 147; CHECK-DISABLED-LABEL: define {{[^@]+}}@unused() { 148; CHECK-DISABLED-NEXT: entry: 149; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call align 4 ptr @__kmpc_alloc_shared(i64 4) #[[ATTR6:[0-9]+]], !dbg [[DBG10:![0-9]+]] 150; CHECK-DISABLED-NEXT: call void @__kmpc_free_shared(ptr [[TMP0]], i64 4) #[[ATTR6]] 151; CHECK-DISABLED-NEXT: ret void 152; 153entry: 154 %0 = call align 4 ptr @__kmpc_alloc_shared(i64 4), !dbg !14 155 call void @use(ptr %0) 156 call void @__kmpc_free_shared(ptr %0, i64 4) 157 ret void 158} 159 160define internal void @convert_and_move_alloca() { 161; CHECK-LABEL: define {{[^@]+}}@convert_and_move_alloca 162; CHECK-SAME: () #[[ATTR1]] { 163; CHECK-NEXT: entry: 164; CHECK-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 4 165; CHECK-NEXT: [[IV_PTR:%.*]] = alloca i32, align 4 166; CHECK-NEXT: br label [[INITLOOP:%.*]] 167; CHECK: initloop: 168; CHECK-NEXT: store i32 0, ptr [[IV_PTR]], align 4 169; CHECK-NEXT: br label [[LOOPBODY:%.*]] 170; CHECK: loopbody: 171; CHECK-NEXT: [[IV:%.*]] = load i32, ptr [[IV_PTR]], align 4 172; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[IV]], 10 173; CHECK-NEXT: br i1 [[TMP0]], label [[EXIT:%.*]], label [[LOOPINC:%.*]] 174; CHECK: loopinc: 175; CHECK-NEXT: [[INC:%.*]] = add i32 [[IV]], 1 176; CHECK-NEXT: store i32 [[INC]], ptr [[IV_PTR]], align 4 177; CHECK-NEXT: br label [[LOOPBODY]] 178; CHECK: exit: 179; CHECK-NEXT: ret void 180; 181; CHECK-DISABLED-LABEL: define {{[^@]+}}@convert_and_move_alloca 182; CHECK-DISABLED-SAME: () #[[ATTR1]] { 183; CHECK-DISABLED-NEXT: entry: 184; CHECK-DISABLED-NEXT: [[DOTH2S:%.*]] = alloca i8, i64 4, align 4 185; CHECK-DISABLED-NEXT: [[IV_PTR:%.*]] = alloca i32, align 4 186; CHECK-DISABLED-NEXT: br label [[INITLOOP:%.*]] 187; CHECK-DISABLED: initloop: 188; CHECK-DISABLED-NEXT: store i32 0, ptr [[IV_PTR]], align 4 189; CHECK-DISABLED-NEXT: br label [[LOOPBODY:%.*]] 190; CHECK-DISABLED: loopbody: 191; CHECK-DISABLED-NEXT: [[IV:%.*]] = load i32, ptr [[IV_PTR]], align 4 192; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = icmp eq i32 [[IV]], 10 193; CHECK-DISABLED-NEXT: br i1 [[TMP0]], label [[EXIT:%.*]], label [[LOOPINC:%.*]] 194; CHECK-DISABLED: loopinc: 195; CHECK-DISABLED-NEXT: [[INC:%.*]] = add i32 [[IV]], 1 196; CHECK-DISABLED-NEXT: store i32 [[INC]], ptr [[IV_PTR]], align 4 197; CHECK-DISABLED-NEXT: br label [[LOOPBODY]] 198; CHECK-DISABLED: exit: 199; CHECK-DISABLED-NEXT: ret void 200; 201entry: 202 %iv_ptr = alloca i32, align 4 203 %ub_ptr = alloca i32, align 4 204 store i32 10, ptr %ub_ptr 205 br label %initloop 206 207initloop: 208 store i32 0, ptr %iv_ptr 209 %ub = load i32, ptr %ub_ptr 210 br label %loopbody 211 212loopbody: 213 %0 = call align 4 ptr @__kmpc_alloc_shared(i64 4), !dbg !16 214 call void @use(ptr %0) 215 call void @__kmpc_free_shared(ptr %0, i64 4) 216 %iv = load i32, ptr %iv_ptr 217 %1 = icmp eq i32 %iv, %ub 218 br i1 %1, label %exit, label %loopinc 219 220loopinc: 221 %inc = add i32 %iv, 1 222 store i32 %inc, ptr %iv_ptr 223 br label %loopbody 224 225exit: 226 ret void 227} 228 229declare ptr @__kmpc_alloc_shared(i64) 230 231declare void @__kmpc_free_shared(ptr, i64) 232 233declare void @unknown_no_openmp() "llvm.assume"="omp_no_openmp" 234 235!llvm.dbg.cu = !{!0} 236!llvm.module.flags = !{!3, !4, !6, !7} 237 238!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) 239!1 = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c") 240!2 = !{} 241!3 = !{i32 2, !"Debug Info Version", i32 3} 242!4 = !{i32 1, !"wchar_size", i32 4} 243!6 = !{i32 7, !"openmp", i32 50} 244!7 = !{i32 7, !"openmp-device", i32 50} 245!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 246!9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 247!10 = distinct !DISubprogram(name: "unused", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 248!11 = !DISubroutineType(types: !2) 249!12 = !DILocation(line: 2, column: 2, scope: !8) 250!13 = !DILocation(line: 4, column: 2, scope: !9) 251!14 = !DILocation(line: 6, column: 2, scope: !9) 252!15 = !DILocation(line: 8, column: 2, scope: !9) 253!16 = !DILocation(line: 10, column: 2, scope: !9) 254;. 255; CHECK: attributes #[[ATTR0]] = { "kernel" } 256; CHECK: attributes #[[ATTR1]] = { nosync nounwind } 257; CHECK: attributes #[[ATTR2]] = { nofree norecurse nosync nounwind memory(write) } 258; CHECK: attributes #[[ATTR3:[0-9]+]] = { nosync nounwind allocsize(0) } 259; CHECK: attributes #[[ATTR4]] = { "llvm.assume"="omp_no_openmp" } 260; CHECK: attributes #[[ATTR5]] = { nosync nounwind memory(write) } 261;. 262; CHECK-DISABLED: attributes #[[ATTR0]] = { "kernel" } 263; CHECK-DISABLED: attributes #[[ATTR1]] = { nosync nounwind } 264; CHECK-DISABLED: attributes #[[ATTR2]] = { nofree norecurse nosync nounwind memory(write) } 265; CHECK-DISABLED: attributes #[[ATTR3:[0-9]+]] = { nosync nounwind allocsize(0) } 266; CHECK-DISABLED: attributes #[[ATTR4]] = { "llvm.assume"="omp_no_openmp" } 267; CHECK-DISABLED: attributes #[[ATTR5]] = { nosync nounwind memory(write) } 268; CHECK-DISABLED: attributes #[[ATTR6]] = { nounwind } 269;. 270; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None) 271; CHECK: [[META1]] = !DIFile(filename: "remove_globalization.c", directory: {{.*}}) 272; CHECK: [[META2]] = !{} 273; CHECK: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3} 274; CHECK: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} 275; CHECK: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50} 276; CHECK: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50} 277; CHECK: [[DBG7]] = !DILocation(line: 4, column: 2, scope: [[META8:![0-9]+]]) 278; CHECK: [[META8]] = distinct !DISubprogram(name: "bar", scope: [[META1]], file: [[META1]], line: 1, type: [[META9:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]]) 279; CHECK: [[META9]] = !DISubroutineType(types: [[META2]]) 280;. 281; CHECK-DISABLED: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C99, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], splitDebugInlining: false, nameTableKind: None) 282; CHECK-DISABLED: [[META1]] = !DIFile(filename: "remove_globalization.c", directory: {{.*}}) 283; CHECK-DISABLED: [[META2]] = !{} 284; CHECK-DISABLED: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3} 285; CHECK-DISABLED: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} 286; CHECK-DISABLED: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50} 287; CHECK-DISABLED: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50} 288; CHECK-DISABLED: [[DBG7]] = !DILocation(line: 4, column: 2, scope: [[META8:![0-9]+]]) 289; CHECK-DISABLED: [[META8]] = distinct !DISubprogram(name: "bar", scope: [[META1]], file: [[META1]], line: 1, type: [[META9:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]]) 290; CHECK-DISABLED: [[META9]] = !DISubroutineType(types: [[META2]]) 291; CHECK-DISABLED: [[DBG10]] = !DILocation(line: 6, column: 2, scope: [[META8]]) 292;. 293;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: 294; CHECK-REMARKS: {{.*}} 295