Skip to content

Commit 232c292

Browse files
authored
Reland [mlir][OpenMP] Use correct debug location with link clause. (#145889)
#145026 was reverted because it failed a sanitizer test. That issue has been fixed in #145883.
1 parent cbf781f commit 232c292

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4831,6 +4831,7 @@ handleDeclareTargetMapVar(MapInfoData &mapData,
48314831
llvm::IRBuilderBase &builder, llvm::Function *func) {
48324832
assert(moduleTranslation.getOpenMPBuilder()->Config.isTargetDevice() &&
48334833
"function only supported for target device codegen");
4834+
llvm::IRBuilderBase::InsertPointGuard guard(builder);
48344835
for (size_t i = 0; i < mapData.MapClause.size(); ++i) {
48354836
// In the case of declare target mapped variables, the basePointer is
48364837
// the reference pointer generated by the convertDeclareTargetAttr
@@ -4865,6 +4866,7 @@ handleDeclareTargetMapVar(MapInfoData &mapData,
48654866
for (llvm::User *user : userVec) {
48664867
if (auto *insn = dyn_cast<llvm::Instruction>(user)) {
48674868
if (insn->getFunction() == func) {
4869+
builder.SetCurrentDebugLocation(insn->getDebugLoc());
48684870
auto *load = builder.CreateLoad(mapData.BasePointers[i]->getType(),
48694871
mapData.BasePointers[i]);
48704872
load->moveBefore(insn->getIterator());
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: mlir-translate -mlir-to-llvmir %s
2+
3+
module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memory_space", 5 : ui32>>, llvm.target_triple = "amdgcn-amd-amdhsa", omp.is_target_device = true} {
4+
llvm.mlir.global external @_QMtest_0Esp() {addr_space = 0 : i32, omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : i32 {
5+
%0 = llvm.mlir.constant(1 : i32) : i32 loc(#loc1)
6+
llvm.return %0 : i32 loc(#loc1)
7+
} loc(#loc1)
8+
llvm.func @_QQmain() {
9+
%0 = llvm.mlir.constant(1 : i64) : i64
10+
%1 = llvm.alloca %0 x i32 : (i64) -> !llvm.ptr<5> loc(#loc2)
11+
%2 = llvm.addrspacecast %1 : !llvm.ptr<5> to !llvm.ptr loc(#loc2)
12+
%6 = llvm.mlir.addressof @_QMtest_0Esp : !llvm.ptr loc(#loc1)
13+
%7 = omp.map.info var_ptr(%2 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr loc(#loc3)
14+
%8 = omp.map.info var_ptr(%6 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr loc(#loc3)
15+
omp.target map_entries(%7 -> %arg0, %8 -> %arg1 : !llvm.ptr, !llvm.ptr) {
16+
%16 = llvm.load %arg1 : !llvm.ptr -> i32 loc(#loc5)
17+
llvm.store %16, %arg0 : i32, !llvm.ptr loc(#loc5)
18+
omp.terminator loc(#loc5)
19+
} loc(#loc5)
20+
llvm.return loc(#loc6)
21+
} loc(#loc15)
22+
}
23+
#di_file = #llvm.di_file<"target7.f90" in "">
24+
#di_null_type = #llvm.di_null_type
25+
#di_compile_unit = #llvm.di_compile_unit<id = distinct[0]<>,
26+
sourceLanguage = DW_LANG_Fortran95, file = #di_file, producer = "flang",
27+
isOptimized = false, emissionKind = LineTablesOnly>
28+
#di_subroutine_type = #llvm.di_subroutine_type<
29+
callingConvention = DW_CC_program, types = #di_null_type>
30+
#di_subprogram = #llvm.di_subprogram<id = distinct[1]<>,
31+
compileUnit = #di_compile_unit, scope = #di_file, name = "main",
32+
file = #di_file, subprogramFlags = "Definition|MainSubprogram",
33+
type = #di_subroutine_type>
34+
#loc1 = loc("test.f90":3:18)
35+
#loc2 = loc("test.f90":7:7)
36+
#loc3 = loc("test.f90":9:18)
37+
#loc5 = loc("test.f90":11:7)
38+
#loc6 = loc("test.f90":12:7)
39+
#loc15 = loc(fused<#di_subprogram>[#loc2])

0 commit comments

Comments
 (0)