1 // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
3 module attributes {omp.is_target_device = false} {
4 llvm.func @omp_target_region_() {
5 %0 = llvm.mlir.constant(20 : i32) : i32
6 %1 = llvm.mlir.constant(10 : i32) : i32
7 %2 = llvm.mlir.constant(1 : i64) : i64
8 %3 = llvm.alloca %2 x i32 {bindc_name = "a", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_regionEa"} : (i64) -> !llvm.ptr
9 %4 = llvm.mlir.constant(1 : i64) : i64
10 %5 = llvm.alloca %4 x i32 {bindc_name = "b", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_regionEb"} : (i64) -> !llvm.ptr
11 %6 = llvm.mlir.constant(1 : i64) : i64
12 %7 = llvm.alloca %6 x i32 {bindc_name = "c", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_regionEc"} : (i64) -> !llvm.ptr
13 llvm.store %1, %3 : i32, !llvm.ptr
14 llvm.store %0, %5 : i32, !llvm.ptr
15 %map1 = omp.map.info var_ptr(%3 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
16 %map2 = omp.map.info var_ptr(%5 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
17 %map3 = omp.map.info var_ptr(%7 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
18 omp.target map_entries( %map1 -> %arg0, %map2 -> %arg1, %map3 -> %arg2 : !llvm.ptr, !llvm.ptr, !llvm.ptr) {
20 %8 = llvm.load %arg0 : !llvm.ptr -> i32
21 %9 = llvm.load %arg1 : !llvm.ptr -> i32
22 %10 = llvm.add %8, %9 : i32
23 llvm.store %10, %arg2 : i32, !llvm.ptr
32 // CHECK: call void @__omp_offloading_[[DEV:.*]]_[[FIL:.*]]_omp_target_region__l[[LINE:.*]](ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}})
33 // CHECK: define internal void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_region__l[[LINE]](ptr %[[ADDR_A:.*]], ptr %[[ADDR_B:.*]], ptr %[[ADDR_C:.*]])
34 // CHECK: %[[STRUCTARG:.*]] = alloca { ptr, ptr, ptr }, align 8
35 // CHECK: %[[GEP1:.*]] = getelementptr { ptr, ptr, ptr }, ptr %[[STRUCTARG]], i32 0, i32 0
36 // CHECK: store ptr %[[ADDR_A]], ptr %[[GEP1]], align 8
37 // CHECK: %[[GEP2:.*]] = getelementptr { ptr, ptr, ptr }, ptr %[[STRUCTARG]], i32 0, i32 1
38 // CHECK: store ptr %[[ADDR_B]], ptr %[[GEP2]], align 8
39 // CHECK: %[[GEP3:.*]] = getelementptr { ptr, ptr, ptr }, ptr %[[STRUCTARG]], i32 0, i32 2
40 // CHECK: store ptr %[[ADDR_C]], ptr %[[GEP3]], align 8
41 // CHECK: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @{{.*}}, i32 1, ptr @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_region__l[[LINE]]..omp_par, ptr %[[STRUCTARG]])
44 // CHECK: define internal void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_region__l[[LINE]]..omp_par(ptr noalias %tid.addr, ptr noalias %zero.addr, ptr %[[STRUCTARG2:.*]]) #0 {
45 // CHECK: %[[GEP4:.*]] = getelementptr { ptr, ptr, ptr }, ptr %[[STRUCTARG2]], i32 0, i32 0
46 // CHECK: %[[LOADGEP1:.*]] = load ptr, ptr %[[GEP4]], align 8
47 // CHECK: %[[GEP5:.*]] = getelementptr { ptr, ptr, ptr }, ptr %0, i32 0, i32 1
48 // CHECK: %[[LOADGEP2:.*]] = load ptr, ptr %[[GEP5]], align 8
49 // CHECK: %[[GEP6:.*]] = getelementptr { ptr, ptr, ptr }, ptr %0, i32 0, i32 2
50 // CHECK: %[[LOADGEP3:.*]] = load ptr, ptr %[[GEP6]], align 8
52 // CHECK: %[[VAL_A:.*]] = load i32, ptr %[[LOADGEP1]], align 4
53 // CHECK: %[[VAL_B:.*]] = load i32, ptr %[[LOADGEP2]], align 4
54 // CHECK: %[[SUM:.*]] = add i32 %[[VAL_A]], %[[VAL_B]]
55 // CHECK: store i32 %[[SUM]], ptr %[[LOADGEP3]], align 4