@@ -5166,6 +5166,31 @@ convertOmpTarget(Operation &opInst, llvm::IRBuilderBase &builder,
5166
5166
return success ();
5167
5167
}
5168
5168
5169
+ // Add DIOp based expression in the declare target variables for AMDGPU target.
5170
+ static void updateDebugInfoForDeclareTargetVariables (
5171
+ LLVM::GlobalOp globalOp, LLVM::ModuleTranslation &moduleTranslation) {
5172
+ llvm::Module *M = moduleTranslation.getLLVMModule ();
5173
+ if (!((llvm::Triple (M->getTargetTriple ())).isAMDGPU ()))
5174
+ return ;
5175
+
5176
+ llvm::GlobalVariable *GV = M->getGlobalVariable (globalOp.getSymName ());
5177
+ if (GV) {
5178
+ llvm::SmallVector<llvm::DIGlobalVariableExpression *> GVEs;
5179
+ GV->getDebugInfo (GVEs);
5180
+ GV->eraseMetadata (llvm::LLVMContext::MD_dbg);
5181
+ llvm::DIExprBuilder ExprBuilder (M->getContext ());
5182
+ unsigned int globalAS = M->getDataLayout ().getDefaultGlobalsAddressSpace ();
5183
+ auto ptrTy = llvm::PointerType::get (M->getContext (), globalAS);
5184
+ ExprBuilder.append <llvm::DIOp::Arg>(0u , ptrTy);
5185
+ ExprBuilder.append <llvm::DIOp::Deref>(GV->getType ());
5186
+ for (auto *GVE : GVEs) {
5187
+ auto *newGVE = llvm::DIGlobalVariableExpression::get (
5188
+ M->getContext (), GVE->getVariable (), ExprBuilder.intoExpression ());
5189
+ GV->addDebugInfo (newGVE);
5190
+ }
5191
+ }
5192
+ }
5193
+
5169
5194
static LogicalResult
5170
5195
convertDeclareTargetAttr (Operation *op, mlir::omp::DeclareTargetAttr attribute,
5171
5196
LLVM::ModuleTranslation &moduleTranslation) {
@@ -5197,6 +5222,7 @@ convertDeclareTargetAttr(Operation *op, mlir::omp::DeclareTargetAttr attribute,
5197
5222
5198
5223
if (LLVM::GlobalOp gOp = dyn_cast<LLVM::GlobalOp>(op)) {
5199
5224
llvm::Module *llvmModule = moduleTranslation.getLLVMModule ();
5225
+ updateDebugInfoForDeclareTargetVariables (gOp , moduleTranslation);
5200
5226
if (auto *gVal = llvmModule->getNamedValue (gOp .getSymName ())) {
5201
5227
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder ();
5202
5228
bool isDeclaration = gOp .isDeclaration ();
0 commit comments