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; 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. 12 13@S = external local_unnamed_addr global i8* 14 15%struct.ident_t = type { i32, i32, i32, i32, i8* } 16 17declare i32 @__kmpc_target_init(%struct.ident_t*, i8, i1, i1) 18declare void @__kmpc_target_deinit(%struct.ident_t*, i8, i1) 19 20;. 21; CHECK: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external local_unnamed_addr global i8* 22;. 23; CHECK-DISABLED: @[[S:[a-zA-Z0-9_$"\\.-]+]] = external local_unnamed_addr global i8* 24;. 25define void @kernel() { 26; CHECK-LABEL: define {{[^@]+}}@kernel() { 27; CHECK-NEXT: entry: 28; CHECK-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i8 1, i1 false, i1 true) 29; CHECK-NEXT: call void @foo() #[[ATTR4:[0-9]+]] 30; CHECK-NEXT: call void @bar() #[[ATTR4]] 31; CHECK-NEXT: call void @unknown_no_openmp() 32; CHECK-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i8 1, i1 true) 33; CHECK-NEXT: ret void 34; 35; CHECK-DISABLED-LABEL: define {{[^@]+}}@kernel() { 36; CHECK-DISABLED-NEXT: entry: 37; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i8 1, i1 false, i1 true) 38; CHECK-DISABLED-NEXT: call void @foo() #[[ATTR4:[0-9]+]] 39; CHECK-DISABLED-NEXT: call void @bar() #[[ATTR4]] 40; CHECK-DISABLED-NEXT: call void @unknown_no_openmp() 41; CHECK-DISABLED-NEXT: call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i8 1, i1 true) 42; CHECK-DISABLED-NEXT: ret void 43; 44entry: 45 %0 = call i32 @__kmpc_target_init(%struct.ident_t* nonnull null, i8 1, i1 true, i1 true) 46 call void @foo() 47 call void @bar() 48 call void @unknown_no_openmp() 49 call void @__kmpc_target_deinit(%struct.ident_t* nonnull null, i8 1, i1 true) 50 ret void 51} 52 53define internal void @foo() { 54; CHECK-LABEL: define {{[^@]+}}@foo 55; CHECK-SAME: () #[[ATTR0:[0-9]+]] { 56; CHECK-NEXT: entry: 57; CHECK-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1 58; CHECK-NEXT: ret void 59; 60; CHECK-DISABLED-LABEL: define {{[^@]+}}@foo 61; CHECK-DISABLED-SAME: () #[[ATTR0:[0-9]+]] { 62; CHECK-DISABLED-NEXT: entry: 63; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1 64; CHECK-DISABLED-NEXT: ret void 65; 66entry: 67 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !12 68 call void @use(i8* %0) 69 call void @__kmpc_free_shared(i8* %0, i64 4) 70 ret void 71} 72 73define internal void @bar() { 74; CHECK-LABEL: define {{[^@]+}}@bar 75; CHECK-SAME: () #[[ATTR0]] { 76; CHECK-NEXT: entry: 77; CHECK-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 noundef 4) #[[ATTR4]], !dbg [[DBG8:![0-9]+]] 78; CHECK-NEXT: call void @share(i8* nofree writeonly [[TMP0]]) #[[ATTR5:[0-9]+]] 79; CHECK-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 noundef 4) #[[ATTR4]] 80; CHECK-NEXT: ret void 81; 82; CHECK-DISABLED-LABEL: define {{[^@]+}}@bar 83; CHECK-DISABLED-SAME: () #[[ATTR0]] { 84; CHECK-DISABLED-NEXT: entry: 85; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 noundef 4) #[[ATTR4]], !dbg [[DBG8:![0-9]+]] 86; CHECK-DISABLED-NEXT: call void @share(i8* nofree writeonly [[TMP0]]) #[[ATTR5:[0-9]+]] 87; CHECK-DISABLED-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 noundef 4) #[[ATTR4]] 88; CHECK-DISABLED-NEXT: ret void 89; 90entry: 91 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !13 92 call void @share(i8* %0) 93 call void @__kmpc_free_shared(i8* %0, i64 4) 94 ret void 95} 96 97define internal void @use(i8* %x) { 98; CHECK-LABEL: define {{[^@]+}}@use 99; CHECK-SAME: (i8* noalias nocapture nofree readnone [[X:%.*]]) #[[ATTR1:[0-9]+]] { 100; CHECK-NEXT: entry: 101; CHECK-NEXT: ret void 102; 103; CHECK-DISABLED-LABEL: define {{[^@]+}}@use 104; CHECK-DISABLED-SAME: (i8* noalias nocapture nofree readnone [[X:%.*]]) #[[ATTR1:[0-9]+]] { 105; CHECK-DISABLED-NEXT: entry: 106; CHECK-DISABLED-NEXT: ret void 107; 108entry: 109 ret void 110} 111 112define internal void @share(i8* %x) { 113; CHECK-LABEL: define {{[^@]+}}@share 114; CHECK-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR2:[0-9]+]] { 115; CHECK-NEXT: entry: 116; CHECK-NEXT: store i8* [[X]], i8** @S, align 8 117; CHECK-NEXT: ret void 118; 119; CHECK-DISABLED-LABEL: define {{[^@]+}}@share 120; CHECK-DISABLED-SAME: (i8* nofree writeonly [[X:%.*]]) #[[ATTR2:[0-9]+]] { 121; CHECK-DISABLED-NEXT: entry: 122; CHECK-DISABLED-NEXT: store i8* [[X]], i8** @S, align 8 123; CHECK-DISABLED-NEXT: ret void 124; 125entry: 126 store i8* %x, i8** @S 127 ret void 128} 129 130define void @unused() { 131; CHECK-LABEL: define {{[^@]+}}@unused() { 132; CHECK-NEXT: entry: 133; CHECK-NEXT: [[TMP0:%.*]] = alloca i8, i64 4, align 1 134; CHECK-NEXT: call void @use(i8* noalias readnone undef) 135; CHECK-NEXT: ret void 136; 137; CHECK-DISABLED-LABEL: define {{[^@]+}}@unused() { 138; CHECK-DISABLED-NEXT: entry: 139; CHECK-DISABLED-NEXT: [[TMP0:%.*]] = call i8* @__kmpc_alloc_shared(i64 4), !dbg [[DBG11:![0-9]+]] 140; CHECK-DISABLED-NEXT: call void @use(i8* noalias readnone [[TMP0]]) 141; CHECK-DISABLED-NEXT: call void @__kmpc_free_shared(i8* [[TMP0]], i64 4) 142; CHECK-DISABLED-NEXT: ret void 143; 144entry: 145 %0 = call i8* @__kmpc_alloc_shared(i64 4), !dbg !14 146 call void @use(i8* %0) 147 call void @__kmpc_free_shared(i8* %0, i64 4) 148 ret void 149} 150 151; CHECK: declare i8* @__kmpc_alloc_shared(i64) 152declare i8* @__kmpc_alloc_shared(i64) 153 154; CHECK: declare void @__kmpc_free_shared(i8* nocapture, i64) 155declare void @__kmpc_free_shared(i8*, i64) 156 157declare void @unknown_no_openmp() "llvm.assume"="omp_no_openmp" 158 159!llvm.dbg.cu = !{!0} 160!llvm.module.flags = !{!3, !4, !6, !7} 161!nvvm.annotations = !{!5} 162 163!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) 164!1 = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c") 165!2 = !{} 166!3 = !{i32 2, !"Debug Info Version", i32 3} 167!4 = !{i32 1, !"wchar_size", i32 4} 168!5 = !{void ()* @kernel, !"kernel", i32 1} 169!6 = !{i32 7, !"openmp", i32 50} 170!7 = !{i32 7, !"openmp-device", i32 50} 171!8 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 172!9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 173!10 = distinct !DISubprogram(name: "unused", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 174!11 = !DISubroutineType(types: !2) 175!12 = !DILocation(line: 2, column: 2, scope: !8) 176!13 = !DILocation(line: 4, column: 2, scope: !9) 177!14 = !DILocation(line: 6, column: 2, scope: !9) 178;. 179; CHECK: attributes #[[ATTR0]] = { nosync nounwind } 180; CHECK: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn } 181; CHECK: attributes #[[ATTR2]] = { nofree nosync nounwind willreturn writeonly } 182; CHECK: attributes #[[ATTR3:[0-9]+]] = { "llvm.assume"="omp_no_openmp" } 183; CHECK: attributes #[[ATTR4]] = { nounwind } 184; CHECK: attributes #[[ATTR5]] = { nosync nounwind writeonly } 185;. 186; CHECK-DISABLED: attributes #[[ATTR0]] = { nosync nounwind } 187; CHECK-DISABLED: attributes #[[ATTR1]] = { nofree nosync nounwind readnone willreturn } 188; CHECK-DISABLED: attributes #[[ATTR2]] = { nofree nosync nounwind willreturn writeonly } 189; CHECK-DISABLED: attributes #[[ATTR3:[0-9]+]] = { "llvm.assume"="omp_no_openmp" } 190; CHECK-DISABLED: attributes #[[ATTR4]] = { nounwind } 191; CHECK-DISABLED: attributes #[[ATTR5]] = { nosync nounwind writeonly } 192;. 193; CHECK: [[META0:![0-9]+]] = 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) 194; CHECK: [[META1:![0-9]+]] = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c") 195; CHECK: [[META2:![0-9]+]] = !{} 196; CHECK: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3} 197; CHECK: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} 198; CHECK: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50} 199; CHECK: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50} 200; CHECK: [[META7:![0-9]+]] = !{void ()* @kernel, !"kernel", i32 1} 201; CHECK: [[DBG8]] = !DILocation(line: 4, column: 2, scope: !9) 202; CHECK: [[META9:![0-9]+]] = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 203; CHECK: [[META10:![0-9]+]] = !DISubroutineType(types: !2) 204;. 205; CHECK-DISABLED: [[META0:![0-9]+]] = 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) 206; CHECK-DISABLED: [[META1:![0-9]+]] = !DIFile(filename: "remove_globalization.c", directory: "/tmp/remove_globalization.c") 207; CHECK-DISABLED: [[META2:![0-9]+]] = !{} 208; CHECK-DISABLED: [[META3:![0-9]+]] = !{i32 2, !"Debug Info Version", i32 3} 209; CHECK-DISABLED: [[META4:![0-9]+]] = !{i32 1, !"wchar_size", i32 4} 210; CHECK-DISABLED: [[META5:![0-9]+]] = !{i32 7, !"openmp", i32 50} 211; CHECK-DISABLED: [[META6:![0-9]+]] = !{i32 7, !"openmp-device", i32 50} 212; CHECK-DISABLED: [[META7:![0-9]+]] = !{void ()* @kernel, !"kernel", i32 1} 213; CHECK-DISABLED: [[DBG8]] = !DILocation(line: 4, column: 2, scope: !9) 214; CHECK-DISABLED: [[META9:![0-9]+]] = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 215; CHECK-DISABLED: [[META10:![0-9]+]] = !DISubroutineType(types: !2) 216; CHECK-DISABLED: [[DBG11]] = !DILocation(line: 6, column: 2, scope: !9) 217;. 218