[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_uses_allocators_codegen.cpp
blob24e09b3861e392036f0311a2396267963a6509b8
1 // Test host codegen.
2 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
4 // RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
6 // expected-no-diagnostics
7 #ifndef HEADER
8 #define HEADER
10 enum omp_allocator_handle_t {
11 omp_null_allocator = 0,
12 omp_default_mem_alloc = 1,
13 omp_large_cap_mem_alloc = 2,
14 omp_const_mem_alloc = 3,
15 omp_high_bw_mem_alloc = 4,
16 omp_low_lat_mem_alloc = 5,
17 omp_cgroup_mem_alloc = 6,
18 omp_pteam_mem_alloc = 7,
19 omp_thread_mem_alloc = 8,
20 KMP_ALLOCATOR_MAX_HANDLE = __UINTPTR_MAX__
23 typedef enum omp_alloctrait_key_t { omp_atk_sync_hint = 1,
24 omp_atk_alignment = 2,
25 omp_atk_access = 3,
26 omp_atk_pool_size = 4,
27 omp_atk_fallback = 5,
28 omp_atk_fb_data = 6,
29 omp_atk_pinned = 7,
30 omp_atk_partition = 8
31 } omp_alloctrait_key_t;
32 typedef enum omp_alloctrait_value_t {
33 omp_atv_false = 0,
34 omp_atv_true = 1,
35 omp_atv_default = 2,
36 omp_atv_contended = 3,
37 omp_atv_uncontended = 4,
38 omp_atv_sequential = 5,
39 omp_atv_private = 6,
40 omp_atv_all = 7,
41 omp_atv_thread = 8,
42 omp_atv_pteam = 9,
43 omp_atv_cgroup = 10,
44 omp_atv_default_mem_fb = 11,
45 omp_atv_null_fb = 12,
46 omp_atv_abort_fb = 13,
47 omp_atv_allocator_fb = 14,
48 omp_atv_environment = 15,
49 omp_atv_nearest = 16,
50 omp_atv_blocked = 17,
51 omp_atv_interleaved = 18
52 } omp_alloctrait_value_t;
54 typedef struct omp_alloctrait_t {
55 omp_alloctrait_key_t key;
56 __UINTPTR_TYPE__ value;
57 } omp_alloctrait_t;
59 // Just map the traits variable as a firstprivate variable.
60 // CHECK-DAG: [[SIZES:@.+]] = private unnamed_addr constant [1 x i64] [i64 160]
61 // CHECK-DAG: [[MAPTYPES:@.+]] = private unnamed_addr constant [1 x i64] [i64 673]
63 // CHECK: define {{.*}}[[FOO:@.+]]()
64 void foo() {
65 omp_alloctrait_t traits[10];
66 omp_allocator_handle_t my_allocator;
68 // CHECK: [[RES:%.+]] = call i32 @__tgt_target_kernel(ptr @{{.+}}, i64 -1, i32 1, i32 0, ptr @.[[TGT_REGION:.+]].region_id, ptr %[[KERNEL_ARGS:.+]])
69 // CHECK: [[CMP:%.+]] = icmp ne i32 [[RES]], 0
70 // CHECK: br i1 [[CMP]], label %[[FAILED:.+]], label %[[DONE:.+]]
71 // CHECK: [[FAILED]]:
72 // CHECK: call void @[[TGT_REGION]](ptr %{{[^,]+}})
73 #pragma omp target parallel for uses_allocators(omp_null_allocator, omp_thread_mem_alloc, my_allocator(traits))
74 for (int i = 0; i < 10; ++i)
78 // CHECK: define internal void @[[TGT_REGION]](ptr {{.+}})
79 // CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
80 // CHECK: [[MY_ALLOCATOR_ADDR:%.+]] = alloca i64,
81 // CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
82 // CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 10, ptr [[TRAITS_ADDR]])
83 // CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
84 // CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
86 // Destroy allocator upon exit from the region.
87 // CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
88 // CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
89 // CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
90 // CHECK: ret void
92 #endif