Skip to content
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

[mlir][debuginfo] Add support for subroutine annotations #110946

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -586,19 +586,20 @@ def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",
OptionalParameter<"unsigned">:$scopeLine,
OptionalParameter<"DISubprogramFlags">:$subprogramFlags,
OptionalParameter<"DISubroutineTypeAttr">:$type,
OptionalArrayRefParameter<"DINodeAttr">:$retainedNodes
OptionalArrayRefParameter<"DINodeAttr">:$retainedNodes,
OptionalArrayRefParameter<"DINodeAttr">:$annotations
);
let builders = [
AttrBuilder<(ins
"DistinctAttr":$id, "DICompileUnitAttr":$compileUnit,
"DIScopeAttr":$scope, "StringAttr":$name, "StringAttr":$linkageName,
"DIFileAttr":$file, "unsigned":$line, "unsigned":$scopeLine,
"DISubprogramFlags":$subprogramFlags, "DISubroutineTypeAttr":$type,
"ArrayRef<DINodeAttr>":$retainedNodes
"ArrayRef<DINodeAttr>":$retainedNodes, "ArrayRef<DINodeAttr>":$annotations
), [{
return $_get($_ctxt, /*recId=*/nullptr, /*isRecSelf=*/false, id, compileUnit,
scope, name, linkageName, file, line, scopeLine,
subprogramFlags, type, retainedNodes);
subprogramFlags, type, retainedNodes, annotations);
}]>
];
let assemblyFormat = "`<` struct(params) `>`";
Expand Down Expand Up @@ -670,6 +671,21 @@ def LLVM_DIImportedEntityAttr : LLVM_Attr<"DIImportedEntity", "di_imported_entit
let assemblyFormat = "`<` struct(params) `>`";
}

//===----------------------------------------------------------------------===//
// DIStringAnnotationAttr
//===----------------------------------------------------------------------===//

def LLVM_DIStringAnnotationAttr : LLVM_Attr<"DIStringAnnotation",
"di_string_annotation",
/*traits=*/[], "DINodeAttr"> {
let parameters = (ins
"StringAttr":$name,
"StringAttr":$value
);

let assemblyFormat = "`<` struct(params) `>`";
}

//===----------------------------------------------------------------------===//
// DISubrangeAttr
//===----------------------------------------------------------------------===//
Expand Down
17 changes: 9 additions & 8 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ bool DINodeAttr::classof(Attribute attr) {
DIDerivedTypeAttr, DIFileAttr, DIGlobalVariableAttr,
DIImportedEntityAttr, DILabelAttr, DILexicalBlockAttr,
DILexicalBlockFileAttr, DILocalVariableAttr, DIModuleAttr,
DINamespaceAttr, DINullTypeAttr, DIStringTypeAttr,
DISubprogramAttr, DISubrangeAttr, DISubroutineTypeAttr>(
attr);
DINamespaceAttr, DINullTypeAttr, DIStringAnnotationAttr,
DIStringTypeAttr, DISubprogramAttr, DISubrangeAttr,
DISubroutineTypeAttr>(attr);
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -221,15 +221,16 @@ DICompositeTypeAttr::getRecSelf(DistinctAttr recId) {
//===----------------------------------------------------------------------===//

DIRecursiveTypeAttrInterface DISubprogramAttr::withRecId(DistinctAttr recId) {
return DISubprogramAttr::get(
getContext(), recId, getIsRecSelf(), getId(), getCompileUnit(),
getScope(), getName(), getLinkageName(), getFile(), getLine(),
getScopeLine(), getSubprogramFlags(), getType(), getRetainedNodes());
return DISubprogramAttr::get(getContext(), recId, getIsRecSelf(), getId(),
getCompileUnit(), getScope(), getName(),
getLinkageName(), getFile(), getLine(),
getScopeLine(), getSubprogramFlags(), getType(),
getRetainedNodes(), getAnnotations());
}

DIRecursiveTypeAttrInterface DISubprogramAttr::getRecSelf(DistinctAttr recId) {
return DISubprogramAttr::get(recId.getContext(), recId, /*isRecSelf=*/true,
{}, {}, {}, {}, {}, 0, 0, {}, {}, {}, {});
{}, {}, {}, {}, {}, 0, 0, {}, {}, {}, {}, {});
}

//===----------------------------------------------------------------------===//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
auto subprogramAttr = LLVM::DISubprogramAttr::get(
context, id, compileUnitAttr, fileAttr, funcName, funcName, fileAttr,
/*line=*/line, /*scopeline=*/col, subprogramFlags, subroutineTypeAttr,
/*retainedNodes=*/{});
/*retainedNodes=*/{}, /*annotations=*/{});
llvmFunc->setLoc(FusedLoc::get(context, {loc}, subprogramAttr));
}

Expand Down
10 changes: 9 additions & 1 deletion mlir/lib/Target/LLVMIR/DebugTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ DebugTranslation::getMDTupleOrNull(ArrayRef<DINodeAttr> elements) {
return nullptr;
SmallVector<llvm::Metadata *> llvmElements = llvm::to_vector(
llvm::map_range(elements, [&](DINodeAttr attr) -> llvm::Metadata * {
if (DIStringAnnotationAttr annAttr =
dyn_cast<DIStringAnnotationAttr>(attr)) {
llvm::Metadata *ops[2] = {
llvm::MDString::get(llvmCtx, annAttr.getName()),
llvm::MDString::get(llvmCtx, annAttr.getValue())};
return llvm::MDNode::get(llvmCtx, ops);
}
return translate(attr);
}));
return llvm::MDNode::get(llvmCtx, llvmElements);
Expand Down Expand Up @@ -332,7 +339,8 @@ llvm::DISubprogram *DebugTranslation::translateImpl(DISubprogramAttr attr) {
/*ThisAdjustment=*/0, llvm::DINode::FlagZero,
static_cast<llvm::DISubprogram::DISPFlags>(attr.getSubprogramFlags()),
compileUnit, /*TemplateParams=*/nullptr, /*Declaration=*/nullptr,
getMDTupleOrNull(attr.getRetainedNodes()));
getMDTupleOrNull(attr.getRetainedNodes()), nullptr,
getMDTupleOrNull(attr.getAnnotations()));
if (attr.getId())
distinctAttrToNode.try_emplace(attr.getId(), node);
return node;
Expand Down
Loading