Skip to content

Commit b531fb6

Browse files
committed
Add device specific expression into declare target variable.
1 parent 43e3cec commit b531fb6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ LogicalResult ModuleTranslation::convertGlobals() {
10951095
llvm::DIGlobalVariableExpression *diGlobalExpr =
10961096
debugTranslation->translateGlobalVariableExpression(exprAttr);
10971097
llvm::DIGlobalVariable *diGlobalVar = diGlobalExpr->getVariable();
1098+
10981099
var->addDebugInfo(diGlobalExpr);
10991100

11001101
// There is no `globals` field in DICompileUnitAttr which can be

0 commit comments

Comments
 (0)