Skip to content

Commit 469487a

Browse files
committed
[mlir][gpu] Fix bug with GPU hardware intrinsic global location
1 parent d1b0b4b commit 469487a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ struct OpToFuncCallLowering : public ConvertOpToLLVMPattern<SourceOp> {
164164
auto parentFunc = op->getParentOfType<FunctionOpInterface>();
165165
assert(parentFunc && "expected there to be a parent function");
166166
OpBuilder b(parentFunc);
167-
return b.create<LLVMFuncOp>(op->getLoc(), funcName, funcType);
167+
168+
// Create a valid global location removing any metadata attached to the
169+
// location as debug info metadata inside of a function cannot be used
170+
// outside of that function.
171+
auto globalloc = op->getLoc()->findInstanceOfOrUnknown<FileLineColLoc>();
172+
return b.create<LLVMFuncOp>(globalloc, funcName, funcType);
168173
}
169174

170175
StringRef getFunctionName(Type type, SourceOp op) const {

mlir/test/Conversion/GPUToNVVM/gpu-to-nvvm-debuginfo.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ gpu.module @test_module_1 {
2323
gpu.return
2424
}
2525
}
26+
27+
// Check that debug info metadata from the function is removed from the global location.
28+
gpu.module @test_module_2 {
29+
// CHECK-DAG: llvm.func @__nv_abs(i32) -> i32 loc([[LOC]])
30+
func.func @gpu_abs_with_loc(%arg_i32 : i32) -> (i32) {
31+
%result32 = math.absi %arg_i32 : i32 loc(fused<#di_subprogram>[#loc])
32+
func.return %result32 : i32
33+
}
34+
}

0 commit comments

Comments
 (0)