Skip to content

Commit 667a9f7

Browse files
committed
[MLIR][OpenMP] Fix compiler crash when translating omp.target to LLVM IR
This patch fixes a compiler crash that would happen during translation to LLVM IR if the optional `map` argument of the `omp.target` operation was not present. A unit test is added to ensure this has been fixed. Differential Revision: https://reviews.llvm.org/D158722
1 parent 985e399 commit 667a9f7

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
18841884

18851885
DataLayout DL = DataLayout(opInst.getParentOfType<ModuleOp>());
18861886
SmallVector<Value> mapOperands = targetOp.getMapOperands();
1887-
ArrayAttr mapTypes = targetOp.getMapTypes().value();
1887+
ArrayAttr mapTypes = targetOp.getMapTypes().value_or(nullptr);
18881888

18891889
llvm::OpenMPIRBuilder::MapInfosTy combinedInfos;
18901890
auto genMapInfoCB = [&](llvm::OpenMPIRBuilder::InsertPointTy codeGenIP)

mlir/test/Target/LLVMIR/omptarget-region-llvm.mlir

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,36 @@ module attributes {omp.is_target_device = false} {
2121
}
2222
llvm.return
2323
}
24+
25+
llvm.func @omp_target_no_map() {
26+
omp.target {
27+
omp.terminator
28+
}
29+
llvm.return
30+
}
2431
}
2532

26-
// CHECK: call i32 @__tgt_target_kernel(ptr @4, i64 -1, i32 -1, i32 0, ptr @.__omp_offloading_[[DEV:.*]]_[[FIL:.*]]_omp_target_region__l[[LINE:.*]].region_id, ptr %kernel_args)
33+
// CHECK: define void @omp_target_region_()
34+
// CHECK: call i32 @__tgt_target_kernel(ptr @4, i64 -1, i32 -1, i32 0, ptr @.__omp_offloading_[[DEV:.*]]_[[FIL:.*]]_omp_target_region__l[[LINE1:.*]].region_id, ptr %kernel_args)
35+
36+
// CHECK: br i1 %{{.*}}, label %omp_offload.failed, label %omp_offload.cont
37+
// CHECK: omp_offload.failed:
38+
// CHECK: call void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_region__l[[LINE1]](ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}})
39+
// CHECK: omp_offload.cont:
40+
41+
// CHECK: define void @omp_target_no_map()
42+
// CHECK: call i32 @__tgt_target_kernel(ptr @4, i64 -1, i32 -1, i32 0, ptr @.__omp_offloading_[[DEV:.*]]_[[FIL:.*]]_omp_target_no_map_l[[LINE2:.*]].region_id, ptr %kernel_args)
2743

2844
// CHECK: br i1 %{{.*}}, label %omp_offload.failed, label %omp_offload.cont
2945
// CHECK: omp_offload.failed:
30-
// CHECK: call void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_region__l[[LINE]](ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}})
46+
// CHECK: call void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_no_map_l[[LINE2]]()
3147
// CHECK: omp_offload.cont:
3248

33-
// CHECK: define internal void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_region__l[[LINE]](ptr %[[ADDR_A:.*]], ptr %[[ADDR_B:.*]], ptr %[[ADDR_C:.*]])
49+
// CHECK: define internal void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_region__l[[LINE1]](ptr %[[ADDR_A:.*]], ptr %[[ADDR_B:.*]], ptr %[[ADDR_C:.*]])
3450
// CHECK: %[[VAL_A:.*]] = load i32, ptr %[[ADDR_A]], align 4
3551
// CHECK: %[[VAL_B:.*]] = load i32, ptr %[[ADDR_B]], align 4
3652
// CHECK: %[[SUM:.*]] = add i32 %[[VAL_A]], %[[VAL_B]]
3753
// CHECK: store i32 %[[SUM]], ptr %[[ADDR_C]], align 4
3854

55+
// CHECK: define internal void @__omp_offloading_[[DEV]]_[[FIL]]_omp_target_no_map_l[[LINE2]]()
56+
// CHECK: ret void

0 commit comments

Comments
 (0)