@@ -5896,71 +5896,6 @@ static void updateDebugInfoForDeclareTargetVariables(
58965896 }
58975897}
58985898
5899- static void addAllocasForDeclareTargetFunctionPointerArgs (
5900- llvm::Function *Fn, LLVM::ModuleTranslation &moduleTranslation) {
5901- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
5902- llvm::Module &M = ompBuilder->M ;
5903-
5904- if (!llvm::Triple (M.getTargetTriple ()).isAMDGPU ())
5905- return ;
5906-
5907- if (Fn->empty ())
5908- return ;
5909-
5910- llvm::IRBuilderBase &builder = ompBuilder->Builder ;
5911- llvm::OpenMPIRBuilder::InsertPointTy curInsert = builder.saveIP ();
5912- unsigned int allocaAS = M.getDataLayout ().getAllocaAddrSpace ();
5913- unsigned int defaultAS = M.getDataLayout ().getProgramAddressSpace ();
5914-
5915- builder.SetInsertPoint (Fn->getEntryBlock ().getFirstInsertionPt ());
5916-
5917- llvm::Type *PtrTy = builder.getPtrTy (defaultAS);
5918- llvm::Type *AllocaPtrTy = builder.getPtrTy (allocaAS);
5919- llvm::DIExprBuilder EB (Fn->getContext ());
5920- EB.append <llvm::DIOp::Arg>(0u , AllocaPtrTy);
5921- EB.append <llvm::DIOp::Deref>(PtrTy);
5922- EB.append <llvm::DIOp::Deref>(PtrTy);
5923- llvm::DIExpression *Expr = EB.intoExpression ();
5924-
5925- // flang does not generate allocas for the arguments that are passed by ref.
5926- // When the Argument is the location, the quality of the debug information is
5927- // poor. The variables are defines on very few addresses and show up as
5928- // optimized in most places. One of the reason is the interaction of DI-Op
5929- // based ops and regular ones.
5930- // Generating alloca seems like the best thing which is done in the loop
5931- // below. The users are updated accordingly.
5932- for (auto &Arg : Fn->args ()) {
5933- if (Arg.getType ()->isPointerTy ()) {
5934- llvm::Value *AllocaV =
5935- builder.CreateAlloca (Arg.getType (), allocaAS, nullptr );
5936- llvm::Value *GenericV = allocaAS == defaultAS
5937- ? AllocaV
5938- : ompBuilder->Builder .CreateAddrSpaceCast (
5939- AllocaV, builder.getPtrTy (defaultAS));
5940- llvm::StoreInst *Store = builder.CreateStore (&Arg, GenericV);
5941- llvm::Value *Load = builder.CreateLoad (Arg.getType (), GenericV);
5942- llvm::SmallVector<llvm::DbgVariableIntrinsic *> DbgUsers;
5943- llvm::SmallVector<llvm::DbgVariableRecord *> DPUsers;
5944- llvm::findDbgUsers (&Arg, DPUsers);
5945- for (auto *DVI : DbgUsers) {
5946- DVI->replaceVariableLocationOp (&Arg, AllocaV);
5947- DVI->setExpression (Expr);
5948- }
5949- for (auto *DVR : DPUsers) {
5950- DVR->replaceVariableLocationOp (&Arg, AllocaV);
5951- DVR->setExpression (Expr);
5952- }
5953- Arg.replaceUsesWithIf (Load, [&](const llvm::Use &U) -> bool {
5954- // We dont want to replace Arg from the store we created above.
5955- if (const auto *SI = dyn_cast<llvm::StoreInst>(U.getUser ()))
5956- return SI != Store;
5957- return true ;
5958- });
5959- }
5960- }
5961- builder.restoreIP (curInsert);
5962- }
5963-
59645899// This function Add DIOp based expressions to the debug records in the
59655900// declare target functions.
59665901
@@ -5984,13 +5919,16 @@ static void updateDebugInfoForDeclareTargetFunctions(
59845919 if (DR->getNumVariableLocationOps () != 1u )
59855920 return ;
59865921 auto Loc = DR->getVariableLocationOp (0u );
5987- if (!isa<llvm::AllocaInst>(Loc->stripPointerCasts ()))
5988- return ;
5989- llvm::AllocaInst *AI = cast<llvm::AllocaInst>(Loc->stripPointerCasts ());
5990- DR->replaceVariableLocationOp (0u , AI);
59915922 llvm::DIExprBuilder EB (Fn->getContext ());
5992- EB.append <llvm::DIOp::Arg>(0u , AI->getType ());
5993- EB.append <llvm::DIOp::Deref>(AI->getAllocatedType ());
5923+ if (auto AI = dyn_cast<llvm::AllocaInst>(Loc->stripPointerCasts ())) {
5924+ DR->replaceVariableLocationOp (0u , AI);
5925+ EB.append <llvm::DIOp::Arg>(0u , AI->getType ());
5926+ EB.append <llvm::DIOp::Deref>(AI->getAllocatedType ());
5927+ } else if (Loc->getType ()->isPointerTy ()) {
5928+ EB.append <llvm::DIOp::Arg>(0u , Loc->getType ());
5929+ EB.append <llvm::DIOp::Deref>(Loc->getType ());
5930+ } else
5931+ EB.append <llvm::DIOp::Arg>(0u , Loc->getType ());
59945932 DR->setExpression (EB.intoExpression ());
59955933 };
59965934
@@ -6027,11 +5965,8 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
60275965 if (declareType == omp::DeclareTargetDeviceType::host) {
60285966 llvmFunc->dropAllReferences ();
60295967 llvmFunc->eraseFromParent ();
6030- } else {
6031- addAllocasForDeclareTargetFunctionPointerArgs (llvmFunc,
6032- moduleTranslation);
5968+ } else
60335969 updateDebugInfoForDeclareTargetFunctions (llvmFunc, moduleTranslation);
6034- }
60355970 }
60365971 return success ();
60375972 }
0 commit comments