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%struct.ident_t = type { i32, i32, i32, i32, i8* } 7 8@S = external local_unnamed_addr global i8* 9@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 10@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 11 12; CHECK-REMARKS: remark: replace_globalization.c:5:7: Replaced globalized variable with 16 bytes of shared memory 13; CHECK-REMARKS: remark: replace_globalization.c:5:14: Replaced globalized variable with 4 bytes of shared memory 14; CHECK-REMARKS-NOT: 6 bytes 15 16; CHECK: [[SHARED_X:@.+]] = internal addrspace(3) global [16 x i8] undef 17; CHECK: [[SHARED_Y:@.+]] = internal addrspace(3) global [4 x i8] undef 18 19; CHECK: %{{.*}} = call i8* @__kmpc_alloc_shared({{.*}}) 20; CHECK: call void @__kmpc_free_shared({{.*}}) 21define dso_local void @foo() { 22entry: 23 %c = call i32 @__kmpc_target_init(%struct.ident_t* @1, i1 false, i1 true, i1 true) 24 %x = call i8* @__kmpc_alloc_shared(i64 4) 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, i1 false, i1 true) 30 ret void 31} 32 33define void @bar() { 34 %c = call i32 @__kmpc_target_init(%struct.ident_t* @1, i1 false, i1 true, i1 true) 35 call void @baz() 36 call void @qux() 37 call void @negative_qux_spmd() 38 call void @__kmpc_target_deinit(%struct.ident_t* @1, i1 false, i1 true) 39 ret void 40} 41 42; CHECK: call void @use.internalized(i8* nofree writeonly addrspacecast (i8 addrspace(3)* getelementptr inbounds ([16 x i8], [16 x i8] addrspace(3)* [[SHARED_X]], i32 0, i32 0) to i8*)) 43define internal void @baz() { 44entry: 45 %call = call i32 @__kmpc_target_init(%struct.ident_t* nonnull @1, i1 false, i1 false, i1 true) 46 %cmp = icmp eq i32 %call, -1 47 br i1 %cmp, label %master, label %exit 48master: 49 %x = call i8* @__kmpc_alloc_shared(i64 16), !dbg !11 50 %x_on_stack = bitcast i8* %x to [4 x i32]* 51 %0 = bitcast [4 x i32]* %x_on_stack to i8* 52 call void @use(i8* %0) 53 call void @__kmpc_free_shared(i8* %x, i64 16) 54 br label %exit 55exit: 56 ret void 57} 58 59; CHECK: call void @use.internalized(i8* nofree writeonly addrspacecast (i8 addrspace(3)* getelementptr inbounds ([4 x i8], [4 x i8] addrspace(3)* [[SHARED_Y]], i32 0, i32 0) to i8*)) 60define internal void @qux() { 61entry: 62 %call = call i32 @__kmpc_target_init(%struct.ident_t* nonnull @1, i1 false, i1 true, i1 true) 63 %0 = icmp eq i32 %call, -1 64 br i1 %0, label %master, label %exit 65master: 66 %y = call i8* @__kmpc_alloc_shared(i64 4), !dbg !12 67 %y_on_stack = bitcast i8* %y to [4 x i32]* 68 %1 = bitcast [4 x i32]* %y_on_stack to i8* 69 call void @use(i8* %1) 70 call void @__kmpc_free_shared(i8* %y, i64 4) 71 br label %exit 72exit: 73 ret void 74} 75 76define internal void @negative_qux_spmd() { 77entry: 78 %call = call i32 @__kmpc_target_init(%struct.ident_t* nonnull @1, i1 true, i1 true, i1 true) 79 %0 = icmp eq i32 %call, -1 80 br i1 %0, label %master, label %exit 81master: 82 %y = call i8* @__kmpc_alloc_shared(i64 24), !dbg !12 83 %y_on_stack = bitcast i8* %y to [6 x i32]* 84 %1 = bitcast [6 x i32]* %y_on_stack to i8* 85 call void @use(i8* %1) 86 call void @__kmpc_free_shared(i8* %y, i64 24) 87 br label %exit 88exit: 89 ret void 90} 91 92 93define void @use(i8* %x) { 94entry: 95 store i8* %x, i8** @S 96 ret void 97} 98 99declare i8* @__kmpc_alloc_shared(i64) 100 101declare void @__kmpc_free_shared(i8*, i64) 102 103declare i32 @llvm.nvvm.read.ptx.sreg.tid.x() 104 105declare i32 @llvm.nvvm.read.ptx.sreg.ntid.x() 106 107declare i32 @llvm.nvvm.read.ptx.sreg.warpsize() 108 109declare i32 @__kmpc_target_init(%struct.ident_t*, i1, i1, i1) 110 111declare void @__kmpc_target_deinit(%struct.ident_t*, i1, i1) 112 113!llvm.dbg.cu = !{!0} 114!llvm.module.flags = !{!3, !4, !5, !6} 115!nvvm.annotations = !{!7, !8} 116 117!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) 118!1 = !DIFile(filename: "replace_globalization.c", directory: "/tmp/replace_globalization.c") 119!2 = !{} 120!3 = !{i32 2, !"Debug Info Version", i32 3} 121!4 = !{i32 1, !"wchar_size", i32 4} 122!5 = !{i32 7, !"openmp", i32 50} 123!6 = !{i32 7, !"openmp-device", i32 50} 124!7 = !{void ()* @foo, !"kernel", i32 1} 125!8 = !{void ()* @bar, !"kernel", i32 1} 126!9 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2) 127!10 = !DISubroutineType(types: !2) 128!11 = !DILocation(line: 5, column: 7, scope: !9) 129!12 = !DILocation(line: 5, column: 14, scope: !9) 130