1 // Test declare target link under unified memory requirement. 2 3 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-cuda-mode -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK-HOST 4 5 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -fopenmp-cuda-mode -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc 6 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -fopenmp-cuda-mode -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -target-cpu sm_70 -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK-DEVICE 7 8 // expected-no-diagnostics 9 10 #ifndef HEADER 11 #define HEADER 12 13 #define N 1000 14 15 double var = 10.0; 16 double to_var = 20.0; 17 18 #pragma omp requires unified_shared_memory 19 #pragma omp declare target link(var) 20 #pragma omp declare target to(to_var) 21 22 int bar(int n){ 23 double sum = 0; 24 25 #pragma omp target 26 for(int i = 0; i < n; i++) { 27 sum += var + to_var; 28 } 29 30 return sum; 31 } 32 33 // CHECK-HOST: [[VAR:@.+]] = global double 1.000000e+01 34 // CHECK-HOST: [[VAR_DECL_TGT_LINK_PTR:@.+]] = global double* [[VAR]] 35 36 // CHECK-HOST: [[TO_VAR:@.+]] = global double 2.000000e+01 37 // CHECK-HOST: [[VAR_DECL_TGT_TO_PTR:@.+]] = global double* [[TO_VAR]] 38 39 // CHECK-HOST: [[OFFLOAD_SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 8] 40 // CHECK-HOST: [[OFFLOAD_MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 800, i64 800] 41 42 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [21 x i8] 43 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* getelementptr inbounds ([21 x i8], [21 x i8]* [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries" 44 45 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [24 x i8] 46 // CHECK-HOST: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*), i8* getelementptr inbounds ([24 x i8], [24 x i8]* [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 0, i32 0 }, section ".omp_offloading.entries" 47 48 // CHECK-HOST: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*)], section "llvm.metadata" 49 50 // CHECK-HOST: [[N_CASTED:%.+]] = alloca i64 51 // CHECK-HOST: [[SUM_CASTED:%.+]] = alloca i64 52 53 // CHECK-HOST: [[OFFLOAD_BASEPTRS:%.+]] = alloca [2 x i8*] 54 // CHECK-HOST: [[OFFLOAD_PTRS:%.+]] = alloca [2 x i8*] 55 56 // CHECK-HOST: [[LOAD1:%.+]] = load i64, i64* [[N_CASTED]] 57 // CHECK-HOST: [[LOAD2:%.+]] = load i64, i64* [[SUM_CASTED]] 58 59 // CHECK-HOST: [[BPTR1:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OFFLOAD_BASEPTRS]], i32 0, i32 0 60 // CHECK-HOST: [[BCAST1:%.+]] = bitcast i8** [[BPTR1]] to i64* 61 // CHECK-HOST: store i64 [[LOAD1]], i64* [[BCAST1]] 62 // CHECK-HOST: [[BPTR2:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OFFLOAD_PTRS]], i32 0, i32 0 63 // CHECK-HOST: [[BCAST2:%.+]] = bitcast i8** [[BPTR2]] to i64* 64 // CHECK-HOST: store i64 [[LOAD1]], i64* [[BCAST2]] 65 66 // CHECK-HOST: [[BPTR3:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OFFLOAD_BASEPTRS]], i32 0, i32 1 67 // CHECK-HOST: [[BCAST3:%.+]] = bitcast i8** [[BPTR3]] to i64* 68 // CHECK-HOST: store i64 [[LOAD2]], i64* [[BCAST3]] 69 // CHECK-HOST: [[BPTR4:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OFFLOAD_PTRS]], i32 0, i32 1 70 // CHECK-HOST: [[BCAST4:%.+]] = bitcast i8** [[BPTR4]] to i64* 71 // CHECK-HOST: store i64 [[LOAD2]], i64* [[BCAST4]] 72 73 // CHECK-HOST: [[BPTR7:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OFFLOAD_BASEPTRS]], i32 0, i32 0 74 // CHECK-HOST: [[BPTR8:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OFFLOAD_PTRS]], i32 0, i32 0 75 76 // CHECK-HOST: call i32 @__tgt_target(i64 -1, i8* @{{.*}}.region_id, i32 2, i8** [[BPTR7]], i8** [[BPTR8]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[OFFLOAD_SIZES]], i32 0, i32 0), i64* getelementptr inbounds ([2 x i64], [2 x i64]* [[OFFLOAD_MAPTYPES]], i32 0, i32 0)) 77 78 // CHECK-DEVICE: [[VAR_LINK:@.+]] = common global double* null 79 // CHECK-DEVICE: [[VAR_TO:@.+]] = common global double* null 80 81 // CHECK-DEVICE: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_LINK]] to i8*), i8* bitcast (double** [[VAR_TO]] to i8*)], section "llvm.metadata" 82 83 // CHECK-DEVICE: [[VAR_TO_PTR:%.+]] = load double*, double** [[VAR_TO]] 84 // CHECK-DEVICE: load double, double* [[VAR_TO_PTR]] 85 86 #endif 87