@@ -5302,19 +5302,23 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
5302
5302
// The current debug location already has the DISubprogram for the outlined
5303
5303
// function that will be created for the target op. We save it here so that
5304
5304
// we can set it on the outlined function.
5305
- llvm::DebugLoc OutlinedFnLoc = builder.getCurrentDebugLocation ();
5305
+ llvm::DebugLoc outlinedFnLoc = builder.getCurrentDebugLocation ();
5306
+ if (failed (checkImplementationStatus (opInst)))
5307
+ return failure ();
5308
+
5306
5309
// During the handling of target op, we will generate instructions in the
5307
- // parent function like call to oulined function or branch to new BasicBlock.
5308
- // We set the debug location here to parent function so that those get the
5309
- // correct debug locations. For outlined functions, the normal MLIR op
5310
+ // parent function like call to the oulined function or branch to a new
5311
+ // BasicBlock. We set the debug location here to parent function so that those
5312
+ // get the correct debug locations. For outlined functions, the normal MLIR op
5310
5313
// conversion will automatically pick the correct location.
5311
5314
llvm::BasicBlock *parentBB = builder.GetInsertBlock ();
5312
- if (parentBB && !parentBB->empty ())
5313
- builder.SetCurrentDebugLocation (parentBB->back ().getDebugLoc ());
5314
- else
5315
- builder.SetCurrentDebugLocation (llvm::DebugLoc ());
5316
- if (failed (checkImplementationStatus (opInst)))
5317
- return failure ();
5315
+ assert (parentBB);
5316
+ llvm::Function *parentLLVMFn = parentBB->getParent ();
5317
+ assert (parentLLVMFn);
5318
+ if (llvm::DISubprogram *SP = parentLLVMFn->getSubprogram ())
5319
+ builder.SetCurrentDebugLocation (llvm::DILocation::get (
5320
+ parentLLVMFn->getContext (), outlinedFnLoc.getLine (),
5321
+ outlinedFnLoc.getCol (), SP, outlinedFnLoc.getInlinedAt ()));
5318
5322
5319
5323
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
5320
5324
bool isTargetDevice = ompBuilder->Config .isTargetDevice ();
@@ -5409,8 +5413,8 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
5409
5413
assert (llvmParentFn && llvmOutlinedFn &&
5410
5414
" Both parent and outlined functions must exist at this point" );
5411
5415
5412
- if (OutlinedFnLoc && llvmParentFn->getSubprogram ())
5413
- llvmOutlinedFn->setSubprogram (OutlinedFnLoc ->getScope ()->getSubprogram ());
5416
+ if (outlinedFnLoc && llvmParentFn->getSubprogram ())
5417
+ llvmOutlinedFn->setSubprogram (outlinedFnLoc ->getScope ()->getSubprogram ());
5414
5418
5415
5419
if (auto attr = llvmParentFn->getFnAttribute (" target-cpu" );
5416
5420
attr.isStringAttribute ())
0 commit comments