Skip to content

Commit 8bca1b6

Browse files
committed
Handle review comments.
1 parent 6afd64e commit 8bca1b6

File tree

2 files changed

+40
-42
lines changed

2 files changed

+40
-42
lines changed

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,48 +1056,46 @@ LogicalResult ModuleTranslation::convertGlobals() {
10561056

10571057
// Add debug information if present.
10581058
if (op.getDbgExprs()) {
1059-
for (auto attr : *op.getDbgExprs()) {
1060-
if (auto exprAttr =
1061-
dyn_cast_if_present<DIGlobalVariableExpressionAttr>(attr)) {
1062-
llvm::DIGlobalVariableExpression *diGlobalExpr =
1063-
debugTranslation->translateGlobalVariableExpression(exprAttr);
1064-
llvm::DIGlobalVariable *diGlobalVar = diGlobalExpr->getVariable();
1065-
var->addDebugInfo(diGlobalExpr);
1066-
1067-
// There is no `globals` field in DICompileUnitAttr which can be
1068-
// directly assigned to DICompileUnit. We have to build the list by
1069-
// looking at the dbgExpr of all the GlobalOps. The scope of the
1070-
// variable is used to get the DICompileUnit in which to add it. But
1071-
// there are cases where the scope of a global does not directly point
1072-
// to the DICompileUnit and we have to do a bit more work to get to
1073-
// it. Some of those cases are:
1074-
//
1075-
// 1. For the languages that support modules, the scope hierarchy can
1076-
// be variable -> DIModule -> DICompileUnit
1077-
//
1078-
// 2. For the Fortran common block variable, the scope hierarchy can
1079-
// be variable -> DICommonBlock -> DISubprogram -> DICompileUnit
1080-
//
1081-
// 3. For entities like static local variables in C or variable with
1082-
// SAVE attribute in Fortran, the scope hierarchy can be
1083-
// variable -> DISubprogram -> DICompileUnit
1084-
llvm::DIScope *scope = diGlobalVar->getScope();
1085-
if (auto *mod = dyn_cast_if_present<llvm::DIModule>(scope))
1086-
scope = mod->getScope();
1087-
else if (auto *cb = dyn_cast_if_present<llvm::DICommonBlock>(scope)) {
1088-
if (auto *sp =
1089-
dyn_cast_if_present<llvm::DISubprogram>(cb->getScope()))
1090-
scope = sp->getUnit();
1091-
} else if (auto *sp = dyn_cast_if_present<llvm::DISubprogram>(scope))
1059+
for (auto exprAttr :
1060+
op.getDbgExprs()->getAsRange<DIGlobalVariableExpressionAttr>()) {
1061+
llvm::DIGlobalVariableExpression *diGlobalExpr =
1062+
debugTranslation->translateGlobalVariableExpression(exprAttr);
1063+
llvm::DIGlobalVariable *diGlobalVar = diGlobalExpr->getVariable();
1064+
var->addDebugInfo(diGlobalExpr);
1065+
1066+
// There is no `globals` field in DICompileUnitAttr which can be
1067+
// directly assigned to DICompileUnit. We have to build the list by
1068+
// looking at the dbgExpr of all the GlobalOps. The scope of the
1069+
// variable is used to get the DICompileUnit in which to add it. But
1070+
// there are cases where the scope of a global does not directly point
1071+
// to the DICompileUnit and we have to do a bit more work to get to
1072+
// it. Some of those cases are:
1073+
//
1074+
// 1. For the languages that support modules, the scope hierarchy can
1075+
// be variable -> DIModule -> DICompileUnit
1076+
//
1077+
// 2. For the Fortran common block variable, the scope hierarchy can
1078+
// be variable -> DICommonBlock -> DISubprogram -> DICompileUnit
1079+
//
1080+
// 3. For entities like static local variables in C or variable with
1081+
// SAVE attribute in Fortran, the scope hierarchy can be
1082+
// variable -> DISubprogram -> DICompileUnit
1083+
llvm::DIScope *scope = diGlobalVar->getScope();
1084+
if (auto *mod = dyn_cast_if_present<llvm::DIModule>(scope))
1085+
scope = mod->getScope();
1086+
else if (auto *cb = dyn_cast_if_present<llvm::DICommonBlock>(scope)) {
1087+
if (auto *sp =
1088+
dyn_cast_if_present<llvm::DISubprogram>(cb->getScope()))
10921089
scope = sp->getUnit();
1093-
1094-
// Get the compile unit (scope) of the the global variable.
1095-
if (llvm::DICompileUnit *compileUnit =
1096-
dyn_cast_if_present<llvm::DICompileUnit>(scope)) {
1097-
// Update the compile unit with this incoming global variable
1098-
// expression during the finalizing step later.
1099-
allGVars[compileUnit].push_back(diGlobalExpr);
1100-
}
1090+
} else if (auto *sp = dyn_cast_if_present<llvm::DISubprogram>(scope))
1091+
scope = sp->getUnit();
1092+
1093+
// Get the compile unit (scope) of the the global variable.
1094+
if (llvm::DICompileUnit *compileUnit =
1095+
dyn_cast_if_present<llvm::DICompileUnit>(scope)) {
1096+
// Update the compile unit with this incoming global variable
1097+
// expression during the finalizing step later.
1098+
allGVars[compileUnit].push_back(diGlobalExpr);
11011099
}
11021100
}
11031101
}

mlir/test/Target/LLVMIR/llvmir-debug.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ llvm.func @test() {
693693

694694
// -----
695695

696-
// Test multiple DIGlobalVariableExpression on a global
696+
// Test multiple DIGlobalVariableExpression on a global.
697697
#bt = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "int", sizeInBits = 32>
698698
#file = #llvm.di_file<"test.f90" in "">
699699
#cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_C,

0 commit comments

Comments
 (0)