[Mlir-commits] [mlir] d803837 - [mlir] Add missing fields in DICompositeTypeAttr. (#93226)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue May 28 04:22:47 PDT 2024
Author: Abid Qadeer
Date: 2024-05-28T12:22:44+01:00
New Revision: d80383730cc8bf2562451b10eed92f7d781aad80
URL: https://github.com/llvm/llvm-project/commit/d80383730cc8bf2562451b10eed92f7d781aad80
DIFF: https://github.com/llvm/llvm-project/commit/d80383730cc8bf2562451b10eed92f7d781aad80.diff
LOG: [mlir] Add missing fields in DICompositeTypeAttr. (#93226)
The fortran arrays use 'dataLocation', 'rank', 'allocated' and
'associated' fields of the DICompositeType. These were not available in
'DICompositeTypeAttr'. This PR adds the missing fields.
---------
Co-authored-by: Tobias Gysi <tobias.gysi at nextsilicon.com>
Added:
mlir/test/Target/LLVMIR/Import/composite-type-fortran.ll
Modified:
flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
mlir/include/mlir-c/Dialect/LLVM.h
mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
mlir/lib/CAPI/Dialect/LLVM.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
mlir/lib/Target/LLVMIR/DebugImporter.cpp
mlir/lib/Target/LLVMIR/DebugTranslation.cpp
mlir/lib/Target/LLVMIR/DebugTranslation.h
mlir/test/CAPI/llvm.c
mlir/test/Target/LLVMIR/llvmir-debug.mlir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
index 07163de958f91..a174f2c2bc4bf 100644
--- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
+++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
@@ -73,7 +73,9 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
context, llvm::dwarf::DW_TAG_array_type, /*recursive id*/ {},
/* name */ nullptr, /* file */ nullptr, /* line */ 0, /* scope */ nullptr,
elemTy, mlir::LLVM::DIFlags::Zero, /* sizeInBits */ 0,
- /*alignInBits*/ 0, elements);
+ /*alignInBits*/ 0, elements, /* dataLocation */ nullptr,
+ /* rank */ nullptr, /* allocated */ nullptr,
+ /* associated */ nullptr);
}
mlir::LLVM::DITypeAttr
diff --git a/mlir/include/mlir-c/Dialect/LLVM.h b/mlir/include/mlir-c/Dialect/LLVM.h
index 446d364342ac8..e754318d66856 100644
--- a/mlir/include/mlir-c/Dialect/LLVM.h
+++ b/mlir/include/mlir-c/Dialect/LLVM.h
@@ -239,7 +239,9 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDICompositeTypeAttrGet(
MlirContext ctx, unsigned int tag, MlirAttribute recId, MlirAttribute name,
MlirAttribute file, uint32_t line, MlirAttribute scope,
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
- uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements);
+ uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
+ MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
+ MlirAttribute associated);
/// Creates a LLVM DIDerivedType attribute. Note that `dwarfAddressSpace` is an
/// optional field, where `MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL` indicates null
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
index 8965f4f652a20..535cf8dfd2ced 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
@@ -385,7 +385,11 @@ def LLVM_DICompositeTypeAttr : LLVM_Attr<"DICompositeType", "di_composite_type",
OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags,
OptionalParameter<"uint64_t">:$sizeInBits,
OptionalParameter<"uint64_t">:$alignInBits,
- OptionalArrayRefParameter<"DINodeAttr">:$elements
+ OptionalArrayRefParameter<"DINodeAttr">:$elements,
+ OptionalParameter<"DIExpressionAttr">:$dataLocation,
+ OptionalParameter<"DIExpressionAttr">:$rank,
+ OptionalParameter<"DIExpressionAttr">:$allocated,
+ OptionalParameter<"DIExpressionAttr">:$associated
);
let assemblyFormat = "`<` struct(params) `>`";
let extraClassDeclaration = [{
diff --git a/mlir/lib/CAPI/Dialect/LLVM.cpp b/mlir/lib/CAPI/Dialect/LLVM.cpp
index 9a28749631f57..f6fb2cbedfac0 100644
--- a/mlir/lib/CAPI/Dialect/LLVM.cpp
+++ b/mlir/lib/CAPI/Dialect/LLVM.cpp
@@ -163,7 +163,9 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
MlirContext ctx, unsigned int tag, MlirAttribute recId, MlirAttribute name,
MlirAttribute file, uint32_t line, MlirAttribute scope,
MlirAttribute baseType, int64_t flags, uint64_t sizeInBits,
- uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements) {
+ uint64_t alignInBits, intptr_t nElements, MlirAttribute const *elements,
+ MlirAttribute dataLocation, MlirAttribute rank, MlirAttribute allocated,
+ MlirAttribute associated) {
SmallVector<Attribute> elementsStorage;
elementsStorage.reserve(nElements);
@@ -173,7 +175,11 @@ MlirAttribute mlirLLVMDICompositeTypeAttrGet(
cast<DIScopeAttr>(unwrap(scope)), cast<DITypeAttr>(unwrap(baseType)),
DIFlags(flags), sizeInBits, alignInBits,
llvm::map_to_vector(unwrapList(nElements, elements, elementsStorage),
- [](Attribute a) { return cast<DINodeAttr>(a); })));
+ [](Attribute a) { return cast<DINodeAttr>(a); }),
+ cast<DIExpressionAttr>(unwrap(dataLocation)),
+ cast<DIExpressionAttr>(unwrap(rank)),
+ cast<DIExpressionAttr>(unwrap(allocated)),
+ cast<DIExpressionAttr>(unwrap(associated))));
}
MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
index a44e83313c9c1..9bc71e1ebc489 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMAttrs.cpp
@@ -192,16 +192,17 @@ void printExpressionArg(AsmPrinter &printer, uint64_t opcode,
DIRecursiveTypeAttrInterface
DICompositeTypeAttr::withRecId(DistinctAttr recId) {
- return DICompositeTypeAttr::get(getContext(), getTag(), recId, getName(),
- getFile(), getLine(), getScope(),
- getBaseType(), getFlags(), getSizeInBits(),
- getAlignInBits(), getElements());
+ return DICompositeTypeAttr::get(
+ getContext(), getTag(), recId, getName(), getFile(), getLine(),
+ getScope(), getBaseType(), getFlags(), getSizeInBits(), getAlignInBits(),
+ getElements(), getDataLocation(), getRank(), getAllocated(),
+ getAssociated());
}
DIRecursiveTypeAttrInterface
DICompositeTypeAttr::getRecSelf(DistinctAttr recId) {
return DICompositeTypeAttr::get(recId.getContext(), 0, recId, {}, {}, 0, {},
- {}, DIFlags(), 0, 0, {});
+ {}, DIFlags(), 0, 0, {}, {}, {}, {}, {});
}
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Target/LLVMIR/DebugImporter.cpp b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
index b40bfa4f4dbb0..6c011b3c756ff 100644
--- a/mlir/lib/Target/LLVMIR/DebugImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugImporter.cpp
@@ -93,7 +93,11 @@ DICompositeTypeAttr DebugImporter::translateImpl(llvm::DICompositeType *node) {
getStringAttrOrNull(node->getRawName()), translate(node->getFile()),
node->getLine(), translate(node->getScope()), baseType,
flags.value_or(DIFlags::Zero), node->getSizeInBits(),
- node->getAlignInBits(), elements);
+ node->getAlignInBits(), elements,
+ translateExpression(node->getDataLocationExp()),
+ translateExpression(node->getRankExp()),
+ translateExpression(node->getAllocatedExp()),
+ translateExpression(node->getAssociatedExp()));
}
DIDerivedTypeAttr DebugImporter::translateImpl(llvm::DIDerivedType *node) {
@@ -456,6 +460,9 @@ Location DebugImporter::translateLoc(llvm::DILocation *loc) {
}
DIExpressionAttr DebugImporter::translateExpression(llvm::DIExpression *node) {
+ if (!node)
+ return nullptr;
+
SmallVector<DIExpressionElemAttr> ops;
// Begin processing the operations.
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
index 815943c40bdef..dfb7d4952157d 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.cpp
@@ -83,6 +83,13 @@ llvm::DIType *DebugTranslation::translateImpl(DINullTypeAttr attr) {
return nullptr;
}
+llvm::DIExpression *
+DebugTranslation::getExpressionAttrOrNull(DIExpressionAttr attr) {
+ if (!attr)
+ return nullptr;
+ return translateExpression(attr);
+}
+
llvm::MDString *DebugTranslation::getMDStringOrNull(StringAttr stringAttr) {
if (!stringAttr || stringAttr.empty())
return nullptr;
@@ -156,7 +163,13 @@ DebugTranslation::translateImpl(DICompositeTypeAttr attr) {
/*OffsetInBits=*/0,
/*Flags=*/static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
llvm::MDNode::get(llvmCtx, elements),
- /*RuntimeLang=*/0, /*VTableHolder=*/nullptr);
+ /*RuntimeLang=*/0, /*VTableHolder=*/nullptr,
+ /*TemplateParams=*/nullptr, /*Identifier=*/nullptr,
+ /*Discriminator=*/nullptr,
+ getExpressionAttrOrNull(attr.getDataLocation()),
+ getExpressionAttrOrNull(attr.getAssociated()),
+ getExpressionAttrOrNull(attr.getAllocated()),
+ getExpressionAttrOrNull(attr.getRank()));
}
llvm::DIDerivedType *DebugTranslation::translateImpl(DIDerivedTypeAttr attr) {
diff --git a/mlir/lib/Target/LLVMIR/DebugTranslation.h b/mlir/lib/Target/LLVMIR/DebugTranslation.h
index c7a5228cbf5e9..04b7ea41add9a 100644
--- a/mlir/lib/Target/LLVMIR/DebugTranslation.h
+++ b/mlir/lib/Target/LLVMIR/DebugTranslation.h
@@ -103,6 +103,10 @@ class DebugTranslation {
/// nullptr if `stringAttr` is null or contains and empty string.
llvm::MDString *getMDStringOrNull(StringAttr stringAttr);
+ /// Constructs a DIExpression metadata node from the DIExpressionAttr. Returns
+ /// nullptr if `DIExpressionAttr` is null.
+ llvm::DIExpression *getExpressionAttrOrNull(DIExpressionAttr attr);
+
/// A mapping between mlir location+scope and the corresponding llvm debug
/// metadata.
DenseMap<std::tuple<Location, llvm::DILocalScope *, const llvm::DILocation *>,
diff --git a/mlir/test/CAPI/llvm.c b/mlir/test/CAPI/llvm.c
index 0c589a45f9df4..f1d02b43d5232 100644
--- a/mlir/test/CAPI/llvm.c
+++ b/mlir/test/CAPI/llvm.c
@@ -305,10 +305,6 @@ static void testDebugInfoAttributes(MlirContext ctx) {
mlirAttributeDump(
mlirLLVMDIDerivedTypeAttrGet(ctx, 0, bar, di_type, 64, 8, 0, 3, di_type));
- // CHECK: #llvm.di_composite_type<{{.*}}>
- mlirAttributeDump(mlirLLVMDICompositeTypeAttrGet(
- ctx, 0, id, foo, file, 1, compile_unit, di_type, 0, 64, 8, 1, &di_type));
-
MlirAttribute subroutine_type =
mlirLLVMDISubroutineTypeAttrGet(ctx, 0x0, 1, &di_type);
@@ -336,8 +332,15 @@ static void testDebugInfoAttributes(MlirContext ctx) {
// CHECK: #llvm<di_expression_elem(1)>
mlirAttributeDump(expression_elem);
+ MlirAttribute expression =
+ mlirLLVMDIExpressionAttrGet(ctx, 1, &expression_elem);
// CHECK: #llvm.di_expression<[(1)]>
- mlirAttributeDump(mlirLLVMDIExpressionAttrGet(ctx, 1, &expression_elem));
+ mlirAttributeDump(expression);
+
+ // CHECK: #llvm.di_composite_type<{{.*}}>
+ mlirAttributeDump(mlirLLVMDICompositeTypeAttrGet(
+ ctx, 0, id, foo, file, 1, compile_unit, di_type, 0, 64, 8, 1, &di_type,
+ expression, expression, expression, expression));
}
int main(void) {
diff --git a/mlir/test/Target/LLVMIR/Import/composite-type-fortran.ll b/mlir/test/Target/LLVMIR/Import/composite-type-fortran.ll
new file mode 100644
index 0000000000000..1a39748ada63f
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/composite-type-fortran.ll
@@ -0,0 +1,25 @@
+; RUN: mlir-translate -import-llvm -mlir-print-debuginfo %s | FileCheck %s
+
+define void @fn_with_composite() !dbg !3 {
+ ret void
+}
+
+!llvm.dbg.cu = !{!1}
+!llvm.module.flags = !{!0}
+!0 = !{i32 2, !"Debug Info Version", i32 3}
+!1 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !2, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!2 = !DIFile(filename: "test.f90", directory: "")
+!3 = distinct !DISubprogram(name: "fn_with_composite", scope: !1, file: !2, type: !4, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1)
+!4 = !DISubroutineType(cc: DW_CC_normal, types: !5)
+!5 = !{null, !6}
+!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, elements: !8, dataLocation: !DIExpression(DW_OP_push_object_address, DW_OP_deref), associated: !DIExpression(DW_OP_lit0, DW_OP_eq), allocated: !DIExpression(DW_OP_lit0, DW_OP_ne), rank: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 16, DW_OP_deref))
+!7 = !DIBasicType(name: "integer", size: 32, encoding: DW_ATE_signed)
+!8 = !{!9}
+!9 = !DISubrange(count: 5, lowerBound: 1)
+!10 = !DILocation(line: 26, column: 3, scope: !3)
+
+; CHECK: #llvm.di_composite_type<tag = DW_TAG_array_type,
+; CHECK-SAME: dataLocation = <[DW_OP_push_object_address, DW_OP_deref]>
+; CHECK-SAME: rank = <[DW_OP_push_object_address, DW_OP_plus_uconst(16), DW_OP_deref]>
+; CHECK-SAME: allocated = <[DW_OP_lit0, DW_OP_ne]>
+; CHECK-SAME: associated = <[DW_OP_lit0, DW_OP_eq]>
diff --git a/mlir/test/Target/LLVMIR/llvmir-debug.mlir b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
index 2792f13e4ef8f..e5c233bc5e9bb 100644
--- a/mlir/test/Target/LLVMIR/llvmir-debug.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-debug.mlir
@@ -484,3 +484,38 @@ llvm.mlir.global @global_variable() {dbg_expr = #di_global_variable_expression}
// CHECK: ![[SCOPE]] = !DISubprogram({{.*}}type: ![[SUBROUTINE:[0-9]+]],
// CHECK: ![[SUBROUTINE]] = !DISubroutineType(types: ![[SR_TYPES:[0-9]+]])
// CHECK: ![[SR_TYPES]] = !{![[COMP]]}
+
+// -----
+
+#file = #llvm.di_file<"test.f90" in "">
+#cu = #llvm.di_compile_unit<id = distinct[0]<>, sourceLanguage = DW_LANG_Fortran95,
+ file = #file, producer = "", isOptimized = false, emissionKind = Full>
+#i32 = #llvm.di_basic_type<
+ tag = DW_TAG_base_type, name = "integer",
+ sizeInBits = 32, encoding = DW_ATE_signed
+>
+#null = #llvm.di_null_type
+#alloc = #llvm.di_expression<[DW_OP_lit0, DW_OP_ne]>
+#assoc = #llvm.di_expression<[DW_OP_lit0, DW_OP_eq]>
+#rank = #llvm.di_expression<[DW_OP_push_object_address, DW_OP_plus_uconst(16), DW_OP_deref]>
+#datal = #llvm.di_expression<[DW_OP_push_object_address, DW_OP_deref]>
+#array = #llvm.di_composite_type<tag = DW_TAG_array_type,
+ baseType = #i32,
+ dataLocation = #datal, rank = #rank,
+ allocated = #alloc, associated = #assoc,
+ elements = #llvm.di_subrange<lowerBound = 1, count = 5>
+>
+#spType0 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #null, #array>
+#sp0 = #llvm.di_subprogram<
+ compileUnit = #cu, scope = #cu, name = "fn_with_composite", file = #file,
+ subprogramFlags = "Definition|Optimized", type = #spType0
+>
+llvm.func @fn_with_composite() {
+ llvm.return
+}loc(fused<#sp0>["foo.mlir":1:1])
+// CHECK-LABEL: define void @fn_with_composite()
+// CHECK: !DICompositeType(
+// CHECK-SAME: dataLocation: !DIExpression(DW_OP_push_object_address, DW_OP_deref)
+// CHECK-SAME: associated: !DIExpression(DW_OP_lit0, DW_OP_eq)
+// CHECK-SAME: allocated: !DIExpression(DW_OP_lit0, DW_OP_ne)
+// CHECK-SAME: rank: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 16, DW_OP_deref)
More information about the Mlir-commits
mailing list