Skip to content

Commit d31c08d

Browse files
committed
Handle review comments.
There was code duplicated to handle DbgVariableRecord and DbgVariableIntrinsic. That duplication has been removed. Also checked if there is valid DISubprogram right at the start of the function.
1 parent 320c1c6 commit d31c08d

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6811,6 +6811,11 @@ FunctionCallee OpenMPIRBuilder::createDispatchDeinitFunction() {
68116811
static void FixupDebugInfoForOutlinedFunction(
68126812
OpenMPIRBuilder &OMPBuilder, IRBuilderBase &Builder, Function *Func,
68136813
DenseMap<Value *, std::tuple<Value *, unsigned>> &ValueReplacementMap) {
6814+
6815+
DISubprogram *NewSP = Func->getSubprogram();
6816+
if (!NewSP)
6817+
return;
6818+
68146819
DenseMap<const MDNode *, MDNode *> Cache;
68156820
SmallDenseMap<DILocalVariable *, DILocalVariable *> RemappedVariables;
68166821

@@ -6828,50 +6833,41 @@ static void FixupDebugInfoForOutlinedFunction(
68286833
return NewVar;
68296834
};
68306835

6831-
DISubprogram *NewSP = Func->getSubprogram();
6832-
if (NewSP) {
6833-
// The location and scope of variable intrinsics and records still point to
6834-
// the parent function of the target region. Update them.
6835-
for (Instruction &I : instructions(Func)) {
6836-
if (auto *DDI = dyn_cast<llvm::DbgVariableIntrinsic>(&I)) {
6837-
DILocalVariable *OldVar = DDI->getVariable();
6838-
unsigned ArgNo = OldVar->getArg();
6839-
for (auto Loc : DDI->location_ops()) {
6840-
auto Iter = ValueReplacementMap.find(Loc);
6841-
if (Iter != ValueReplacementMap.end()) {
6842-
DDI->replaceVariableLocationOp(Loc, std::get<0>(Iter->second));
6843-
ArgNo = std::get<1>(Iter->second) + 1;
6844-
}
6845-
}
6846-
DDI->setVariable(GetUpdatedDIVariable(OldVar, ArgNo));
6836+
auto UpdateDebugRecord = [&](auto *DR) {
6837+
DILocalVariable *OldVar = DR->getVariable();
6838+
unsigned ArgNo = OldVar->getArg();
6839+
for (auto Loc : DR->location_ops()) {
6840+
auto Iter = ValueReplacementMap.find(Loc);
6841+
if (Iter != ValueReplacementMap.end()) {
6842+
DR->replaceVariableLocationOp(Loc, std::get<0>(Iter->second));
6843+
ArgNo = std::get<1>(Iter->second) + 1;
68476844
}
6848-
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
6849-
DILocalVariable *OldVar = DVR.getVariable();
6850-
unsigned ArgNo = OldVar->getArg();
6851-
for (auto Loc : DVR.location_ops()) {
6852-
auto Iter = ValueReplacementMap.find(Loc);
6853-
if (Iter != ValueReplacementMap.end()) {
6854-
DVR.replaceVariableLocationOp(Loc, std::get<0>(Iter->second));
6855-
ArgNo = std::get<1>(Iter->second) + 1;
6856-
}
6857-
}
6858-
DVR.setVariable(GetUpdatedDIVariable(OldVar, ArgNo));
6859-
}
6860-
}
6861-
// An extra argument is passed to the device. Create the debug data for it.
6862-
if (OMPBuilder.Config.isTargetDevice()) {
6863-
DICompileUnit *CU = NewSP->getUnit();
6864-
auto M = Builder.GetInsertBlock()->getModule();
6865-
DIBuilder DB(*M, true, CU);
6866-
DIType *VoidPtrTy =
6867-
DB.createQualifiedType(dwarf::DW_TAG_pointer_type, nullptr);
6868-
DILocalVariable *Var = DB.createParameterVariable(
6869-
NewSP, "dyn_ptr", /*ArgNo*/ 1, NewSP->getFile(), /*LineNo=*/0,
6870-
VoidPtrTy, /*AlwaysPreserve=*/false, DINode::DIFlags::FlagArtificial);
6871-
auto Loc = DILocation::get(Func->getContext(), 0, 0, NewSP, 0);
6872-
DB.insertDeclare(&(*Func->arg_begin()), Var, DB.createExpression(), Loc,
6873-
&(*Func->begin()));
68746845
}
6846+
DR->setVariable(GetUpdatedDIVariable(OldVar, ArgNo));
6847+
};
6848+
6849+
// The location and scope of variable intrinsics and records still point to
6850+
// the parent function of the target region. Update them.
6851+
for (Instruction &I : instructions(Func)) {
6852+
if (auto *DDI = dyn_cast<llvm::DbgVariableIntrinsic>(&I))
6853+
UpdateDebugRecord(DDI);
6854+
6855+
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange()))
6856+
UpdateDebugRecord(&DVR);
6857+
}
6858+
// An extra argument is passed to the device. Create the debug data for it.
6859+
if (OMPBuilder.Config.isTargetDevice()) {
6860+
DICompileUnit *CU = NewSP->getUnit();
6861+
auto M = Builder.GetInsertBlock()->getModule();
6862+
DIBuilder DB(*M, true, CU);
6863+
DIType *VoidPtrTy =
6864+
DB.createQualifiedType(dwarf::DW_TAG_pointer_type, nullptr);
6865+
DILocalVariable *Var = DB.createParameterVariable(
6866+
NewSP, "dyn_ptr", /*ArgNo*/ 1, NewSP->getFile(), /*LineNo=*/0,
6867+
VoidPtrTy, /*AlwaysPreserve=*/false, DINode::DIFlags::FlagArtificial);
6868+
auto Loc = DILocation::get(Func->getContext(), 0, 0, NewSP, 0);
6869+
DB.insertDeclare(&(*Func->arg_begin()), Var, DB.createExpression(), Loc,
6870+
&(*Func->begin()));
68756871
}
68766872
}
68776873

0 commit comments

Comments
 (0)