1*207b08a9SGiorgis Georgakoudis // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
2c99042baSAlexey Bataev // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
3*207b08a9SGiorgis Georgakoudis // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-nvidia-cuda -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - -disable-llvm-optzns | FileCheck %s --check-prefix=CHECK1
4c99042baSAlexey Bataev // expected-no-diagnostics
5c99042baSAlexey Bataev 
6c99042baSAlexey Bataev int foo(int &a) { return a; }
7c99042baSAlexey Bataev 
8c99042baSAlexey Bataev int bar() {
9c99042baSAlexey Bataev   int a;
10c99042baSAlexey Bataev   return foo(a);
11c99042baSAlexey Bataev }
12c99042baSAlexey Bataev 
13c99042baSAlexey Bataev 
14c99042baSAlexey Bataev int maini1() {
15c99042baSAlexey Bataev   int a;
16c99042baSAlexey Bataev #pragma omp target parallel map(from:a)
17c99042baSAlexey Bataev   {
18c99042baSAlexey Bataev     int b;
19c99042baSAlexey Bataev     a = foo(b) + bar();
20c99042baSAlexey Bataev   }
21c99042baSAlexey Bataev   return a;
22c99042baSAlexey Bataev }
23c99042baSAlexey Bataev 
24c99042baSAlexey Bataev // parallel region
25c99042baSAlexey Bataev 
26c99042baSAlexey Bataev 
27*207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@{{__omp_offloading_[0-9a-z]+_[0-9a-z]+}}__Z6maini1v_l16
28*207b08a9SGiorgis Georgakoudis // CHECK1-SAME: (i32* nonnull align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR0:[0-9]+]] {
29*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
30*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A_ADDR:%.*]] = alloca i32*, align 8
31*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[CAPTURED_VARS_ADDRS:%.*]] = alloca [1 x i8*], align 8
32*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[A]], i32** [[A_ADDR]], align 8
33*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
34*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[NVPTX_NUM_THREADS:%.*]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
35*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    call void @__kmpc_spmd_kernel_init(i32 [[NVPTX_NUM_THREADS]], i16 1)
36*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    call void @__kmpc_data_sharing_init_stack_spmd()
37*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br label [[DOTEXECUTE:%.*]]
38*207b08a9SGiorgis Georgakoudis // CHECK1:       .execute:
39*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP1:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t* @[[GLOB1:[0-9]+]])
40*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP2:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* [[CAPTURED_VARS_ADDRS]], i64 0, i64 0
41*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP3:%.*]] = bitcast i32* [[TMP0]] to i8*
42*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i8* [[TMP3]], i8** [[TMP2]], align 8
43*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP4:%.*]] = bitcast [1 x i8*]* [[CAPTURED_VARS_ADDRS]] to i8**
44*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    call void @__kmpc_parallel_51(%struct.ident_t* @[[GLOB1]], i32 [[TMP1]], i32 1, i32 -1, i32 -1, i8* bitcast (void (i32*, i32*, i32*)* @__omp_outlined__ to i8*), i8* null, i8** [[TMP4]], i64 1)
45*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br label [[DOTOMP_DEINIT:%.*]]
46*207b08a9SGiorgis Georgakoudis // CHECK1:       .omp.deinit:
47*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    call void @__kmpc_spmd_kernel_deinit_v2(i16 1)
48*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br label [[DOTEXIT:%.*]]
49*207b08a9SGiorgis Georgakoudis // CHECK1:       .exit:
50*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    ret void
51*207b08a9SGiorgis Georgakoudis //
52*207b08a9SGiorgis Georgakoudis //
53*207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@__omp_outlined__
54*207b08a9SGiorgis Georgakoudis // CHECK1-SAME: (i32* noalias [[DOTGLOBAL_TID_:%.*]], i32* noalias [[DOTBOUND_TID_:%.*]], i32* nonnull align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR0]] {
55*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
56*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[DOTGLOBAL_TID__ADDR:%.*]] = alloca i32*, align 8
57*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[DOTBOUND_TID__ADDR:%.*]] = alloca i32*, align 8
58*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A_ADDR:%.*]] = alloca i32*, align 8
59*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[B:%.*]] = alloca i32, align 4
60*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[DOTGLOBAL_TID_]], i32** [[DOTGLOBAL_TID__ADDR]], align 8
61*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[DOTBOUND_TID_]], i32** [[DOTBOUND_TID__ADDR]], align 8
62*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[A]], i32** [[A_ADDR]], align 8
63*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
64*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[CALL:%.*]] = call i32 @_Z3fooRi(i32* nonnull align 4 dereferenceable(4) [[B]]) #[[ATTR4:[0-9]+]]
65*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[CALL1:%.*]] = call i32 @_Z3barv() #[[ATTR4]]
66*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[ADD:%.*]] = add nsw i32 [[CALL]], [[CALL1]]
67*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32 [[ADD]], i32* [[TMP0]], align 4
68*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    ret void
69*207b08a9SGiorgis Georgakoudis //
70*207b08a9SGiorgis Georgakoudis //
71*207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@_Z3fooRi
72*207b08a9SGiorgis Georgakoudis // CHECK1-SAME: (i32* nonnull align 4 dereferenceable(4) [[A:%.*]]) #[[ATTR2:[0-9]+]] {
73*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
74*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A_ADDR:%.*]] = alloca i32*, align 8
75*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32* [[A]], i32** [[A_ADDR]], align 8
76*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP0:%.*]] = load i32*, i32** [[A_ADDR]], align 8
77*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4
78*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    ret i32 [[TMP1]]
79*207b08a9SGiorgis Georgakoudis //
80*207b08a9SGiorgis Georgakoudis //
81*207b08a9SGiorgis Georgakoudis // CHECK1-LABEL: define {{[^@]+}}@_Z3barv
82*207b08a9SGiorgis Georgakoudis // CHECK1-SAME: () #[[ATTR2]] {
83*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:  entry:
84*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[RETVAL:%.*]] = alloca i32, align 4
85*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A1:%.*]] = alloca i32, align 4
86*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP0:%.*]] = call i8 @__kmpc_is_spmd_exec_mode() #[[ATTR3:[0-9]+]]
87*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP1:%.*]] = icmp ne i8 [[TMP0]], 0
88*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br i1 [[TMP1]], label [[DOTSPMD:%.*]], label [[DOTNON_SPMD:%.*]]
89*207b08a9SGiorgis Georgakoudis // CHECK1:       .spmd:
90*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br label [[DOTEXIT:%.*]]
91*207b08a9SGiorgis Georgakoudis // CHECK1:       .non-spmd:
92*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP2:%.*]] = call i8* @__kmpc_data_sharing_coalesced_push_stack(i64 128, i16 0)
93*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP3:%.*]] = bitcast i8* [[TMP2]] to %struct._globalized_locals_ty*
94*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br label [[DOTEXIT]]
95*207b08a9SGiorgis Georgakoudis // CHECK1:       .exit:
96*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[_SELECT_STACK:%.*]] = phi %struct._globalized_locals_ty* [ null, [[DOTSPMD]] ], [ [[TMP3]], [[DOTNON_SPMD]] ]
97*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[A:%.*]] = getelementptr inbounds [[STRUCT__GLOBALIZED_LOCALS_TY:%.*]], %struct._globalized_locals_ty* [[_SELECT_STACK]], i32 0, i32 0
98*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[NVPTX_TID:%.*]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
99*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[NVPTX_LANE_ID:%.*]] = and i32 [[NVPTX_TID]], 31
100*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP4:%.*]] = getelementptr inbounds [32 x i32], [32 x i32]* [[A]], i32 0, i32 [[NVPTX_LANE_ID]]
101*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP5:%.*]] = select i1 [[TMP1]], i32* [[A1]], i32* [[TMP4]]
102*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[CALL:%.*]] = call i32 @_Z3fooRi(i32* nonnull align 4 dereferenceable(4) [[TMP5]]) #[[ATTR4]]
103*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    store i32 [[CALL]], i32* [[RETVAL]], align 4
104*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br i1 [[TMP1]], label [[DOTEXIT3:%.*]], label [[DOTNON_SPMD2:%.*]]
105*207b08a9SGiorgis Georgakoudis // CHECK1:       .non-spmd2:
106*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP6:%.*]] = bitcast %struct._globalized_locals_ty* [[_SELECT_STACK]] to i8*
107*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    call void @__kmpc_data_sharing_pop_stack(i8* [[TMP6]])
108*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    br label [[DOTEXIT3]]
109*207b08a9SGiorgis Georgakoudis // CHECK1:       .exit3:
110*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    [[TMP7:%.*]] = load i32, i32* [[RETVAL]], align 4
111*207b08a9SGiorgis Georgakoudis // CHECK1-NEXT:    ret i32 [[TMP7]]
112*207b08a9SGiorgis Georgakoudis //
113