Skip to content

Commit 7519755

Browse files
authored
Reapply "[MLIR][LLVM] Make DISubprogramAttr cyclic" (#106571) with fixes (#106947)
This reverts commit fa93be4, restoring commit d884b77, with fixes that ensure the CAPI declarations are exported properly. This commit implements LLVM_DIRecursiveTypeAttrInterface for the DISubprogramAttr to ensure cyclic subprograms can be imported properly. In the process multiple shortcuts around the recently introduced DIImportedEntityAttr can be removed.
1 parent 1e65b76 commit 7519755

File tree

14 files changed

+265
-176
lines changed

14 files changed

+265
-176
lines changed

flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
146146
elements.push_back(subrangeTy);
147147
}
148148
return mlir::LLVM::DICompositeTypeAttr::get(
149-
context, llvm::dwarf::DW_TAG_array_type, /*recursive_id=*/{},
150-
/*name=*/nullptr, /*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
149+
context, llvm::dwarf::DW_TAG_array_type, /*name=*/nullptr,
150+
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
151151
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0, elements,
152152
dataLocation, /*rank=*/nullptr, allocated, associated);
153153
}
@@ -188,7 +188,7 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
188188
}
189189

190190
return mlir::LLVM::DICompositeTypeAttr::get(
191-
context, llvm::dwarf::DW_TAG_structure_type, /*recursive_id=*/{},
191+
context, llvm::dwarf::DW_TAG_structure_type,
192192
mlir::StringAttr::get(context, result.second.name), fileAttr, line, scope,
193193
/*baseType=*/nullptr, mlir::LLVM::DIFlags::Zero, offset * 8,
194194
/*alignInBits=*/0, elements, /*dataLocation=*/nullptr, /*rank=*/nullptr,
@@ -236,8 +236,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
236236
// have been set to some valid default values.
237237

238238
return mlir::LLVM::DICompositeTypeAttr::get(
239-
context, llvm::dwarf::DW_TAG_array_type, /*recursive_id=*/{},
240-
/*name=*/nullptr, /*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
239+
context, llvm::dwarf::DW_TAG_array_type, /*name=*/nullptr,
240+
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
241241
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0, elements,
242242
/*dataLocation=*/nullptr, /*rank=*/nullptr, /*allocated=*/nullptr,
243243
/*associated=*/nullptr);

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,14 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIBasicTypeAttrGet(
234234
MlirContext ctx, unsigned int tag, MlirAttribute name, uint64_t sizeInBits,
235235
MlirLLVMTypeEncoding encoding);
236236

237+
/// Creates a self-referencing LLVM DICompositeType attribute.
238+
MLIR_CAPI_EXPORTED MlirAttribute
239+
mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId);
240+
237241
/// Creates a LLVM DICompositeType attribute.
238242
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
239-
MlirContext ctx, unsigned int tag, MlirAttribute recId, MlirAttribute name,
240-
MlirAttribute file, uint32_t line, MlirAttribute scope,
243+
MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag,
244+
MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope,
241245
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
242246
uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
243247
MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
@@ -311,13 +315,17 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDILocalVariableAttrGet(
311315
MlirAttribute diFile, unsigned int line, unsigned int arg,
312316
unsigned int alignInBits, MlirAttribute diType, int64_t flags);
313317

318+
/// Creates a self-referencing LLVM DISubprogramAttr attribute.
319+
MLIR_CAPI_EXPORTED MlirAttribute
320+
mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId);
321+
314322
/// Creates a LLVM DISubprogramAttr attribute.
315323
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDISubprogramAttrGet(
316-
MlirContext ctx, MlirAttribute id, MlirAttribute compileUnit,
317-
MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName,
318-
MlirAttribute file, unsigned int line, unsigned int scopeLine,
319-
uint64_t subprogramFlags, MlirAttribute type, intptr_t nRetainedNodes,
320-
MlirAttribute const *retainedNodes);
324+
MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
325+
MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
326+
MlirAttribute linkageName, MlirAttribute file, unsigned int line,
327+
unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
328+
intptr_t nRetainedNodes, MlirAttribute const *retainedNodes);
321329

322330
/// Gets the scope from this DISubprogramAttr.
323331
MLIR_CAPI_EXPORTED MlirAttribute
@@ -356,9 +364,9 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIModuleAttrGet(
356364

357365
/// Creates a LLVM DIImportedEntityAttr attribute.
358366
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIImportedEntityAttrGet(
359-
MlirContext ctx, unsigned int tag, MlirAttribute entity, MlirAttribute file,
360-
unsigned int line, MlirAttribute name, intptr_t nElements,
361-
MlirAttribute const *elements);
367+
MlirContext ctx, unsigned int tag, MlirAttribute scope,
368+
MlirAttribute entity, MlirAttribute file, unsigned int line,
369+
MlirAttribute name, intptr_t nElements, MlirAttribute const *elements);
362370

363371
/// Gets the scope of this DIModuleAttr.
364372
MLIR_CAPI_EXPORTED MlirAttribute

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

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def LLVM_DILanguageParameter : LLVM_DIParameter<
271271
>;
272272

273273
def LLVM_DITagParameter : LLVM_DIParameter<
274-
"tag", /*default=*/"", "Tag", /*errorCase=*/"llvm::dwarf::DW_TAG_invalid"
274+
"tag", /*default=*/"0", "Tag", /*errorCase=*/"llvm::dwarf::DW_TAG_invalid"
275275
>;
276276

277277
def LLVM_DIOperationEncodingParameter : LLVM_DIParameter<
@@ -375,14 +375,17 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
375375
[LLVM_DIRecursiveTypeAttrInterface],
376376
"DITypeAttr"> {
377377
let parameters = (ins
378-
LLVM_DITagParameter:$tag,
378+
// DIRecursiveTypeAttrInterface specific parameters.
379379
OptionalParameter<"DistinctAttr">:$recId,
380+
OptionalParameter<"bool">:$isRecSelf,
381+
// DICompositeType specific parameters.
382+
LLVM_DITagParameter:$tag,
380383
OptionalParameter<"StringAttr">:$name,
381384
OptionalParameter<"DIFileAttr">:$file,
382385
OptionalParameter<"uint32_t">:$line,
383386
OptionalParameter<"DIScopeAttr">:$scope,
384387
OptionalParameter<"DITypeAttr">:$baseType,
385-
OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags,
388+
OptionalParameter<"DIFlags">:$flags,
386389
OptionalParameter<"uint64_t">:$sizeInBits,
387390
OptionalParameter<"uint64_t">:$alignInBits,
388391
OptionalArrayRefParameter<"DINodeAttr">:$elements,
@@ -391,14 +394,26 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
391394
OptionalParameter<"DIExpressionAttr">:$allocated,
392395
OptionalParameter<"DIExpressionAttr">:$associated
393396
);
397+
let builders = [
398+
AttrBuilder<(ins
399+
"unsigned":$tag, "StringAttr":$name, "DIFileAttr":$file,
400+
"uint32_t":$line, "DIScopeAttr":$scope, "DITypeAttr":$baseType,
401+
"DIFlags":$flags, "uint64_t":$sizeInBits, "uint64_t":$alignInBits,
402+
"ArrayRef<DINodeAttr>":$elements, "DIExpressionAttr":$dataLocation,
403+
"DIExpressionAttr":$rank, "DIExpressionAttr":$allocated,
404+
"DIExpressionAttr":$associated
405+
), [{
406+
return $_get($_ctxt, /*recId=*/nullptr, /*isRecSelf=*/nullptr,
407+
tag, name, file, line, scope, baseType, flags, sizeInBits,
408+
alignInBits, elements, dataLocation, rank, allocated,
409+
associated);
410+
}]>
411+
];
394412
let assemblyFormat = "`<` struct(params) `>`";
395413
let extraClassDeclaration = [{
396414
/// Requirements of DIRecursiveTypeAttrInterface.
397415
/// @{
398416

399-
/// Get whether this attr describes a recursive self reference.
400-
bool isRecSelf() { return getTag() == 0; }
401-
402417
/// Get a copy of this type attr but with the recursive ID set to `recId`.
403418
DIRecursiveTypeAttrInterface withRecId(DistinctAttr recId);
404419

@@ -554,36 +569,51 @@ def LLVM_DILocalVariableAttr : LLVM_Attr<"DILocalVariable", "di_local_variable",
554569
//===----------------------------------------------------------------------===//
555570

556571
def LLVM_DISubprogramAttr : LLVM_Attr<"DISubprogram", "di_subprogram",
557-
/*traits=*/[], "DIScopeAttr"> {
572+
[LLVM_DIRecursiveTypeAttrInterface],
573+
"DIScopeAttr"> {
558574
let parameters = (ins
575+
// DIRecursiveTypeAttrInterface specific parameters.
576+
OptionalParameter<"DistinctAttr">:$recId,
577+
OptionalParameter<"bool">:$isRecSelf,
578+
// DISubprogramAttr specific parameters.
559579
OptionalParameter<"DistinctAttr">:$id,
560580
OptionalParameter<"DICompileUnitAttr">:$compileUnit,
561-
"DIScopeAttr":$scope,
581+
OptionalParameter<"DIScopeAttr">:$scope,
562582
OptionalParameter<"StringAttr">:$name,
563583
OptionalParameter<"StringAttr">:$linkageName,
564-
"DIFileAttr":$file,
584+
OptionalParameter<"DIFileAttr">:$file,
565585
OptionalParameter<"unsigned">:$line,
566586
OptionalParameter<"unsigned">:$scopeLine,
567587
OptionalParameter<"DISubprogramFlags">:$subprogramFlags,
568588
OptionalParameter<"DISubroutineTypeAttr">:$type,
569589
OptionalArrayRefParameter<"DINodeAttr">:$retainedNodes
570590
);
571591
let builders = [
572-
AttrBuilderWithInferredContext<(ins
592+
AttrBuilder<(ins
573593
"DistinctAttr":$id, "DICompileUnitAttr":$compileUnit,
574-
"DIScopeAttr":$scope, "StringRef":$name, "StringRef":$linkageName,
594+
"DIScopeAttr":$scope, "StringAttr":$name, "StringAttr":$linkageName,
575595
"DIFileAttr":$file, "unsigned":$line, "unsigned":$scopeLine,
576596
"DISubprogramFlags":$subprogramFlags, "DISubroutineTypeAttr":$type,
577597
"ArrayRef<DINodeAttr>":$retainedNodes
578598
), [{
579-
MLIRContext *ctx = file.getContext();
580-
return $_get(ctx, id, compileUnit, scope, StringAttr::get(ctx, name),
581-
StringAttr::get(ctx, linkageName), file, line,
582-
scopeLine, subprogramFlags, type, retainedNodes);
599+
return $_get($_ctxt, /*recId=*/nullptr, /*isRecSelf=*/false, id, compileUnit,
600+
scope, name, linkageName, file, line, scopeLine,
601+
subprogramFlags, type, retainedNodes);
583602
}]>
584603
];
585-
586604
let assemblyFormat = "`<` struct(params) `>`";
605+
let extraClassDeclaration = [{
606+
/// Requirements of DIRecursiveTypeAttrInterface.
607+
/// @{
608+
609+
/// Get a copy of this type attr but with the recursive ID set to `recId`.
610+
DIRecursiveTypeAttrInterface withRecId(DistinctAttr recId);
611+
612+
/// Build a rec-self instance using the provided `recId`.
613+
static DIRecursiveTypeAttrInterface getRecSelf(DistinctAttr recId);
614+
615+
/// @}
616+
}];
587617
}
588618

589619
//===----------------------------------------------------------------------===//
@@ -627,13 +657,9 @@ def LLVM_DINamespaceAttr : LLVM_Attr<"DINamespace", "di_namespace",
627657

628658
def LLVM_DIImportedEntityAttr : LLVM_Attr<"DIImportedEntity", "di_imported_entity",
629659
/*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.
635660
let parameters = (ins
636661
LLVM_DITagParameter:$tag,
662+
"DIScopeAttr":$scope,
637663
"DINodeAttr":$entity,
638664
OptionalParameter<"DIFileAttr">:$file,
639665
OptionalParameter<"unsigned">:$line,

mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def LLVM_DIRecursiveTypeAttrInterface
406406
let methods = [
407407
InterfaceMethod<[{
408408
Get whether this attr describes a recursive self reference.
409-
}], "bool", "isRecSelf", (ins)>,
409+
}], "bool", "getIsRecSelf", (ins)>,
410410
InterfaceMethod<[{
411411
Get the recursive ID used for matching "rec-decl" with "rec-self".
412412
If this attr instance is not recursive, return a null attribute.

mlir/lib/CAPI/Dialect/LLVM.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,14 @@ MlirAttribute mlirLLVMDIBasicTypeAttrGet(MlirContext ctx, unsigned int tag,
159159
unwrap(ctx), tag, cast<StringAttr>(unwrap(name)), sizeInBits, encoding));
160160
}
161161

162+
MlirAttribute mlirLLVMDICompositeTypeAttrGetRecSelf(MlirAttribute recId) {
163+
return wrap(
164+
DICompositeTypeAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
165+
}
166+
162167
MlirAttribute mlirLLVMDICompositeTypeAttrGet(
163-
MlirContext ctx, unsigned int tag, MlirAttribute recId, MlirAttribute name,
164-
MlirAttribute file, uint32_t line, MlirAttribute scope,
168+
MlirContext ctx, MlirAttribute recId, bool isRecSelf, unsigned int tag,
169+
MlirAttribute name, MlirAttribute file, uint32_t line, MlirAttribute scope,
165170
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
166171
uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
167172
MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
@@ -170,7 +175,7 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
170175
elementsStorage.reserve(nElements);
171176

172177
return wrap(DICompositeTypeAttr::get(
173-
unwrap(ctx), tag, cast<DistinctAttr>(unwrap(recId)),
178+
unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf, tag,
174179
cast<StringAttr>(unwrap(name)), cast<DIFileAttr>(unwrap(file)), line,
175180
cast<DIScopeAttr>(unwrap(scope)), cast<DITypeAttr>(unwrap(baseType)),
176181
DIFlags(flags), sizeInBits, alignInBits,
@@ -289,16 +294,21 @@ MlirAttribute mlirLLVMDISubroutineTypeAttrGet(MlirContext ctx,
289294
[](Attribute a) { return cast<DITypeAttr>(a); })));
290295
}
291296

297+
MlirAttribute mlirLLVMDISubprogramAttrGetRecSelf(MlirAttribute recId) {
298+
return wrap(DISubprogramAttr::getRecSelf(cast<DistinctAttr>(unwrap(recId))));
299+
}
300+
292301
MlirAttribute mlirLLVMDISubprogramAttrGet(
293-
MlirContext ctx, MlirAttribute id, MlirAttribute compileUnit,
294-
MlirAttribute scope, MlirAttribute name, MlirAttribute linkageName,
295-
MlirAttribute file, unsigned int line, unsigned int scopeLine,
296-
uint64_t subprogramFlags, MlirAttribute type, intptr_t nRetainedNodes,
297-
MlirAttribute const *retainedNodes) {
302+
MlirContext ctx, MlirAttribute recId, bool isRecSelf, MlirAttribute id,
303+
MlirAttribute compileUnit, MlirAttribute scope, MlirAttribute name,
304+
MlirAttribute linkageName, MlirAttribute file, unsigned int line,
305+
unsigned int scopeLine, uint64_t subprogramFlags, MlirAttribute type,
306+
intptr_t nRetainedNodes, MlirAttribute const *retainedNodes) {
298307
SmallVector<Attribute> nodesStorage;
299308
nodesStorage.reserve(nRetainedNodes);
300309
return wrap(DISubprogramAttr::get(
301-
unwrap(ctx), cast<DistinctAttr>(unwrap(id)),
310+
unwrap(ctx), cast<DistinctAttr>(unwrap(recId)), isRecSelf,
311+
cast<DistinctAttr>(unwrap(id)),
302312
cast<DICompileUnitAttr>(unwrap(compileUnit)),
303313
cast<DIScopeAttr>(unwrap(scope)), cast<StringAttr>(unwrap(name)),
304314
cast<StringAttr>(unwrap(linkageName)), cast<DIFileAttr>(unwrap(file)),
@@ -353,14 +363,15 @@ MlirAttribute mlirLLVMDIModuleAttrGetScope(MlirAttribute diModule) {
353363
}
354364

355365
MlirAttribute mlirLLVMDIImportedEntityAttrGet(
356-
MlirContext ctx, unsigned int tag, MlirAttribute entity, MlirAttribute file,
357-
unsigned int line, MlirAttribute name, intptr_t nElements,
358-
MlirAttribute const *elements) {
366+
MlirContext ctx, unsigned int tag, MlirAttribute scope,
367+
MlirAttribute entity, MlirAttribute file, unsigned int line,
368+
MlirAttribute name, intptr_t nElements, MlirAttribute const *elements) {
359369
SmallVector<Attribute> elementsStorage;
360370
elementsStorage.reserve(nElements);
361371
return wrap(DIImportedEntityAttr::get(
362-
unwrap(ctx), tag, cast<DINodeAttr>(unwrap(entity)),
363-
cast<DIFileAttr>(unwrap(file)), line, cast<StringAttr>(unwrap(name)),
372+
unwrap(ctx), tag, cast<DIScopeAttr>(unwrap(scope)),
373+
cast<DINodeAttr>(unwrap(entity)), cast<DIFileAttr>(unwrap(file)), line,
374+
cast<StringAttr>(unwrap(name)),
364375
llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
365376
[](Attribute a) { return cast<DINodeAttr>(a); })));
366377
}

mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,33 @@ void printExpressionArg(AsmPrinter &printer, uint64_t opcode,
203203
DIRecursiveTypeAttrInterface
204204
DICompositeTypeAttr::withRecId(DistinctAttr recId) {
205205
return DICompositeTypeAttr::get(
206-
getContext(), getTag(), recId, getName(), getFile(), getLine(),
207-
getScope(), getBaseType(), getFlags(), getSizeInBits(), getAlignInBits(),
208-
getElements(), getDataLocation(), getRank(), getAllocated(),
209-
getAssociated());
206+
getContext(), recId, getIsRecSelf(), getTag(), getName(), getFile(),
207+
getLine(), getScope(), getBaseType(), getFlags(), getSizeInBits(),
208+
getAlignInBits(), getElements(), getDataLocation(), getRank(),
209+
getAllocated(), getAssociated());
210210
}
211211

212212
DIRecursiveTypeAttrInterface
213213
DICompositeTypeAttr::getRecSelf(DistinctAttr recId) {
214-
return DICompositeTypeAttr::get(recId.getContext(), 0, recId, {}, {}, 0, {},
215-
{}, DIFlags(), 0, 0, {}, {}, {}, {}, {});
214+
return DICompositeTypeAttr::get(recId.getContext(), recId, /*isRecSelf=*/true,
215+
0, {}, {}, 0, {}, {}, DIFlags(), 0, 0, {}, {},
216+
{}, {}, {});
217+
}
218+
219+
//===----------------------------------------------------------------------===//
220+
// DISubprogramAttr
221+
//===----------------------------------------------------------------------===//
222+
223+
DIRecursiveTypeAttrInterface DISubprogramAttr::withRecId(DistinctAttr recId) {
224+
return DISubprogramAttr::get(
225+
getContext(), recId, getIsRecSelf(), getId(), getCompileUnit(),
226+
getScope(), getName(), getLinkageName(), getFile(), getLine(),
227+
getScopeLine(), getSubprogramFlags(), getType(), getRetainedNodes());
228+
}
229+
230+
DIRecursiveTypeAttrInterface DISubprogramAttr::getRecSelf(DistinctAttr recId) {
231+
return DISubprogramAttr::get(recId.getContext(), recId, /*isRecSelf=*/true,
232+
{}, {}, {}, {}, {}, 0, 0, {}, {}, {}, {});
216233
}
217234

218235
//===----------------------------------------------------------------------===//

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3155,9 +3155,9 @@ struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface {
31553155
.Case<AccessGroupAttr, AliasScopeAttr, AliasScopeDomainAttr,
31563156
DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
31573157
DIDerivedTypeAttr, DIFileAttr, DIGlobalVariableAttr,
3158-
DIGlobalVariableExpressionAttr, DILabelAttr, DILexicalBlockAttr,
3159-
DILexicalBlockFileAttr, DILocalVariableAttr, DIModuleAttr,
3160-
DINamespaceAttr, DINullTypeAttr, DIStringTypeAttr,
3158+
DIGlobalVariableExpressionAttr, DIImportedEntityAttr, DILabelAttr,
3159+
DILexicalBlockAttr, DILexicalBlockFileAttr, DILocalVariableAttr,
3160+
DIModuleAttr, DINamespaceAttr, DINullTypeAttr, DIStringTypeAttr,
31613161
DISubprogramAttr, DISubroutineTypeAttr, LoopAnnotationAttr,
31623162
LoopVectorizeAttr, LoopInterleaveAttr, LoopUnrollAttr,
31633163
LoopUnrollAndJamAttr, LoopLICMAttr, LoopDistributeAttr,

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
6565
auto subroutineTypeAttr =
6666
LLVM::DISubroutineTypeAttr::get(context, llvm::dwarf::DW_CC_normal, {});
6767

68-
StringAttr funcNameAttr = llvmFunc.getNameAttr();
6968
// Only definitions need a distinct identifier and a compilation unit.
7069
DistinctAttr id;
7170
auto subprogramFlags = LLVM::DISubprogramFlags::Optimized;
@@ -75,11 +74,10 @@ static void addScopeToFunction(LLVM::LLVMFuncOp llvmFunc,
7574
} else {
7675
compileUnitAttr = {};
7776
}
77+
auto funcName = StringAttr::get(context, llvmFunc.getName());
7878
auto subprogramAttr = LLVM::DISubprogramAttr::get(
79-
context, id, compileUnitAttr, fileAttr, funcNameAttr, funcNameAttr,
80-
fileAttr,
81-
/*line=*/line,
82-
/*scopeline=*/col, subprogramFlags, subroutineTypeAttr,
79+
context, id, compileUnitAttr, fileAttr, funcName, funcName, fileAttr,
80+
/*line=*/line, /*scopeline=*/col, subprogramFlags, subroutineTypeAttr,
8381
/*retainedNodes=*/{});
8482
llvmFunc->setLoc(FusedLoc::get(context, {loc}, subprogramAttr));
8583
}

0 commit comments

Comments
 (0)