Skip to content

Commit 895f3c0

Browse files
committed
Handle review comments.
Mostly formatting nits and adding comments.
1 parent 1e16cc7 commit 895f3c0

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

mlir/include/mlir-c/Dialect/LLVM.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIModuleAttrGet(
357357
/// Creates a LLVM DIImportedEntityAttr attribute.
358358
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIImportedEntityAttrGet(
359359
MlirContext ctx, unsigned int tag, MlirAttribute entity, MlirAttribute file,
360-
unsigned int line, MlirAttribute name, intptr_t nNodes,
361-
MlirAttribute const *elements);
360+
unsigned int line, MlirAttribute name, intptr_t nRetainedNodes,
361+
MlirAttribute const *retainedNodes);
362362

363363
/// Gets the scope of this DIModuleAttr.
364364
MLIR_CAPI_EXPORTED MlirAttribute

mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,11 @@ def LLVM_DINamespaceAttr : LLVM_Attr<"DINamespace", "di_namespace",
627627

628628
def LLVM_DIImportedEntityAttr : LLVM_Attr<"DIImportedEntity", "di_imported_entity",
629629
/*traits=*/[], "DINodeAttr"> {
630+
/// TODO: DIImportedEntity has a 'scope' field which represents the scope where
631+
/// this entity is imported. Currently, we are not adding a 'scope' field in
632+
/// DIImportedEntityAttr to avoid cyclic dependency. As DIImportedEntityAttr
633+
/// entries will be contained inside a scope entity (e.g. DISubprogramAttr),
634+
/// the scope can easily be inferred.
630635
let parameters = (ins
631636
LLVM_DITagParameter:$tag,
632637
"DINodeAttr":$entity,

mlir/lib/CAPI/Dialect/LLVM.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,14 @@ MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
353353

354354
MlirAttribute mlirLLVMDIImportedEntityAttrGet(
355355
MlirContext ctx, unsigned int tag, MlirAttribute entity, MlirAttribute file,
356-
unsigned int line, MlirAttribute name, intptr_t nElements,
357-
MlirAttribute const *elements) {
358-
SmallVector<Attribute> elementsStorage;
359-
elementsStorage.reserve(nElements);
356+
unsigned int line, MlirAttribute name, intptr_t nRetainedNodes,
357+
MlirAttribute const *retainedNodes) {
358+
SmallVector<Attribute> nodesStorage;
359+
nodesStorage.reserve(nRetainedNodes);
360360
return wrap(DIImportedEntityAttr::get(
361361
unwrap(ctx), tag, cast<DINodeAttr>(unwrap(entity)),
362362
cast<DIFileAttr>(unwrap(file)), line, cast<StringAttr>(unwrap(name)),
363-
llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
364-
[](Attribute a) { return cast<DINodeAttr>(a); })));
363+
llvm::map_to_vector(
364+
unwrapList(nRetainedNodes, retainedNodes, nodesStorage),
365+
[](Attribute a) { return cast<DINodeAttr>(a); })));
365366
}

mlir/lib/Dialect/LLVMIR/Transforms/DIScopeForLLVMFuncOp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
7979
context, id, compileUnitAttr, fileAttr, funcNameAttr, funcNameAttr,
8080
fileAttr,
8181
/*line=*/line,
82-
/*scopeline=*/col, subprogramFlags, subroutineTypeAttr, {});
82+
/*scopeline=*/col, subprogramFlags, subroutineTypeAttr,
83+
/*retainedNodes=*/{});
8384
llvmFunc->setLoc(FusedLoc::get(context, {loc}, subprogramAttr));
8485
}
8586

mlir/lib/Target/LLVMIR/DebugImporter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ DINamespaceAttr DebugImporter::translateImpl(llvm::DINamespace *node) {
211211
DIImportedEntityAttr
212212
DebugImporter::translateImpl(llvm::DIImportedEntity *node) {
213213
SmallVector<DINodeAttr> elements;
214-
215214
for (llvm::DINode *element : node->getElements()) {
216215
assert(element && "expected a non-null element type");
217216
elements.push_back(translate(element));
@@ -240,9 +239,8 @@ DISubprogramAttr DebugImporter::translateImpl(llvm::DISubprogram *node) {
240239
return nullptr;
241240

242241
SmallVector<DINodeAttr> retainedNodes;
243-
244-
for (auto node : node->getRetainedNodes())
245-
retainedNodes.push_back(translate(node));
242+
for (llvm::DINode *retainedNode : node->getRetainedNodes())
243+
retainedNodes.push_back(translate(retainedNode));
246244

247245
return DISubprogramAttr::get(context, id, translate(node->getUnit()), scope,
248246
getStringAttrOrNull(node->getRawName()),

mlir/lib/Target/LLVMIR/DebugTranslation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,12 @@ llvm::DISubprogram *DebugTranslation::translateImpl(DISubprogramAttr attr) {
306306
static_cast<llvm::DISubprogram::DISPFlags>(attr.getSubprogramFlags()),
307307
compileUnit);
308308

309+
// DIImportedEntity requires scope information which DIImportedEntityAttr does
310+
// not have. This is why we translate DIImportedEntityAttr after we have
311+
// created DISubprogram as we can use it as the scope.
309312
SmallVector<llvm::Metadata *> retainedNodes;
310-
311-
for (auto nodeAttr : attr.getRetainedNodes()) {
312-
if (DIImportedEntityAttr importedAttr =
313-
dyn_cast<DIImportedEntityAttr>(nodeAttr)) {
313+
for (DINodeAttr nodeAttr : attr.getRetainedNodes()) {
314+
if (auto importedAttr = dyn_cast<DIImportedEntityAttr>(nodeAttr)) {
314315
llvm::DINode *dn = translate(importedAttr, node);
315316
retainedNodes.push_back(dn);
316317
}

mlir/lib/Target/LLVMIR/DebugTranslation.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class DebugTranslation {
8989
llvm::DISubrange *translateImpl(DISubrangeAttr attr);
9090
llvm::DISubroutineType *translateImpl(DISubroutineTypeAttr attr);
9191
llvm::DIType *translateImpl(DITypeAttr attr);
92+
93+
/// Currently, DIImportedEntityAttr does not have a scope field to avoid a
94+
/// cyclic dependency. The scope information is obtained from the entity
95+
/// which holds the list of DIImportedEntityAttr. This requires that scope
96+
/// information be passed to translate function.
9297
llvm::DIImportedEntity *translate(DIImportedEntityAttr attr, llvm::DIScope *);
9398

9499
/// Attributes that support self recursion need to implement an additional

0 commit comments

Comments
 (0)