@@ -4985,19 +4985,23 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
4985
4985
// The current debug location already has the DISubprogram for the outlined
4986
4986
// function that will be created for the target op. We save it here so that
4987
4987
// we can set it on the outlined function.
4988
- llvm::DebugLoc OutlinedFnLoc = builder.getCurrentDebugLocation ();
4988
+ llvm::DebugLoc outlinedFnLoc = builder.getCurrentDebugLocation ();
4989
+ if (failed (checkImplementationStatus (opInst)))
4990
+ return failure ();
4991
+
4989
4992
// During the handling of target op, we will generate instructions in the
4990
- // parent function like call to oulined function or branch to new BasicBlock.
4991
- // We set the debug location here to parent function so that those get the
4992
- // correct debug locations. For outlined functions, the normal MLIR op
4993
+ // parent function like call to the oulined function or branch to a new
4994
+ // BasicBlock. We set the debug location here to parent function so that those
4995
+ // get the correct debug locations. For outlined functions, the normal MLIR op
4993
4996
// conversion will automatically pick the correct location.
4994
4997
llvm::BasicBlock *parentBB = builder.GetInsertBlock ();
4995
- if (parentBB && !parentBB->empty ())
4996
- builder.SetCurrentDebugLocation (parentBB->back ().getDebugLoc ());
4997
- else
4998
- builder.SetCurrentDebugLocation (llvm::DebugLoc ());
4999
- if (failed (checkImplementationStatus (opInst)))
5000
- return failure ();
4998
+ assert (parentBB);
4999
+ llvm::Function *parentLLVMFn = parentBB->getParent ();
5000
+ assert (parentLLVMFn);
5001
+ if (llvm::DISubprogram *SP = parentLLVMFn->getSubprogram ())
5002
+ builder.SetCurrentDebugLocation (llvm::DILocation::get (
5003
+ parentLLVMFn->getContext (), outlinedFnLoc.getLine (),
5004
+ outlinedFnLoc.getCol (), SP, outlinedFnLoc.getInlinedAt ()));
5001
5005
5002
5006
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
5003
5007
bool isTargetDevice = ompBuilder->Config .isTargetDevice ();
@@ -5092,8 +5096,8 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
5092
5096
assert (llvmParentFn && llvmOutlinedFn &&
5093
5097
" Both parent and outlined functions must exist at this point" );
5094
5098
5095
- if (OutlinedFnLoc && llvmParentFn->getSubprogram ())
5096
- llvmOutlinedFn->setSubprogram (OutlinedFnLoc ->getScope ()->getSubprogram ());
5099
+ if (outlinedFnLoc && llvmParentFn->getSubprogram ())
5100
+ llvmOutlinedFn->setSubprogram (outlinedFnLoc ->getScope ()->getSubprogram ());
5097
5101
5098
5102
if (auto attr = llvmParentFn->getFnAttribute (" target-cpu" );
5099
5103
attr.isStringAttribute ())
0 commit comments