xref: /llvm-project/flang/test/Fir/omp-declare-target-data.fir (revision 8a1ce2d6c28fa04b446b9c78a6f4d9443aca4ef3)
1// RUN: fir-opt --fir-to-llvm-ir %s | FileCheck %s
2
3module attributes {omp.is_target_device = false} {
4
5  // CHECK: llvm.mlir.global external @_QMtest_0Earray_1d(dense<[1, 2, 3]> : tensor<3xi32>) {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>{{.*}}} : !llvm.array<3 x i32>
6  fir.global @_QMtest_0Earray_1d(dense<[1, 2, 3]> : tensor<3xi32>) {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !fir.array<3xi32>
7
8  // CHECK: llvm.mlir.global external @_QMtest_0Earray_2d() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>{{.*}}} : !llvm.array<2 x array<2 x i32>>
9  fir.global @_QMtest_0Earray_2d {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !fir.array<2x2xi32> {
10    %0 = fir.undefined !fir.array<2x2xi32>
11    %c1_i32 = arith.constant 1 : i32
12    %1 = fir.insert_value %0, %c1_i32, [0 : index, 0 : index] : (!fir.array<2x2xi32>, i32) -> !fir.array<2x2xi32>
13    %c2_i32 = arith.constant 2 : i32
14    %2 = fir.insert_value %1, %c2_i32, [1 : index, 0 : index] : (!fir.array<2x2xi32>, i32) -> !fir.array<2x2xi32>
15    %c3_i32 = arith.constant 3 : i32
16    %3 = fir.insert_value %2, %c3_i32, [0 : index, 1 : index] : (!fir.array<2x2xi32>, i32) -> !fir.array<2x2xi32>
17    %c4_i32 = arith.constant 4 : i32
18    %4 = fir.insert_value %3, %c4_i32, [1 : index, 1 : index] : (!fir.array<2x2xi32>, i32) -> !fir.array<2x2xi32>
19    %c2 = arith.constant 2 : index
20    %c2_0 = arith.constant 2 : index
21    fir.has_value %4 : !fir.array<2x2xi32>
22  }
23
24  // CHECK: llvm.mlir.global external @_QMtest_0Edata_extended_link_1() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>{{.*}}} : f32
25  fir.global @_QMtest_0Edata_extended_link_1 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : f32 {
26    %cst = arith.constant 2.000000e+00 : f32
27    fir.has_value %cst : f32
28  }
29
30  // CHECK: llvm.mlir.global external @_QMtest_0Edata_extended_link_2() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>{{.*}}} : f32
31  fir.global @_QMtest_0Edata_extended_link_2 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : f32 {
32    %cst = arith.constant 3.000000e+00 : f32
33    fir.has_value %cst : f32
34  }
35
36  // CHECK: llvm.mlir.global external @_QMtest_0Edata_extended_to_1() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}} : f32
37  fir.global @_QMtest_0Edata_extended_to_1 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : f32 {
38    %cst = arith.constant 2.000000e+00 : f32
39    fir.has_value %cst : f32
40  }
41
42  // CHECK: llvm.mlir.global external @_QMtest_0Edata_extended_to_2() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}} : f32 {
43  fir.global @_QMtest_0Edata_extended_to_2 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : f32 {
44    %cst = arith.constant 3.000000e+00 : f32
45    fir.has_value %cst : f32
46  }
47
48  // CHECK: llvm.mlir.global external @_QMtest_0Edata_int() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>{{.*}}} : i32
49  fir.global @_QMtest_0Edata_int {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : i32 {
50    %c10_i32 = arith.constant 10 : i32
51    fir.has_value %c10_i32 : i32
52  }
53
54  // CHECK: llvm.mlir.global external @_QMtest_0Edata_int_clauseless() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}} : i32
55  fir.global @_QMtest_0Edata_int_clauseless {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : i32 {
56    %c1_i32 = arith.constant 1 : i32
57    fir.has_value %c1_i32 : i32
58  }
59
60  // CHECK: llvm.mlir.global external @_QMtest_0Edata_int_to() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}} : i32
61  fir.global @_QMtest_0Edata_int_to {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>} : i32 {
62    %c5_i32 = arith.constant 5 : i32
63    fir.has_value %c5_i32 : i32
64  }
65
66  // CHECK: llvm.mlir.global external @_QMtest_0Ept1() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>{{.*}}} : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8)> {
67  fir.global @_QMtest_0Ept1 {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !fir.box<!fir.ptr<i32>> {
68    %0 = fir.zero_bits !fir.ptr<i32>
69    %1 = fir.embox %0 : (!fir.ptr<i32>) -> !fir.box<!fir.ptr<i32>>
70    fir.has_value %1 : !fir.box<!fir.ptr<i32>>
71  }
72
73  // CHECK: llvm.mlir.global external @_QMtest_0Ept2_tar() {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>{{.*}}} : i32
74  fir.global @_QMtest_0Ept2_tar {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} target : i32 {
75    %c5_i32 = arith.constant 5 : i32
76    fir.has_value %c5_i32 : i32
77  }
78}
79