1; RUN: opt -S -passes='openmp-opt' < %s | FileCheck %s 2; RUN: opt -passes=openmp-opt -pass-remarks=openmp-opt -disable-output < %s 2>&1 | FileCheck %s -check-prefix=CHECK-REMARKS 3target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64" 4target triple = "nvptx64" 5 6@S = external local_unnamed_addr global i8* 7 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: [[SHARED_X:@.+]] = internal addrspace(3) global [16 x i8] undef 11; CHECK: [[SHARED_Y:@.+]] = internal addrspace(3) global [4 x i8] undef 12 13; CHECK: %{{.*}} = call i8* @__kmpc_alloc_shared({{.*}}) 14; CHECK: call void @__kmpc_free_shared({{.*}}) 15define dso_local void @foo() { 16entry: 17 %x = call i8* @__kmpc_alloc_shared(i64 4) 18 %x_on_stack = bitcast i8* %x to i32* 19 %0 = bitcast i32* %x_on_stack to i8* 20 call void @use(i8* %0) 21 call void @__kmpc_free_shared(i8* %x) 22 ret void 23} 24 25define void @bar() { 26 call void @baz() 27 call void @qux() 28 ret void 29} 30 31; CHECK: %{{.*}} = bitcast i8* addrspacecast (i8 addrspace(3)* getelementptr inbounds ([16 x i8], [16 x i8] addrspace(3)* [[SHARED_X]], i32 0, i32 0) to i8*) to [4 x i32]* 32define internal void @baz() { 33entry: 34 %tid = call i32 @llvm.nvvm.read.ptx.sreg.tid.x() 35 %cmp = icmp eq i32 %tid, 0 36 br i1 %cmp, label %master, label %exit 37master: 38 %x = call i8* @__kmpc_alloc_shared(i64 16), !dbg !11 39 %x_on_stack = bitcast i8* %x to [4 x i32]* 40 %0 = bitcast [4 x i32]* %x_on_stack to i8* 41 call void @use(i8* %0) 42 call void @__kmpc_free_shared(i8* %x) 43 br label %exit 44exit: 45 ret void 46} 47 48; CHECK: %{{.*}} = bitcast i8* addrspacecast (i8 addrspace(3)* getelementptr inbounds ([4 x i8], [4 x i8] addrspace(3)* [[SHARED_Y]], i32 0, i32 0) to i8*) to [4 x i32]* 49define internal void @qux() { 50entry: 51 %tid = call i32 @llvm.nvvm.read.ptx.sreg.tid.x() 52 %ntid = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x() 53 %warpsize = call i32 @llvm.nvvm.read.ptx.sreg.warpsize() 54 %0 = sub nuw i32 %warpsize, 1 55 %1 = sub nuw i32 %ntid, 1 56 %2 = xor i32 %0, -1 57 %master_tid = and i32 %1, %2 58 %3 = icmp eq i32 %tid, %master_tid 59 br i1 %3, label %master, label %exit 60master: 61 %y = call i8* @__kmpc_alloc_shared(i64 4), !dbg !12 62 %y_on_stack = bitcast i8* %y to [4 x i32]* 63 %4 = bitcast [4 x i32]* %y_on_stack to i8* 64 call void @use(i8* %4) 65 call void @__kmpc_free_shared(i8* %y) 66 br label %exit 67exit: 68 ret void 69} 70 71 72define void @use(i8* %x) { 73entry: 74 store i8* %x, i8** @S 75 ret void 76} 77 78declare i8* @__kmpc_alloc_shared(i64) 79 80declare void @__kmpc_free_shared(i8*) 81 82declare i32 @llvm.nvvm.read.ptx.sreg.tid.x() 83 84declare i32 @llvm.nvvm.read.ptx.sreg.ntid.x() 85 86declare i32 @llvm.nvvm.read.ptx.sreg.warpsize() 87 88 89!llvm.dbg.cu = !{!0} 90!llvm.module.flags = !{!3, !4, !5, !6} 91!nvvm.annotations = !{!7, !8} 92 93!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) 94!1 = !DIFile(filename: "replace_globalization.c", directory: "/tmp/replace_globalization.c") 95!2 = !{} 96!3 = !{i32 2, !"Debug Info Version", i32 3} 97!4 = !{i32 1, !"wchar_size", i32 4} 98!5 = !{i32 7, !"openmp", i32 50} 99!6 = !{i32 7, !"openmp-device", i32 50} 100!7 = !{void ()* @foo, !"kernel", i32 1} 101!8 = !{void ()* @bar, !"kernel", i32 1} 102!9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 103!10 = !DISubroutineType(types: !2) 104!11 = !DILocation(line: 5, column: 7, scope: !9) 105!12 = !DILocation(line: 5, column: 14, scope: !9) 106