@@ -5464,54 +5464,24 @@ static void updateDebugInfoForDeclareTargetVariables(
5464
5464
}
5465
5465
}
5466
5466
5467
- // This function handle any adjustments needed in declare target function to
5468
- // generate valid debug info for AMDGPU. It does 2 main things:
5469
- // 1. Add DIOp based expressions
5470
- // 2. If a debug reocrd points to function Argument as location then change it
5471
- // to use an alloca instead.
5467
+ // This function adds DIOp based expressions in declare target function to
5468
+ // generate valid debug info for AMDGPU.
5469
+
5472
5470
static void updateDebugInfoForDeclareTargetFunctions (
5473
5471
llvm::Function *Fn, LLVM::ModuleTranslation &moduleTranslation) {
5474
5472
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
5475
5473
llvm::Module &M = ompBuilder->M ;
5476
5474
5477
- if (!(( llvm::Triple (M.getTargetTriple ())) .isAMDGPU () ))
5475
+ if (!llvm::Triple (M.getTargetTriple ()).isAMDGPU ())
5478
5476
return ;
5479
5477
5480
- llvm::IRBuilderBase &builder = ompBuilder->Builder ;
5481
- llvm::OpenMPIRBuilder::InsertPointTy curInsert = builder.saveIP ();
5482
- unsigned int allocaAS = M.getDataLayout ().getAllocaAddrSpace ();
5483
- unsigned int defaultAS = M.getDataLayout ().getProgramAddressSpace ();
5484
-
5485
- // In most cases, function argument are passed by reference in Fortran. In
5486
- // such cases, flang does not generate an alloca for such arguments. The
5487
- // debug record also point to the Argument* as the location. The AMDGPU
5488
- // backend drops the debug record in such cases. To side step this issue,
5489
- // we generate an alloca and store the Argument pointer in it. Then we can
5490
- // use that alloca as variable location and it works fine. Note that the
5491
- // expression used in the debug record has doubel indirection now. One for
5492
- // reading Argument* from the alloca and then reading the variable value from
5493
- // the Argument*.
5494
- auto genAlloca = [&](llvm::Value *Arg) {
5495
- builder.SetInsertPoint (Fn->getEntryBlock ().getFirstInsertionPt ());
5496
- llvm::Value *V = builder.CreateAlloca (Arg->getType (), allocaAS, nullptr );
5497
- if (allocaAS != defaultAS && Arg->getType ()->isPointerTy ())
5498
- V = ompBuilder->Builder .CreateAddrSpaceCast (V,
5499
- builder.getPtrTy (defaultAS));
5500
- builder.CreateStore (Arg, V);
5501
- builder.restoreIP (curInsert);
5502
- return V;
5503
- };
5504
5478
auto UpdateDebugRecord = [&](auto *DR) {
5505
5479
for (auto Loc : DR->location_ops ()) {
5506
5480
llvm::DIExprBuilder ExprBuilder (Fn->getContext ());
5507
- ExprBuilder.append <llvm::DIOp::Arg>(
5508
- 0u , ompBuilder->Builder .getPtrTy (allocaAS));
5509
- if (auto *Arg = dyn_cast<llvm::Argument>(Loc)) {
5510
- ExprBuilder.append <llvm::DIOp::Deref>(
5511
- ompBuilder->Builder .getPtrTy (defaultAS));
5512
- llvm::Value *newLoc = genAlloca (Arg);
5513
- DR->replaceVariableLocationOp (Arg, newLoc);
5514
- }
5481
+ llvm::Type *Ty = Loc->getType ();
5482
+ if (auto *Ref = dyn_cast<llvm::AddrSpaceCastInst>(Loc))
5483
+ Ty = Ref->getPointerOperand ()->getType ();
5484
+ ExprBuilder.append <llvm::DIOp::Arg>(0u , Ty);
5515
5485
ExprBuilder.append <llvm::DIOp::Deref>(Loc->getType ());
5516
5486
DR->setExpression (ExprBuilder.intoExpression ());
5517
5487
}
0 commit comments