xref: /llvm-project/mlir/test/Target/LLVMIR/omptarget-array-sectioning-host.mlir (revision cdb3ebf1e62df060767863e1e683409d6077ca6e)
1// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
2
3// This test checks the offload sizes provided to the OpenMP kernel argument
4// structure are correct when lowering to LLVM-IR from MLIR with 3-D bounds
5// provided for a 3-D array. One with full default size, and the other with
6// a user specified OpenMP array sectioning. We expect the default sized
7// array bounds to lower to the full size of the array and the sectioned
8// array to be the size of 3*3*1*element-byte-size (36 bytes in this case).
9
10module attributes {omp.is_target_device = false, omp.target_triples = ["amdgcn-amd-amdhsa"]} {
11  llvm.func @_3d_target_array_section() {
12    %0 = llvm.mlir.addressof @_QFEinarray : !llvm.ptr
13    %1 = llvm.mlir.addressof @_QFEoutarray : !llvm.ptr
14    %2 = llvm.mlir.constant(1 : index) : i64
15    %3 = llvm.mlir.constant(0 : index) : i64
16    %4 = llvm.mlir.constant(2 : index) : i64
17    %5 = omp.map.bounds   lower_bound(%3 : i64) upper_bound(%4 : i64) stride(%2 : i64) start_idx(%2 : i64)
18    %6 = omp.map.bounds   lower_bound(%2 : i64) upper_bound(%2 : i64) stride(%2 : i64) start_idx(%2 : i64)
19    %7 = omp.map.info var_ptr(%0 : !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>)   map_clauses(tofrom) capture(ByRef) bounds(%5, %5, %6) -> !llvm.ptr {name = "inarray(1:3,1:3,2:2)"}
20    %8 = omp.map.info var_ptr(%1 : !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>)   map_clauses(tofrom) capture(ByRef) bounds(%5, %5, %5) -> !llvm.ptr {name = "outarray(1:3,1:3,1:3)"}
21    omp.target   map_entries(%7 -> %arg0, %8 -> %arg1 : !llvm.ptr, !llvm.ptr) {
22      %9 = llvm.mlir.constant(0 : i64) : i64
23      %10 = llvm.mlir.constant(1 : i64) : i64
24      %11 = llvm.getelementptr %arg0[0, %10, %9, %9] : (!llvm.ptr, i64, i64, i64) -> !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>
25      %12 = llvm.load %11 : !llvm.ptr -> i32
26      %13 = llvm.getelementptr %arg1[0, %10, %9, %9] : (!llvm.ptr, i64, i64, i64) -> !llvm.ptr, !llvm.array<3 x array<3 x array<3 x i32>>>
27      llvm.store %12, %13 : i32, !llvm.ptr
28      omp.terminator
29    }
30    llvm.return
31  }
32  llvm.mlir.global internal @_QFEinarray() {addr_space = 0 : i32} : !llvm.array<3 x array<3 x array<3 x i32>>> {
33    %0 = llvm.mlir.zero : !llvm.array<3 x array<3 x array<3 x i32>>>
34    llvm.return %0 : !llvm.array<3 x array<3 x array<3 x i32>>>
35  }
36  llvm.mlir.global internal @_QFEoutarray() {addr_space = 0 : i32} : !llvm.array<3 x array<3 x array<3 x i32>>> {
37    %0 = llvm.mlir.zero : !llvm.array<3 x array<3 x array<3 x i32>>>
38    llvm.return %0 : !llvm.array<3 x array<3 x array<3 x i32>>>
39  }
40}
41
42// CHECK: @.offload_sizes = private unnamed_addr constant [2 x i64] [i64 36, i64 108]
43// CHECK: @.offload_maptypes = private unnamed_addr constant [2 x i64] [i64 35, i64 35]
44// CHECK: @.offload_mapnames = private constant [2 x ptr] [ptr @0, ptr @1]
45
46// CHECK: define void @_3d_target_array_section()
47
48// CHECK: %[[OFFLOADBASEPTRS:.*]] = getelementptr inbounds [2 x ptr], ptr %.offload_baseptrs, i32 0, i32 0
49// CHECK: store ptr @_QFEinarray, ptr %[[OFFLOADBASEPTRS]], align 8
50// CHECK: %[[OFFLOADPTRS:.*]] = getelementptr inbounds [2 x ptr], ptr %.offload_ptrs, i32 0, i32 0
51// CHECK: store ptr getelementptr inbounds ([3 x [3 x [3 x i32]]], ptr @_QFEinarray, i64 0, i64 1, i64 0, i64 0), ptr %[[OFFLOADPTRS]], align 8
52
53// CHECK: %[[OFFLOADBASEPTRS2:.*]] = getelementptr inbounds [2 x ptr], ptr %.offload_baseptrs, i32 0, i32 1
54// CHECK: store ptr @_QFEoutarray, ptr %[[OFFLOADBASEPTRS2]], align 8
55// CHECK: %[[OFFLOADPTRS2:.*]] = getelementptr inbounds [2 x ptr], ptr %.offload_ptrs, i32 0, i32 1
56// CHECK: store ptr @_QFEoutarray, ptr %[[OFFLOADPTRS2]], align 8
57