@@ -271,7 +271,7 @@ def LLVM_DILanguageParameter : LLVM_DIParameter<
271271>;
272272
273273def 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
277277def 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
556571def 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
628658def 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,
0 commit comments