[llvm] [mlir] [OMPIRBuilder] Don't generate DISubprogram for outlined function. (PR #138149)
Sergio Afonso via llvm-commits
llvm-commits at lists.llvm.org
Tue May 13 05:40:35 PDT 2025
================
@@ -4982,6 +4982,20 @@ static LogicalResult
convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
auto targetOp = cast<omp::TargetOp>(opInst);
+ // The current debug location already has the DISubprogram for the outlined
+ // function that will be created for the target op. We save it here so that
+ // we can set it on the outlined function.
+ llvm::DebugLoc OutlinedFnLoc = builder.getCurrentDebugLocation();
+ // During the handling of target op, we will generate instructions in the
+ // parent function like call to oulined function or branch to new BasicBlock.
+ // We set the debug location here to parent function so that those get the
+ // correct debug locations. For outlined functions, the normal MLIR op
+ // conversion will automatically pick the correct location.
+ llvm::BasicBlock *parentBB = builder.GetInsertBlock();
+ if (parentBB && !parentBB->empty())
+ builder.SetCurrentDebugLocation(parentBB->back().getDebugLoc());
+ else
+ builder.SetCurrentDebugLocation(llvm::DebugLoc());
----------------
skatrak wrote:
If I understand it correctly, this will use the debug information from the last instruction introduced in this block (i.e. the last thing added while translating the previous MLIR op). But then it will not do so if `omp.target` is the first operation in the block, which doesn't seem right.
Looking at the comment above, would it make sense to perhaps get the debug information from `parentBB->getParent()` (the parent function)? Also, couldn't we assert that `parentBB != nullptr` here?
https://github.com/llvm/llvm-project/pull/138149
More information about the llvm-commits
mailing list