[MLIR][LLVM] Add variant part debug info support#195321
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-mlir-llvm @llvm/pr-subscribers-flang-fir-hlfir Author: jiel-nv ChangesSummaryThis PR extends the MLIR LLVM dialect debug-info attributes to represent DWARF variant parts, discriminators, and per-alternative discriminator values. The change adds Details
Patch is 26.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/195321.diff 13 Files Affected:
diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
index da7a513315a4e..f6e18c5b27391 100644
--- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
+++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
@@ -187,7 +187,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
dataLocation, rank, /*allocated=*/nullptr,
- /*associated=*/nullptr, elements);
+ /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
}
addOp(llvm::dwarf::DW_OP_push_object_address, {});
@@ -264,7 +265,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
context, llvm::dwarf::DW_TAG_array_type, /*name=*/nullptr,
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
- dataLocation, /*rank=*/nullptr, allocated, associated, elements);
+ dataLocation, /*rank=*/nullptr, allocated, associated,
+ /*identifier=*/nullptr, /*discriminator=*/nullptr, elements);
}
std::pair<std::uint64_t, unsigned short>
@@ -398,7 +400,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
mlir::StringAttr::get(context, ""), fileAttr, /*line=*/0, scope,
/*baseType=*/nullptr, mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0,
/*alignInBits=*/0, /*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, elements);
+ /*allocated=*/nullptr, /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
DerivedTypeCache::ActiveLevels nestedRecursions =
derivedTypeCache.startTranslating(Ty, placeHolder);
@@ -438,7 +441,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
convertType(seqTy.getEleTy(), fileAttr, scope, declOp),
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
/*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, arrayElements);
+ /*allocated=*/nullptr, /*associated=*/nullptr,
+ /*identifier=*/nullptr, /*discriminator=*/nullptr, arrayElements);
} else
elemTy = convertType(fieldTy, fileAttr, scope, /*declOp=*/nullptr);
offset = llvm::alignTo(offset, byteAlign);
@@ -459,7 +463,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
mlir::StringAttr::get(context, sourceName.name), fileAttr, line, scope,
/*baseType=*/nullptr, mlir::LLVM::DIFlags::Zero, offset * 8,
/*alignInBits=*/0, /*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, elements);
+ /*allocated=*/nullptr, /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
derivedTypeCache.finalize(Ty, finalAttr, std::move(nestedRecursions));
@@ -503,7 +508,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertTupleType(
mlir::StringAttr::get(context, ""), fileAttr, /*line=*/0, scope,
/*baseType=*/nullptr, mlir::LLVM::DIFlags::Zero, offset * 8,
/*alignInBits=*/0, /*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, elements);
+ /*allocated=*/nullptr, /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
derivedTypeCache.finalize(Ty, typeAttr, std::move(nestedRecursions));
return typeAttr;
}
@@ -565,7 +571,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
/*dataLocation=*/nullptr, /*rank=*/nullptr, /*allocated=*/nullptr,
- /*associated=*/nullptr, elements);
+ /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
}
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertVectorType(
@@ -598,7 +605,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertVectorType(
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Vector, sizeInBits, /*alignInBits=*/0,
/*dataLocation=*/nullptr, /*rank=*/nullptr, /*allocated=*/nullptr,
- /*associated=*/nullptr, elements);
+ /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
}
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
diff --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index 5170f01a2f621..09d3ad198a3b2 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -307,7 +307,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
- MlirAttribute associated);
+ MlirAttribute associated, MlirAttribute identifier,
+ MlirAttribute discriminator);
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void);
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 22face8b9d4b0..bb958213abd2d 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -494,6 +494,8 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
OptionalParameter<"DIExpressionAttr">:$rank,
OptionalParameter<"DIExpressionAttr">:$allocated,
OptionalParameter<"DIExpressionAttr">:$associated,
+ OptionalParameter<"StringAttr">:$identifier,
+ OptionalParameter<"DIDerivedTypeAttr">:$discriminator,
OptionalArrayRefParameter<"DINodeAttr">:$elements
);
let builders = [
@@ -503,12 +505,13 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
"DIFlags":$flags, "uint64_t":$sizeInBits, "uint64_t":$alignInBits,
"DIExpressionAttr":$dataLocation, "DIExpressionAttr":$rank,
"DIExpressionAttr":$allocated, "DIExpressionAttr":$associated,
+ "StringAttr":$identifier, "DIDerivedTypeAttr":$discriminator,
"ArrayRef<DINodeAttr>":$elements
), [{
- return $_get($_ctxt, /*recId=*/nullptr, /*isRecSelf=*/nullptr,
+ return $_get($_ctxt, /*recId=*/nullptr, /*isRecSelf=*/false,
tag, name, file, line, scope, baseType, flags, sizeInBits,
alignInBits, dataLocation, rank, allocated,
- associated, elements);
+ associated, identifier, discriminator, elements);
}]>
];
let assemblyFormat = "`<` struct(params) `>`";
@@ -547,9 +550,10 @@ def LLVM_DIDerivedTypeAttr : LLVM_Attr<"DIDerivedType", "di_derived_type",
OptionalParameter<"uint64_t">:$offsetInBits,
OptionalParameter<"std::optional<unsigned>">:$dwarfAddressSpace,
OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags,
- OptionalParameter<"DINodeAttr">:$extraData
+ OptionalParameter<"::mlir::Attribute">:$extraData
);
let assemblyFormat = "`<` struct(params) `>`";
+ let genVerifyDecl = 1;
// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
index 05b88b428102c..a5040d5104ab9 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
@@ -189,6 +189,8 @@ def DICompositeTypeAttr : DialectAttribute<(attr
OptionalAttribute<"DIExpressionAttr">:$rank,
OptionalAttribute<"DIExpressionAttr">:$allocated,
OptionalAttribute<"DIExpressionAttr">:$associated,
+ OptionalAttribute<"StringAttr">:$identifier,
+ OptionalAttribute<"DIDerivedTypeAttr">:$discriminator,
OptionalArrayRef<"DINodeAttr">:$elements
)>;
@@ -209,7 +211,7 @@ def DIDerivedTypeAttr : DialectAttribute<(attr
OptionalInt<"unsigned">:$dwarfAddressSpace,
EnumClassFlag<"DIFlags", "getFlags()">:$_rawflags,
LocalVar<"DIFlags", "(DIFlags)_rawflags">:$flags,
- OptionalAttribute<"DINodeAttr">:$extraData
+ OptionalAttribute<"Attribute">:$extraData
)>;
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index f690af2cdb8a1..6b8cac201d8bf 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -253,7 +253,8 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
- MlirAttribute associated) {
+ MlirAttribute associated, MlirAttribute identifier,
+ MlirAttribute discriminator) {
SmallVector<Attribute> elementsStorage;
elementsStorage.reserve(nElements);
@@ -266,6 +267,8 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
cast<DIExpressionAttr>(unwrap(rank)),
cast<DIExpressionAttr>(unwrap(allocated)),
cast<DIExpressionAttr>(unwrap(associated)),
+ cast<StringAttr>(unwrap(identifier)),
+ cast<DIDerivedTypeAttr>(unwrap(discriminator)),
llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
llvm::CastTo<DINodeAttr>)));
}
@@ -286,7 +289,7 @@ MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
unwrap(ctx), tag, cast<StringAttr>(unwrap(name)),
cast<DIFileAttr>(unwrap(file)), line, cast<DIScopeAttr>(unwrap(scope)),
cast<DITypeAttr>(unwrap(baseType)), sizeInBits, alignInBits, offsetInBits,
- addressSpace, DIFlags(flags), cast<DINodeAttr>(unwrap(extraData))));
+ addressSpace, DIFlags(flags), unwrap(extraData)));
}
MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void) {
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 674a406cb368b..00d2bba3f3d36 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -204,6 +204,23 @@ bool DITypeAttr::classof(Attribute attr) {
attr);
}
+//===----------------------------------------------------------------------===//
+// DIDerivedTypeAttr
+//===----------------------------------------------------------------------===//
+
+LogicalResult
+DIDerivedTypeAttr::verify(function_ref<InFlightDiagnostic()> emitError,
+ unsigned tag, StringAttr name, DIFileAttr file,
+ uint32_t line, DIScopeAttr scope, DITypeAttr baseType,
+ uint64_t sizeInBits, uint32_t alignInBits,
+ uint64_t offsetInBits,
+ std::optional<unsigned> dwarfAddressSpace,
+ DIFlags flags, Attribute extraData) {
+ if (extraData && !llvm::isa<DINodeAttr, IntegerAttr>(extraData))
+ return emitError() << "extraData must be a DINodeAttr or an IntegerAttr";
+ return success();
+}
+
//===----------------------------------------------------------------------===//
// TBAANodeAttr
//===----------------------------------------------------------------------===//
@@ -320,14 +337,14 @@ DICompositeTypeAttr::withRecId(DistinctAttr recId) {
getContext(), recId, getIsRecSelf(), getTag(), getName(), getFile(),
getLine(), getScope(), getBaseType(), getFlags(), getSizeInBits(),
getAlignInBits(), getDataLocation(), getRank(), getAllocated(),
- getAssociated(), getElements());
+ getAssociated(), getIdentifier(), getDiscriminator(), getElements());
}
DIRecursiveTypeAttrInterface
DICompositeTypeAttr::getRecSelf(DistinctAttr recId) {
return DICompositeTypeAttr::get(recId.getContext(), recId, /*isRecSelf=*/true,
0, {}, {}, 0, {}, {}, DIFlags(), 0, 0, {}, {},
- {}, {}, {});
+ {}, {}, {}, {}, {});
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
index ab37c21fdacf8..b3cbe481f5983 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
@@ -101,7 +101,9 @@ DICompositeTypeAttr DebugImporter::translateImpl(llvm::DICompositeType *node) {
node->getAlignInBits(), translateExpression(node->getDataLocationExp()),
translateExpression(node->getRankExp()),
translateExpression(node->getAllocatedExp()),
- translateExpression(node->getAssociatedExp()), elements);
+ translateExpression(node->getAssociatedExp()),
+ getStringAttrOrNull(node->getRawIdentifier()),
+ translate(node->getDiscriminator()), elements);
}
DIDerivedTypeAttr DebugImporter::translateImpl(llvm::DIDerivedType *node) {
@@ -109,8 +111,20 @@ DIDerivedTypeAttr DebugImporter::translateImpl(llvm::DIDerivedType *node) {
DITypeAttr baseType = translate(node->getBaseType());
if (node->getBaseType() && !baseType)
return nullptr;
- DINodeAttr extraData =
- translate(dyn_cast_or_null<llvm::DINode>(node->getExtraData()));
+ llvm::Metadata *rawExtraData = node->getExtraData();
+ Attribute extraData;
+ if (auto *extraDataNode = dyn_cast_or_null<llvm::DINode>(rawExtraData)) {
+ extraData = translate(extraDataNode);
+ } else if (auto *constantAsMetadata =
+ dyn_cast_or_null<llvm::ConstantAsMetadata>(rawExtraData)) {
+ if (auto *constantInt =
+ dyn_cast<llvm::ConstantInt>(constantAsMetadata->getValue())) {
+ const APInt &value = constantInt->getValue();
+ extraData =
+ IntegerAttr::get(IntegerType::get(context, value.getBitWidth()),
+ value);
+ }
+ }
return DIDerivedTypeAttr::get(
context, node->getTag(), getStringAttrOrNull(node->getRawName()),
translate(node->getFile()), node->getLine(), translate(node->getScope()),
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index db9bc874314bb..a69e7b5338caa 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -10,8 +10,10 @@
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "llvm/ADT/SmallVectorExtras.h"
#include "llvm/ADT/TypeSwitch.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
@@ -225,8 +227,8 @@ DebugTranslation::translateImpl(DICompositeTypeAttr attr) {
/*Flags=*/static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
getMDTupleOrNull(attr.getElements()),
/*RuntimeLang=*/0, /*EnumKind*/ std::nullopt, /*VTableHolder=*/nullptr,
- /*TemplateParams=*/nullptr, /*Identifier=*/nullptr,
- /*Discriminator=*/nullptr,
+ /*TemplateParams=*/nullptr, getMDStringOrNull(attr.getIdentifier()),
+ translate(attr.getDiscriminator()),
getExpressionAttrOrNull(attr.getDataLocation()),
getExpressionAttrOrNull(attr.getAssociated()),
getExpressionAttrOrNull(attr.getAllocated()),
@@ -234,6 +236,21 @@ DebugTranslation::translateImpl(DICompositeTypeAttr attr) {
}
llvm::DIDerivedType *DebugTranslation::translateImpl(DIDerivedTypeAttr attr) {
+ llvm::Metadata *extraData = nullptr;
+ if (Attribute extraDataAttr = attr.getExtraData()) {
+ extraData =
+ llvm::TypeSwitch<Attribute, llvm::Metadata *>(extraDataAttr)
+ .Case([&](DINodeAttr nodeAttr) { return translate(nodeAttr); })
+ .Case([&](IntegerAttr intAttr) {
+ return llvm::ConstantAsMetadata::get(
+ llvm::ConstantInt::get(llvmCtx, intAttr.getValue()));
+ })
+ .Default([](Attribute) -> llvm::Metadata * {
+ llvm_unreachable(
+ "verifier guarantees DINodeAttr or IntegerAttr");
+ });
+ }
+
return llvm::DIDerivedType::get(
llvmCtx, attr.getTag(), getMDStringOrNull(attr.getName()),
translate(attr.getFile()), attr.getLine(), translate(attr.getScope()),
@@ -241,7 +258,7 @@ llvm::DIDerivedType *DebugTranslation::translateImpl(DIDerivedTypeAttr attr) {
attr.getAlignInBits(), attr.getOffsetInBits(),
attr.getDwarfAddressSpace(), /*PtrAuthData=*/std::nullopt,
/*Flags=*/static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
- translate(attr.getExtraData()));
+ extraData);
}
llvm::DIStringType *DebugTranslation::translateImpl(DIStringTypeAttr attr) {
diff --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index fe48ec5568168..caa29379e9fd6 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -378,10 +378,15 @@ static void testDebugInfoAttributes(MlirContext ctx) {
// CHECK: #llvm.di_composite_type<recId = {{.*}}, isRecSelf = true>
mlirAttributeDump(mlirLLVMDICompositeTypeAttrGetRecSelf(recId1));
+ MlirAttribute discriminator = mlirLLVMDIDerivedTypeAttrGet(
+ ctx, /*DW_TAG_member=*/0x0d, bar, file, 1, compile_unit, di_type, 8, 0,
+ 0, MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL, 0, mlirAttributeGetNull());
+
// CHECK: #llvm.di_composite_type<{{.*}}>
mlirAttributeDump(mlirLLVMDICompositeTypeAttrGet(
ctx, recId1, false, 0, foo, file, 1, compile_unit, di_type, 0, 64, 8, 1,
- &di_type, expression, expression, expression, expression));
+ &di_type, expression, expression, expression, expression, bar,
+ discriminator));
}
int main(void) {
diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index e9793c15a5272..21bcbcffbace7 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -29,6 +29,12 @@
sizeInBits = 32, encoding = DW_ATE_signed
>
+// CHECK-DAG: #[[FLOAT1:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "float1", sizeInBits = 32, encoding = DW_ATE_float>
+#float1 = #llvm.di_basic_type<
+ tag = DW_TAG_base_type, name = "float1",
+ sizeInBits = 32, encoding = DW_ATE_float
+>
+
// CHECK-DAG: #[[PTR0:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[INT0]], sizeInBits = 64, alignInBits = 32, offsetInBits = 4, extraData = #[[INT1]]>
#ptr0 = #llvm.di_derived_type<
tag = DW_TAG_pointer_type, baseType = #int0,
@@ -74,6 +80,31 @@
elements = #llvm.di_subrange<count = 4>
>
+// CHECK-DAG: #[[DISC:.*]] = #llvm.di_derived_type<tag = DW_TAG_member, name = "discriminator", baseType = #[[INT0]], flags = Artificial>
+#disc = #llvm.di_derived_type<
+ tag = DW_TAG_member, name = "discriminator", baseType = #int0,
+ flags = Artificial
+>
+
+// CHECK-DAG: #[[ELEM_INT:.*]] = #llvm.di_derived_type<tag = DW_TAG_member, name = "_int1", baseType = #[[INT1]], extraData = 1 : i8>
+#elemInt = #llvm.di_derived_type<
+ tag = DW_TAG_member, name = "_int1", baseType = #int1,
+ extraData = 1 : i8
+>
+
+// CHECK-DAG: #[[ELEM_FLOAT:.*]] = #llvm.di_derived_type<tag = DW_TAG_member, name = "_float1", baseType = #[[FLOAT1]], extraData = 2 : i8>
+#elemFloat = #llvm.di_derived_type<
+ tag = DW_TAG_member, name = "_float1", baseType = #float1,
+ extraData = 2 : i8
+>
+
+// CHECK-DAG: #[[VARIANT:.*]] = #llvm.di_composite_type<tag = DW_TAG_variant_part, name = "variant_part", identifier = "variant-id", discriminator = #[[DISC]], elements = #[[ELEM_INT]], #[[ELEM_FLOAT]]>
+#variant = #llvm.di_composite_type<
+ tag = DW_TAG_variant_part, name = "variant_part",
+ identifier = "variant-id", discriminator = #disc,
+ elements = #elemInt, #elemFloat
+>
+
// CHECK-DAG: #[[TOPLEVEL:.*]] = #llvm.di_namespace<name = "toplevel", exportSymbols = true>
#toplevel_namespace = #llvm.di_namespace<
name = "toplevel", exportSymbols = true
@@ -104,9 +135,9 @@
name = "expr_elements2", baseType = #int0, elements =
#llvm.di_generic_subrange<count = #exp1, lowerBound = #exp2, stride = #exp3>>
-// CHECK-DAG: #[[SPTYPE0:.*]] = #llvm.di_subroutine_type<callingConvention = D...
[truncated]
|
|
@llvm/pr-subscribers-mlir Author: jiel-nv ChangesSummaryThis PR extends the MLIR LLVM dialect debug-info attributes to represent DWARF variant parts, discriminators, and per-alternative discriminator values. The change adds Details
Patch is 26.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/195321.diff 13 Files Affected:
diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
index da7a513315a4e..f6e18c5b27391 100644
--- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
+++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
@@ -187,7 +187,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
dataLocation, rank, /*allocated=*/nullptr,
- /*associated=*/nullptr, elements);
+ /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
}
addOp(llvm::dwarf::DW_OP_push_object_address, {});
@@ -264,7 +265,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
context, llvm::dwarf::DW_TAG_array_type, /*name=*/nullptr,
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
- dataLocation, /*rank=*/nullptr, allocated, associated, elements);
+ dataLocation, /*rank=*/nullptr, allocated, associated,
+ /*identifier=*/nullptr, /*discriminator=*/nullptr, elements);
}
std::pair<std::uint64_t, unsigned short>
@@ -398,7 +400,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
mlir::StringAttr::get(context, ""), fileAttr, /*line=*/0, scope,
/*baseType=*/nullptr, mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0,
/*alignInBits=*/0, /*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, elements);
+ /*allocated=*/nullptr, /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
DerivedTypeCache::ActiveLevels nestedRecursions =
derivedTypeCache.startTranslating(Ty, placeHolder);
@@ -438,7 +441,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
convertType(seqTy.getEleTy(), fileAttr, scope, declOp),
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
/*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, arrayElements);
+ /*allocated=*/nullptr, /*associated=*/nullptr,
+ /*identifier=*/nullptr, /*discriminator=*/nullptr, arrayElements);
} else
elemTy = convertType(fieldTy, fileAttr, scope, /*declOp=*/nullptr);
offset = llvm::alignTo(offset, byteAlign);
@@ -459,7 +463,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
mlir::StringAttr::get(context, sourceName.name), fileAttr, line, scope,
/*baseType=*/nullptr, mlir::LLVM::DIFlags::Zero, offset * 8,
/*alignInBits=*/0, /*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, elements);
+ /*allocated=*/nullptr, /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
derivedTypeCache.finalize(Ty, finalAttr, std::move(nestedRecursions));
@@ -503,7 +508,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertTupleType(
mlir::StringAttr::get(context, ""), fileAttr, /*line=*/0, scope,
/*baseType=*/nullptr, mlir::LLVM::DIFlags::Zero, offset * 8,
/*alignInBits=*/0, /*dataLocation=*/nullptr, /*rank=*/nullptr,
- /*allocated=*/nullptr, /*associated=*/nullptr, elements);
+ /*allocated=*/nullptr, /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
derivedTypeCache.finalize(Ty, typeAttr, std::move(nestedRecursions));
return typeAttr;
}
@@ -565,7 +571,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
/*dataLocation=*/nullptr, /*rank=*/nullptr, /*allocated=*/nullptr,
- /*associated=*/nullptr, elements);
+ /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
}
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertVectorType(
@@ -598,7 +605,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertVectorType(
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr, elemTy,
mlir::LLVM::DIFlags::Vector, sizeInBits, /*alignInBits=*/0,
/*dataLocation=*/nullptr, /*rank=*/nullptr, /*allocated=*/nullptr,
- /*associated=*/nullptr, elements);
+ /*associated=*/nullptr, /*identifier=*/nullptr,
+ /*discriminator=*/nullptr, elements);
}
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
diff --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index 5170f01a2f621..09d3ad198a3b2 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -307,7 +307,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
- MlirAttribute associated);
+ MlirAttribute associated, MlirAttribute identifier,
+ MlirAttribute discriminator);
MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void);
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 22face8b9d4b0..bb958213abd2d 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -494,6 +494,8 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
OptionalParameter<"DIExpressionAttr">:$rank,
OptionalParameter<"DIExpressionAttr">:$allocated,
OptionalParameter<"DIExpressionAttr">:$associated,
+ OptionalParameter<"StringAttr">:$identifier,
+ OptionalParameter<"DIDerivedTypeAttr">:$discriminator,
OptionalArrayRefParameter<"DINodeAttr">:$elements
);
let builders = [
@@ -503,12 +505,13 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
"DIFlags":$flags, "uint64_t":$sizeInBits, "uint64_t":$alignInBits,
"DIExpressionAttr":$dataLocation, "DIExpressionAttr":$rank,
"DIExpressionAttr":$allocated, "DIExpressionAttr":$associated,
+ "StringAttr":$identifier, "DIDerivedTypeAttr":$discriminator,
"ArrayRef<DINodeAttr>":$elements
), [{
- return $_get($_ctxt, /*recId=*/nullptr, /*isRecSelf=*/nullptr,
+ return $_get($_ctxt, /*recId=*/nullptr, /*isRecSelf=*/false,
tag, name, file, line, scope, baseType, flags, sizeInBits,
alignInBits, dataLocation, rank, allocated,
- associated, elements);
+ associated, identifier, discriminator, elements);
}]>
];
let assemblyFormat = "`<` struct(params) `>`";
@@ -547,9 +550,10 @@ def LLVM_DIDerivedTypeAttr : LLVM_Attr<"DIDerivedType", "di_derived_type",
OptionalParameter<"uint64_t">:$offsetInBits,
OptionalParameter<"std::optional<unsigned>">:$dwarfAddressSpace,
OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags,
- OptionalParameter<"DINodeAttr">:$extraData
+ OptionalParameter<"::mlir::Attribute">:$extraData
);
let assemblyFormat = "`<` struct(params) `>`";
+ let genVerifyDecl = 1;
// Generate mnemonic alias for the attribute.
let genMnemonicAlias = 1;
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
index 05b88b428102c..a5040d5104ab9 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
@@ -189,6 +189,8 @@ def DICompositeTypeAttr : DialectAttribute<(attr
OptionalAttribute<"DIExpressionAttr">:$rank,
OptionalAttribute<"DIExpressionAttr">:$allocated,
OptionalAttribute<"DIExpressionAttr">:$associated,
+ OptionalAttribute<"StringAttr">:$identifier,
+ OptionalAttribute<"DIDerivedTypeAttr">:$discriminator,
OptionalArrayRef<"DINodeAttr">:$elements
)>;
@@ -209,7 +211,7 @@ def DIDerivedTypeAttr : DialectAttribute<(attr
OptionalInt<"unsigned">:$dwarfAddressSpace,
EnumClassFlag<"DIFlags", "getFlags()">:$_rawflags,
LocalVar<"DIFlags", "(DIFlags)_rawflags">:$flags,
- OptionalAttribute<"DINodeAttr">:$extraData
+ OptionalAttribute<"Attribute">:$extraData
)>;
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index f690af2cdb8a1..6b8cac201d8bf 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -253,7 +253,8 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
- MlirAttribute associated) {
+ MlirAttribute associated, MlirAttribute identifier,
+ MlirAttribute discriminator) {
SmallVector<Attribute> elementsStorage;
elementsStorage.reserve(nElements);
@@ -266,6 +267,8 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
cast<DIExpressionAttr>(unwrap(rank)),
cast<DIExpressionAttr>(unwrap(allocated)),
cast<DIExpressionAttr>(unwrap(associated)),
+ cast<StringAttr>(unwrap(identifier)),
+ cast<DIDerivedTypeAttr>(unwrap(discriminator)),
llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
llvm::CastTo<DINodeAttr>)));
}
@@ -286,7 +289,7 @@ MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
unwrap(ctx), tag, cast<StringAttr>(unwrap(name)),
cast<DIFileAttr>(unwrap(file)), line, cast<DIScopeAttr>(unwrap(scope)),
cast<DITypeAttr>(unwrap(baseType)), sizeInBits, alignInBits, offsetInBits,
- addressSpace, DIFlags(flags), cast<DINodeAttr>(unwrap(extraData))));
+ addressSpace, DIFlags(flags), unwrap(extraData)));
}
MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void) {
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index 674a406cb368b..00d2bba3f3d36 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -204,6 +204,23 @@ bool DITypeAttr::classof(Attribute attr) {
attr);
}
+//===----------------------------------------------------------------------===//
+// DIDerivedTypeAttr
+//===----------------------------------------------------------------------===//
+
+LogicalResult
+DIDerivedTypeAttr::verify(function_ref<InFlightDiagnostic()> emitError,
+ unsigned tag, StringAttr name, DIFileAttr file,
+ uint32_t line, DIScopeAttr scope, DITypeAttr baseType,
+ uint64_t sizeInBits, uint32_t alignInBits,
+ uint64_t offsetInBits,
+ std::optional<unsigned> dwarfAddressSpace,
+ DIFlags flags, Attribute extraData) {
+ if (extraData && !llvm::isa<DINodeAttr, IntegerAttr>(extraData))
+ return emitError() << "extraData must be a DINodeAttr or an IntegerAttr";
+ return success();
+}
+
//===----------------------------------------------------------------------===//
// TBAANodeAttr
//===----------------------------------------------------------------------===//
@@ -320,14 +337,14 @@ DICompositeTypeAttr::withRecId(DistinctAttr recId) {
getContext(), recId, getIsRecSelf(), getTag(), getName(), getFile(),
getLine(), getScope(), getBaseType(), getFlags(), getSizeInBits(),
getAlignInBits(), getDataLocation(), getRank(), getAllocated(),
- getAssociated(), getElements());
+ getAssociated(), getIdentifier(), getDiscriminator(), getElements());
}
DIRecursiveTypeAttrInterface
DICompositeTypeAttr::getRecSelf(DistinctAttr recId) {
return DICompositeTypeAttr::get(recId.getContext(), recId, /*isRecSelf=*/true,
0, {}, {}, 0, {}, {}, DIFlags(), 0, 0, {}, {},
- {}, {}, {});
+ {}, {}, {}, {}, {});
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
index ab37c21fdacf8..b3cbe481f5983 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
@@ -101,7 +101,9 @@ DICompositeTypeAttr DebugImporter::translateImpl(llvm::DICompositeType *node) {
node->getAlignInBits(), translateExpression(node->getDataLocationExp()),
translateExpression(node->getRankExp()),
translateExpression(node->getAllocatedExp()),
- translateExpression(node->getAssociatedExp()), elements);
+ translateExpression(node->getAssociatedExp()),
+ getStringAttrOrNull(node->getRawIdentifier()),
+ translate(node->getDiscriminator()), elements);
}
DIDerivedTypeAttr DebugImporter::translateImpl(llvm::DIDerivedType *node) {
@@ -109,8 +111,20 @@ DIDerivedTypeAttr DebugImporter::translateImpl(llvm::DIDerivedType *node) {
DITypeAttr baseType = translate(node->getBaseType());
if (node->getBaseType() && !baseType)
return nullptr;
- DINodeAttr extraData =
- translate(dyn_cast_or_null<llvm::DINode>(node->getExtraData()));
+ llvm::Metadata *rawExtraData = node->getExtraData();
+ Attribute extraData;
+ if (auto *extraDataNode = dyn_cast_or_null<llvm::DINode>(rawExtraData)) {
+ extraData = translate(extraDataNode);
+ } else if (auto *constantAsMetadata =
+ dyn_cast_or_null<llvm::ConstantAsMetadata>(rawExtraData)) {
+ if (auto *constantInt =
+ dyn_cast<llvm::ConstantInt>(constantAsMetadata->getValue())) {
+ const APInt &value = constantInt->getValue();
+ extraData =
+ IntegerAttr::get(IntegerType::get(context, value.getBitWidth()),
+ value);
+ }
+ }
return DIDerivedTypeAttr::get(
context, node->getTag(), getStringAttrOrNull(node->getRawName()),
translate(node->getFile()), node->getLine(), translate(node->getScope()),
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index db9bc874314bb..a69e7b5338caa 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -10,8 +10,10 @@
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "llvm/ADT/SmallVectorExtras.h"
#include "llvm/ADT/TypeSwitch.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
@@ -225,8 +227,8 @@ DebugTranslation::translateImpl(DICompositeTypeAttr attr) {
/*Flags=*/static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
getMDTupleOrNull(attr.getElements()),
/*RuntimeLang=*/0, /*EnumKind*/ std::nullopt, /*VTableHolder=*/nullptr,
- /*TemplateParams=*/nullptr, /*Identifier=*/nullptr,
- /*Discriminator=*/nullptr,
+ /*TemplateParams=*/nullptr, getMDStringOrNull(attr.getIdentifier()),
+ translate(attr.getDiscriminator()),
getExpressionAttrOrNull(attr.getDataLocation()),
getExpressionAttrOrNull(attr.getAssociated()),
getExpressionAttrOrNull(attr.getAllocated()),
@@ -234,6 +236,21 @@ DebugTranslation::translateImpl(DICompositeTypeAttr attr) {
}
llvm::DIDerivedType *DebugTranslation::translateImpl(DIDerivedTypeAttr attr) {
+ llvm::Metadata *extraData = nullptr;
+ if (Attribute extraDataAttr = attr.getExtraData()) {
+ extraData =
+ llvm::TypeSwitch<Attribute, llvm::Metadata *>(extraDataAttr)
+ .Case([&](DINodeAttr nodeAttr) { return translate(nodeAttr); })
+ .Case([&](IntegerAttr intAttr) {
+ return llvm::ConstantAsMetadata::get(
+ llvm::ConstantInt::get(llvmCtx, intAttr.getValue()));
+ })
+ .Default([](Attribute) -> llvm::Metadata * {
+ llvm_unreachable(
+ "verifier guarantees DINodeAttr or IntegerAttr");
+ });
+ }
+
return llvm::DIDerivedType::get(
llvmCtx, attr.getTag(), getMDStringOrNull(attr.getName()),
translate(attr.getFile()), attr.getLine(), translate(attr.getScope()),
@@ -241,7 +258,7 @@ llvm::DIDerivedType *DebugTranslation::translateImpl(DIDerivedTypeAttr attr) {
attr.getAlignInBits(), attr.getOffsetInBits(),
attr.getDwarfAddressSpace(), /*PtrAuthData=*/std::nullopt,
/*Flags=*/static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
- translate(attr.getExtraData()));
+ extraData);
}
llvm::DIStringType *DebugTranslation::translateImpl(DIStringTypeAttr attr) {
diff --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index fe48ec5568168..caa29379e9fd6 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -378,10 +378,15 @@ static void testDebugInfoAttributes(MlirContext ctx) {
// CHECK: #llvm.di_composite_type<recId = {{.*}}, isRecSelf = true>
mlirAttributeDump(mlirLLVMDICompositeTypeAttrGetRecSelf(recId1));
+ MlirAttribute discriminator = mlirLLVMDIDerivedTypeAttrGet(
+ ctx, /*DW_TAG_member=*/0x0d, bar, file, 1, compile_unit, di_type, 8, 0,
+ 0, MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL, 0, mlirAttributeGetNull());
+
// CHECK: #llvm.di_composite_type<{{.*}}>
mlirAttributeDump(mlirLLVMDICompositeTypeAttrGet(
ctx, recId1, false, 0, foo, file, 1, compile_unit, di_type, 0, 64, 8, 1,
- &di_type, expression, expression, expression, expression));
+ &di_type, expression, expression, expression, expression, bar,
+ discriminator));
}
int main(void) {
diff --git a/mlir/test/Dialect/LLVMIR/debuginfo.mlir b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
index e9793c15a5272..21bcbcffbace7 100644
--- a/mlir/test/Dialect/LLVMIR/debuginfo.mlir
+++ b/mlir/test/Dialect/LLVMIR/debuginfo.mlir
@@ -29,6 +29,12 @@
sizeInBits = 32, encoding = DW_ATE_signed
>
+// CHECK-DAG: #[[FLOAT1:.*]] = #llvm.di_basic_type<tag = DW_TAG_base_type, name = "float1", sizeInBits = 32, encoding = DW_ATE_float>
+#float1 = #llvm.di_basic_type<
+ tag = DW_TAG_base_type, name = "float1",
+ sizeInBits = 32, encoding = DW_ATE_float
+>
+
// CHECK-DAG: #[[PTR0:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[INT0]], sizeInBits = 64, alignInBits = 32, offsetInBits = 4, extraData = #[[INT1]]>
#ptr0 = #llvm.di_derived_type<
tag = DW_TAG_pointer_type, baseType = #int0,
@@ -74,6 +80,31 @@
elements = #llvm.di_subrange<count = 4>
>
+// CHECK-DAG: #[[DISC:.*]] = #llvm.di_derived_type<tag = DW_TAG_member, name = "discriminator", baseType = #[[INT0]], flags = Artificial>
+#disc = #llvm.di_derived_type<
+ tag = DW_TAG_member, name = "discriminator", baseType = #int0,
+ flags = Artificial
+>
+
+// CHECK-DAG: #[[ELEM_INT:.*]] = #llvm.di_derived_type<tag = DW_TAG_member, name = "_int1", baseType = #[[INT1]], extraData = 1 : i8>
+#elemInt = #llvm.di_derived_type<
+ tag = DW_TAG_member, name = "_int1", baseType = #int1,
+ extraData = 1 : i8
+>
+
+// CHECK-DAG: #[[ELEM_FLOAT:.*]] = #llvm.di_derived_type<tag = DW_TAG_member, name = "_float1", baseType = #[[FLOAT1]], extraData = 2 : i8>
+#elemFloat = #llvm.di_derived_type<
+ tag = DW_TAG_member, name = "_float1", baseType = #float1,
+ extraData = 2 : i8
+>
+
+// CHECK-DAG: #[[VARIANT:.*]] = #llvm.di_composite_type<tag = DW_TAG_variant_part, name = "variant_part", identifier = "variant-id", discriminator = #[[DISC]], elements = #[[ELEM_INT]], #[[ELEM_FLOAT]]>
+#variant = #llvm.di_composite_type<
+ tag = DW_TAG_variant_part, name = "variant_part",
+ identifier = "variant-id", discriminator = #disc,
+ elements = #elemInt, #elemFloat
+>
+
// CHECK-DAG: #[[TOPLEVEL:.*]] = #llvm.di_namespace<name = "toplevel", exportSymbols = true>
#toplevel_namespace = #llvm.di_namespace<
name = "toplevel", exportSymbols = true
@@ -104,9 +135,9 @@
name = "expr_elements2", baseType = #int0, elements =
#llvm.di_generic_subrange<count = #exp1, lowerBound = #exp2, stride = #exp3>>
-// CHECK-DAG: #[[SPTYPE0:.*]] = #llvm.di_subroutine_type<callingConvention = D...
[truncated]
|
bzcheeseman
left a comment
There was a problem hiding this comment.
Looks fine to me, but @gysit might have context I don't so please wait for their review as well.
Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
|
@bzcheeseman @gysit thank you for the review. Could you also approve the CI workflow? Thanks! |
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
|
Looks like the workflow needs approval again after the clang-format push @gysit |
|
Thanks for the review! Could someone help with merging/landing this at your convenience? |
|
@jiel-nv Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/177/builds/34071 Here is the relevant piece of the build log for the reference |
This failure is real, but not totally the fault of this PR, since it was a race condition between this and a different PR that adds extra validation. #195720 updates the test. |
|
Thanks for the quick fix! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/43904 Here is the relevant piece of the build log for the reference |
#### Summary This PR extends the MLIR LLVM dialect debug-info attributes to represent DWARF variant parts, discriminators, and per-alternative discriminator values. The change adds `identifier` and `discriminator` support to `DICompositeTypeAttr`, allowing MLIR to model `DW_TAG_variant_part` metadata that LLVM IR already supports. It also broadens `DIDerivedTypeAttr`'s `extraData` field from `DINodeAttr` to a verified polymorphic `Attribute`, supporting both debug-info nodes and integer constants used by variant alternatives. #### Details - Add `identifier` and `discriminator` fields to `DICompositeTypeAttr`, bytecode serialization, LLVM IR import/export, C API bindings, and Flang call sites. - Change `DIDerivedTypeAttr.extraData` to accept either `DINodeAttr` or `IntegerAttr`, with verifier coverage for invalid attribute kinds. - Preserve integer bit width when importing `ConstantAsMetadata(ConstantInt)` into MLIR. - Add parse/print, verifier, LLVM IR import/export, and C API test coverage for variant-part debug info. --------- Co-authored-by: Tobias Gysi <tobias.gysi@nextsilicon.com>
Needed after llvm#194556, and llvm#195321 missed out on the cleanup since it was still in review.
- Dropped -Os and -Oz after llvm/llvm-project#191363 - Emit scalar `{add,sub,mul}.rn.bf16` ops after llvm/llvm-project#190414 - Also changed to avoid hardcoding line numbers in test_line_info.py - Add identifier/discriminator arguments to DICompositeTypeAttr::get calls after llvm/llvm-project#195321 - Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing MCContext after llvm/llvm-project#195032 - Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with NVVM::BarrierOp/nvvm.barrier after llvm/llvm-project#195608
- Dropped -Os and -Oz after llvm/llvm-project#191363 - Emit scalar `{add,sub,mul}.rn.bf16` ops after llvm/llvm-project#190414 - Also changed to avoid hardcoding line numbers in test_line_info.py - Add identifier/discriminator arguments to DICompositeTypeAttr::get calls after llvm/llvm-project#195321 - Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing MCContext after llvm/llvm-project#195032 - Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with NVVM::BarrierOp/nvvm.barrier after llvm/llvm-project#195608
* Dropped -Os and -Oz after llvm/llvm-project#191363 * Emit scalar {add,sub,mul}.rn.bf16 ops after llvm/llvm-project#190414 * Also changed to avoid hardcoding line numbers in test_line_info.py * Add identifier/discriminator arguments to DICompositeTypeAttr::get * calls after llvm/llvm-project#195321 * Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing * MCContext after llvm/llvm-project#195032 * Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with * NVVM::BarrierOp/nvvm.barrier after llvm/llvm-project#195608 * Update AMD target parser includes after llvm/llvm-project#198433 * Add explicit TypeID for AMD UniformityAnalysis after llvm/llvm-project#199634 * Update finite-trip-count AMD range analysis after llvm/llvm-project#196616 * Update NVVM::BarrierOp creation after llvm/llvm-project#199404 also disable SLP vectorizer on sm_80 to workaround a ptxas bug --------- Co-authored-by: Lei Zhang <antiagainst@gmail.com> Co-authored-by: Lei Zhang <Lei.Zhang2@amd.com>
* Dropped -Os and -Oz after llvm/llvm-project#191363 * Emit scalar {add,sub,mul}.rn.bf16 ops after llvm/llvm-project#190414 * Also changed to avoid hardcoding line numbers in test_line_info.py * Add identifier/discriminator arguments to DICompositeTypeAttr::get * calls after llvm/llvm-project#195321 * Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing * MCContext after llvm/llvm-project#195032 * Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with * NVVM::BarrierOp/nvvm.barrier after llvm/llvm-project#195608 * Update AMD target parser includes after llvm/llvm-project#198433 * Add explicit TypeID for AMD UniformityAnalysis after llvm/llvm-project#199634 * Update finite-trip-count AMD range analysis after llvm/llvm-project#196616 * Update NVVM::BarrierOp creation after llvm/llvm-project#199404 also disable SLP vectorizer on sm_80 to workaround a ptxas bug --------- Co-authored-by: Lei Zhang <antiagainst@gmail.com> Co-authored-by: Lei Zhang <Lei.Zhang2@amd.com>
* Dropped -Os and -Oz after llvm/llvm-project#191363 * Emit scalar {add,sub,mul}.rn.bf16 ops after llvm/llvm-project#190414 * Also changed to avoid hardcoding line numbers in test_line_info.py * Add identifier/discriminator arguments to DICompositeTypeAttr::get * calls after llvm/llvm-project#195321 * Pass MCRegisterInfo and MCSubtargetInfo by reference when constructing * MCContext after llvm/llvm-project#195032 * Replace NVVM::Barrier0Op and nvvm.barrier0 test expectations with * NVVM::BarrierOp/nvvm.barrier after llvm/llvm-project#195608 * Update AMD target parser includes after llvm/llvm-project#198433 * Add explicit TypeID for AMD UniformityAnalysis after llvm/llvm-project#199634 * Update finite-trip-count AMD range analysis after llvm/llvm-project#196616 * Update NVVM::BarrierOp creation after llvm/llvm-project#199404 also disable SLP vectorizer on sm_80 to workaround a ptxas bug --------- Co-authored-by: Lei Zhang <antiagainst@gmail.com> Co-authored-by: Lei Zhang <Lei.Zhang2@amd.com>
Summary
This PR extends the MLIR LLVM dialect debug-info attributes to represent DWARF variant parts, discriminators, and per-alternative discriminator values.
The change adds
identifieranddiscriminatorsupport toDICompositeTypeAttr, allowing MLIR to modelDW_TAG_variant_partmetadata that LLVM IR already supports. It also broadensDIDerivedTypeAttr'sextraDatafield fromDINodeAttrto a verified polymorphicAttribute, supporting both debug-info nodes and integer constants used by variant alternatives.Details
identifieranddiscriminatorfields toDICompositeTypeAttr, bytecode serialization, LLVM IR import/export, C API bindings, and Flang call sites.DIDerivedTypeAttr.extraDatato accept eitherDINodeAttrorIntegerAttr, with verifier coverage for invalid attribute kinds.ConstantAsMetadata(ConstantInt)into MLIR.