@@ -4654,8 +4654,28 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
46544654
46554655 if (LLVM::GlobalOp gOp = dyn_cast<LLVM::GlobalOp>(op)) {
46564656 llvm::Module *llvmModule = moduleTranslation.getLLVMModule ();
4657+ llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
4658+ if (ompBuilder->Config .isTargetDevice ()) {
4659+ llvm::GlobalVariable *GV =
4660+ llvmModule->getGlobalVariable (gOp .getSymName ());
4661+ if (GV) {
4662+ llvm::SmallVector<llvm::DIGlobalVariableExpression *> GVEs;
4663+ GV->getDebugInfo (GVEs);
4664+ GV->eraseMetadata (llvm::LLVMContext::MD_dbg);
4665+ llvm::DIExprBuilder ExprBuilder (llvmModule->getContext ());
4666+ auto ptrTy = llvm::PointerType::get (llvmModule->getContext (), 1 );
4667+ ExprBuilder.append <llvm::DIOp::Arg>(0u , ptrTy);
4668+ ExprBuilder.append <llvm::DIOp::Deref>(GV->getType ());
4669+ // TODO: Take care of any existing expression in the GVE
4670+ for (auto *GVE : GVEs) {
4671+ auto *newGVE = llvm::DIGlobalVariableExpression::get (
4672+ llvmModule->getContext (), GVE->getVariable (),
4673+ ExprBuilder.intoExpression ());
4674+ GV->addDebugInfo (newGVE);
4675+ }
4676+ }
4677+ }
46574678 if (auto *gVal = llvmModule->getNamedValue (gOp .getSymName ())) {
4658- llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
46594679 bool isDeclaration = gOp .isDeclaration ();
46604680 bool isExternallyVisible =
46614681 gOp .getVisibility () != mlir::SymbolTable::Visibility::Private;
0 commit comments