-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[mlir][debug] Allow multiple DIGlobalVariableExpression on globals. #111981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
6afd64e
8bca1b6
008b414
81b8418
cec4e7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2089,7 +2089,7 @@ void GlobalOp::build(OpBuilder &builder, OperationState &result, Type type, | |||||
| Attribute value, uint64_t alignment, unsigned addrSpace, | ||||||
| bool dsoLocal, bool threadLocal, SymbolRefAttr comdat, | ||||||
| ArrayRef<NamedAttribute> attrs, | ||||||
| DIGlobalVariableExpressionAttr dbgExpr) { | ||||||
| ArrayRef<Attribute> dbgExprs) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Can this be typed (here and in the other places)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this but it did not work. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok makes sense! I think DIGlobalVariableExpressionArrayAttr has a verifier so things should ultimately be checked. |
||||||
| result.addAttribute(getSymNameAttrName(result.name), | ||||||
| builder.getStringAttr(name)); | ||||||
| result.addAttribute(getGlobalTypeAttrName(result.name), TypeAttr::get(type)); | ||||||
|
|
@@ -2121,8 +2121,9 @@ void GlobalOp::build(OpBuilder &builder, OperationState &result, Type type, | |||||
| builder.getI32IntegerAttr(addrSpace)); | ||||||
| result.attributes.append(attrs.begin(), attrs.end()); | ||||||
|
|
||||||
| if (dbgExpr) | ||||||
| result.addAttribute(getDbgExprAttrName(result.name), dbgExpr); | ||||||
| if (!dbgExprs.empty()) | ||||||
| result.addAttribute(getDbgExprsAttrName(result.name), | ||||||
| ArrayAttr::get(builder.getContext(), dbgExprs)); | ||||||
|
|
||||||
| result.addRegion(); | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1055,44 +1055,50 @@ LogicalResult ModuleTranslation::convertGlobals() { | |
| globalsMapping.try_emplace(op, var); | ||
|
|
||
| // Add debug information if present. | ||
| if (op.getDbgExpr()) { | ||
| llvm::DIGlobalVariableExpression *diGlobalExpr = | ||
| debugTranslation->translateGlobalVariableExpression(op.getDbgExpr()); | ||
| llvm::DIGlobalVariable *diGlobalVar = diGlobalExpr->getVariable(); | ||
| var->addDebugInfo(diGlobalExpr); | ||
|
|
||
| // There is no `globals` field in DICompileUnitAttr which can be directly | ||
| // assigned to DICompileUnit. We have to build the list by looking at the | ||
| // dbgExpr of all the GlobalOps. The scope of the variable is used to get | ||
| // the DICompileUnit in which to add it. | ||
| // But there are cases where the scope of a global does not | ||
| // directly point to the DICompileUnit and we have to do a bit more work | ||
| // to get to it. Some of those cases are: | ||
| // | ||
| // 1. For the languages that support modules, the scope hierarchy can be | ||
| // variable -> DIModule -> DICompileUnit | ||
| // | ||
| // 2. For the Fortran common block variable, the scope hierarchy can be | ||
| // variable -> DICommonBlock -> DISubprogram -> DICompileUnit | ||
| // | ||
| // 3. For entities like static local variables in C or variable with | ||
| // SAVE attribute in Fortran, the scope hierarchy can be | ||
| // variable -> DISubprogram -> DICompileUnit | ||
| llvm::DIScope *scope = diGlobalVar->getScope(); | ||
| if (auto *mod = dyn_cast_if_present<llvm::DIModule>(scope)) | ||
| scope = mod->getScope(); | ||
| else if (auto *cb = dyn_cast_if_present<llvm::DICommonBlock>(scope)) { | ||
| if (auto *sp = dyn_cast_if_present<llvm::DISubprogram>(cb->getScope())) | ||
| scope = sp->getUnit(); | ||
| } else if (auto *sp = dyn_cast_if_present<llvm::DISubprogram>(scope)) | ||
| scope = sp->getUnit(); | ||
|
|
||
| // Get the compile unit (scope) of the the global variable. | ||
| if (llvm::DICompileUnit *compileUnit = | ||
| dyn_cast_if_present<llvm::DICompileUnit>(scope)) { | ||
| // Update the compile unit with this incoming global variable expression | ||
| // during the finalizing step later. | ||
| allGVars[compileUnit].push_back(diGlobalExpr); | ||
| if (op.getDbgExprs()) { | ||
| for (auto attr : *op.getDbgExprs()) { | ||
| if (auto exprAttr = | ||
| dyn_cast_if_present<DIGlobalVariableExpressionAttr>(attr)) { | ||
|
||
| llvm::DIGlobalVariableExpression *diGlobalExpr = | ||
| debugTranslation->translateGlobalVariableExpression(exprAttr); | ||
| llvm::DIGlobalVariable *diGlobalVar = diGlobalExpr->getVariable(); | ||
| var->addDebugInfo(diGlobalExpr); | ||
|
|
||
| // There is no `globals` field in DICompileUnitAttr which can be | ||
| // directly assigned to DICompileUnit. We have to build the list by | ||
| // looking at the dbgExpr of all the GlobalOps. The scope of the | ||
| // variable is used to get the DICompileUnit in which to add it. But | ||
| // there are cases where the scope of a global does not directly point | ||
| // to the DICompileUnit and we have to do a bit more work to get to | ||
| // it. Some of those cases are: | ||
| // | ||
| // 1. For the languages that support modules, the scope hierarchy can | ||
| // be variable -> DIModule -> DICompileUnit | ||
| // | ||
| // 2. For the Fortran common block variable, the scope hierarchy can | ||
| // be variable -> DICommonBlock -> DISubprogram -> DICompileUnit | ||
| // | ||
| // 3. For entities like static local variables in C or variable with | ||
| // SAVE attribute in Fortran, the scope hierarchy can be | ||
| // variable -> DISubprogram -> DICompileUnit | ||
| llvm::DIScope *scope = diGlobalVar->getScope(); | ||
| if (auto *mod = dyn_cast_if_present<llvm::DIModule>(scope)) | ||
| scope = mod->getScope(); | ||
| else if (auto *cb = dyn_cast_if_present<llvm::DICommonBlock>(scope)) { | ||
| if (auto *sp = | ||
| dyn_cast_if_present<llvm::DISubprogram>(cb->getScope())) | ||
| scope = sp->getUnit(); | ||
| } else if (auto *sp = dyn_cast_if_present<llvm::DISubprogram>(scope)) | ||
| scope = sp->getUnit(); | ||
|
|
||
| // Get the compile unit (scope) of the the global variable. | ||
| if (llvm::DICompileUnit *compileUnit = | ||
| dyn_cast_if_present<llvm::DICompileUnit>(scope)) { | ||
| // Update the compile unit with this incoming global variable | ||
| // expression during the finalizing step later. | ||
| allGVars[compileUnit].push_back(diGlobalExpr); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would consider moving this right below the definition of LLVM_DIGlobalVariableExpressionAttr? We already have such arrays for example for LLVM_AliasScopeArrayAttr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.