[llvm] [mlir] [OMPIRBuilder] Don't generate DISubprogram for outlined function. (PR #138149)

Abid Qadeer via llvm-commits llvm-commits at lists.llvm.org
Tue May 20 10:21:19 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());
----------------
abidh wrote:

My idea was that for empty basic block, an empty location will be set. But it occurred to me that it will cause Verifier failure in certain cases. I have now changed the way debug location is set and added a testcase to cover it.

https://github.com/llvm/llvm-project/pull/138149


More information about the llvm-commits mailing list