@@ -6986,22 +6986,17 @@ static void FixupDebugInfoForOutlinedFunction(
6986
6986
// snippet) as location of variable. The AMDGPU backend drops the debug
6987
6987
// info for variable in such cases. So we change the location to alloca
6988
6988
// instead.
6989
+ if (DR->getNumVariableLocationOps () != 1u )
6990
+ return ;
6991
+ auto Loc = DR->getVariableLocationOp (0u );
6989
6992
bool PassByRef = false ;
6990
- llvm::Type *locType = nullptr ;
6991
- for (auto Loc : DR->location_ops ()) {
6992
- locType = Loc->getType ();
6993
- if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Loc)) {
6994
- DR->replaceVariableLocationOp (Loc, Load->getPointerOperand ());
6995
- PassByRef = true ;
6996
- }
6993
+ if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(Loc)) {
6994
+ Loc = Load->getPointerOperand ();
6995
+ PassByRef = true ;
6997
6996
}
6998
6997
// Add DIOps based expression. Note that we generate an extra indirection
6999
6998
// if an argument is mapped by reference. The first reads the pointer
7000
6999
// from alloca and 2nd read the value of the variable from that pointer.
7001
- llvm::DIExprBuilder ExprBuilder (Builder.getContext ());
7002
- unsigned int allocaAS = M->getDataLayout ().getAllocaAddrSpace ();
7003
- unsigned int defaultAS = M->getDataLayout ().getProgramAddressSpace ();
7004
- ExprBuilder.append <llvm::DIOp::Arg>(0u , Builder.getPtrTy (allocaAS));
7005
7000
// We have 2 options for the variables that are mapped byRef.
7006
7001
// 1. Use a single indirection but change the type to the reference to the
7007
7002
// original type. It will show up in the debugger as
@@ -7010,10 +7005,15 @@ static void FixupDebugInfoForOutlinedFunction(
7010
7005
// 2. Use double indirection and keep the original type. It will show up
7011
7006
// in debugger as "x=5". This approached is used here as it is
7012
7007
// consistent with the normal fortran parameters display.
7013
- if (PassByRef)
7014
- ExprBuilder.append <llvm::DIOp::Deref>(Builder.getPtrTy (defaultAS));
7015
- ExprBuilder.append <llvm::DIOp::Deref>(locType);
7016
- DR->setExpression (ExprBuilder.intoExpression ());
7008
+ if (auto AI = dyn_cast<llvm::AllocaInst>(Loc->stripPointerCasts ())) {
7009
+ DR->replaceVariableLocationOp (0u , AI);
7010
+ llvm::DIExprBuilder ExprBuilder (Builder.getContext ());
7011
+ ExprBuilder.append <llvm::DIOp::Arg>(0u , AI->getType ());
7012
+ if (PassByRef)
7013
+ ExprBuilder.append <llvm::DIOp::Deref>(AI->getAllocatedType ());
7014
+ ExprBuilder.append <llvm::DIOp::Deref>(AI->getAllocatedType ());
7015
+ DR->setExpression (ExprBuilder.intoExpression ());
7016
+ }
7017
7017
}
7018
7018
7019
7019
DR->setVariable (GetUpdatedDIVariable (OldVar, ArgNo));
0 commit comments