Skip to content
Merged
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
8 changes: 6 additions & 2 deletions flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
context, llvm::dwarf::DW_TAG_member,
mlir::StringAttr::get(context, fieldName), elemTy, byteSize * 8,
byteAlign * 8, offset * 8, /*optional<address space>=*/std::nullopt,
/*flags=*/mlir::LLVM::DIFlags::Zero,
/*extra data=*/nullptr);
elements.push_back(tyAttr);
offset += llvm::alignTo(byteSize, byteAlign);
Expand Down Expand Up @@ -480,6 +481,7 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertTupleType(
context, llvm::dwarf::DW_TAG_member, mlir::StringAttr::get(context, ""),
elemTy, byteSize * 8, byteAlign * 8, offset * 8,
/*optional<address space>=*/std::nullopt,
/*flags=*/mlir::LLVM::DIFlags::Zero,
/*extra data=*/nullptr);
elements.push_back(tyAttr);
offset += llvm::alignTo(byteSize, byteAlign);
Expand Down Expand Up @@ -673,7 +675,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType(
context, llvm::dwarf::DW_TAG_pointer_type,
mlir::StringAttr::get(context, ""), elTyAttr, /*sizeInBits=*/ptrSize * 8,
/*alignInBits=*/0, /*offset=*/0,
/*optional<address space>=*/std::nullopt, /*extra data=*/nullptr);
/*optional<address space>=*/std::nullopt,
/*flags=*/mlir::LLVM::DIFlags::Zero, /*extra data=*/nullptr);
}

static mlir::StringAttr getBasicTypeName(mlir::MLIRContext *context,
Expand Down Expand Up @@ -742,7 +745,8 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
context, llvm::dwarf::DW_TAG_pointer_type,
mlir::StringAttr::get(context, ""), subroutineTy,
/*sizeInBits=*/ptrSize * 8, /*alignInBits=*/0, /*offset=*/0,
/*optional<address space>=*/std::nullopt, /*extra data=*/nullptr);
/*optional<address space>=*/std::nullopt,
/*flags=*/mlir::LLVM::DIFlags::Zero, /*extra data=*/nullptr);
} else if (auto refTy = mlir::dyn_cast_if_present<fir::ReferenceType>(Ty)) {
auto elTy = refTy.getEleTy();
return convertPointerLikeType(elTy, fileAttr, scope, declOp,
Expand Down
3 changes: 2 additions & 1 deletion mlir/include/mlir-c/Dialect/LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void);
MLIR_CAPI_EXPORTED MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
MlirContext ctx, unsigned int tag, MlirAttribute name,
MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,
uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData);
uint64_t offsetInBits, int64_t dwarfAddressSpace, int64_t flags,
MlirAttribute extraData);

MLIR_CAPI_EXPORTED MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void);

Expand Down
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMAttrDefs.td
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ def LLVM_DIDerivedTypeAttr : LLVM_Attr<"DIDerivedType", "di_derived_type",
OptionalParameter<"uint32_t">:$alignInBits,
OptionalParameter<"uint64_t">:$offsetInBits,
OptionalParameter<"std::optional<unsigned>">:$dwarfAddressSpace,
OptionalParameter<"DIFlags", "DIFlags::Zero">:$flags,
OptionalParameter<"DINodeAttr">:$extraData
);
let assemblyFormat = "`<` struct(params) `>`";
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Dialect/LLVMIR/LLVMDialectBytecode.td
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ def DIDerivedTypeAttr : DialectAttribute<(attr
VarInt:$alignInBits,
VarInt:$offsetInBits,
OptionalInt<"unsigned">:$dwarfAddressSpace,
EnumClassFlag<"DIFlags", "getFlags()">:$_rawflags,
LocalVar<"DIFlags", "(DIFlags)_rawflags">:$flags,
OptionalAttribute<"DINodeAttr">:$extraData
)>;

Expand Down
12 changes: 7 additions & 5 deletions mlir/lib/CAPI/Dialect/LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,19 @@ MlirStringRef mlirLLVMDICompositeTypeAttrGetName(void) {
return wrap(DICompositeTypeAttr::name);
}

MlirAttribute mlirLLVMDIDerivedTypeAttrGet(
MlirContext ctx, unsigned int tag, MlirAttribute name,
MlirAttribute baseType, uint64_t sizeInBits, uint32_t alignInBits,
uint64_t offsetInBits, int64_t dwarfAddressSpace, MlirAttribute extraData) {
MlirAttribute
mlirLLVMDIDerivedTypeAttrGet(MlirContext ctx, unsigned int tag,
MlirAttribute name, MlirAttribute baseType,
uint64_t sizeInBits, uint32_t alignInBits,
uint64_t offsetInBits, int64_t dwarfAddressSpace,
int64_t flags, MlirAttribute extraData) {
std::optional<unsigned> addressSpace = std::nullopt;
if (dwarfAddressSpace >= 0)
addressSpace = (unsigned)dwarfAddressSpace;
return wrap(DIDerivedTypeAttr::get(
unwrap(ctx), tag, cast<StringAttr>(unwrap(name)),
cast<DITypeAttr>(unwrap(baseType)), sizeInBits, alignInBits, offsetInBits,
addressSpace, cast<DINodeAttr>(unwrap(extraData))));
addressSpace, DIFlags(flags), cast<DINodeAttr>(unwrap(extraData))));
}

MlirStringRef mlirLLVMDIDerivedTypeAttrGetName(void) {
Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/Target/LLVMIR/DebugImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ DIDerivedTypeAttr DebugImporter::translateImpl(llvm::DIDerivedType *node) {
return DIDerivedTypeAttr::get(
context, node->getTag(), getStringAttrOrNull(node->getRawName()),
baseType, node->getSizeInBits(), node->getAlignInBits(),
node->getOffsetInBits(), node->getDWARFAddressSpace(), extraData);
node->getOffsetInBits(), node->getDWARFAddressSpace(),
symbolizeDIFlags(node->getFlags()).value_or(DIFlags::Zero), extraData);
}

DIStringTypeAttr DebugImporter::translateImpl(llvm::DIStringType *node) {
Expand Down
3 changes: 2 additions & 1 deletion mlir/lib/Target/LLVMIR/DebugTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ llvm::DIDerivedType *DebugTranslation::translateImpl(DIDerivedTypeAttr attr) {
/*Scope=*/nullptr, translate(attr.getBaseType()), attr.getSizeInBits(),
attr.getAlignInBits(), attr.getOffsetInBits(),
attr.getDwarfAddressSpace(), /*PtrAuthData=*/std::nullopt,
/*Flags=*/llvm::DINode::FlagZero, translate(attr.getExtraData()));
/*Flags=*/static_cast<llvm::DINode::DIFlags>(attr.getFlags()),
translate(attr.getExtraData()));
}

llvm::DIStringType *DebugTranslation::translateImpl(DIStringTypeAttr attr) {
Expand Down
6 changes: 3 additions & 3 deletions mlir/test/CAPI/llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ static void testDebugInfoAttributes(MlirContext ctx) {
// CHECK: #llvm.di_derived_type<{{.*}}>
// CHECK-NOT: dwarfAddressSpace
mlirAttributeDump(mlirLLVMDIDerivedTypeAttrGet(
ctx, 0, bar, di_type, 64, 8, 0, MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL,
ctx, 0, bar, di_type, 64, 8, 0, MLIR_CAPI_DWARF_ADDRESS_SPACE_NULL, 0,
di_type));

// CHECK: #llvm.di_derived_type<{{.*}} dwarfAddressSpace = 3{{.*}}>
mlirAttributeDump(
mlirLLVMDIDerivedTypeAttrGet(ctx, 0, bar, di_type, 64, 8, 0, 3, di_type));
mlirAttributeDump(mlirLLVMDIDerivedTypeAttrGet(ctx, 0, bar, di_type, 64, 8, 0,
3, 0, di_type));

MlirAttribute subroutine_type =
mlirLLVMDISubroutineTypeAttrGet(ctx, 0x0, 1, &di_type);
Expand Down
14 changes: 12 additions & 2 deletions mlir/test/Dialect/LLVMIR/debuginfo.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
dwarfAddressSpace = 3, extraData = #int1
>

// CHECK-DAG: #[[PTR3:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, flags = "Artificial|ObjectPointer">
#ptr3 = #llvm.di_derived_type<
tag = DW_TAG_pointer_type, flags = "Artificial|ObjectPointer"
>

// CHECK-DAG: #[[PTR4:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type>
#ptr4 = #llvm.di_derived_type<
tag = DW_TAG_pointer_type, flags = "Zero"
>

// CHECK-DAG: #[[COMP0:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type, name = "array0", line = 10, sizeInBits = 128, alignInBits = 32>
#comp0 = #llvm.di_composite_type<
tag = DW_TAG_array_type, name = "array0",
Expand Down Expand Up @@ -89,9 +99,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 = DW_CC_normal, types = #[[NULL]], #[[INT0]], #[[PTR0]], #[[PTR1]], #[[PTR2]], #[[COMP0:.*]], #[[COMP1:.*]], #[[COMP2:.*]], #[[COMP3:.*]]>
// CHECK-DAG: #[[SPTYPE0:.*]] = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #[[NULL]], #[[INT0]], #[[PTR0]], #[[PTR1]], #[[PTR2]], #[[PTR3]], #[[PTR4]], #[[COMP0:.*]], #[[COMP1:.*]], #[[COMP2:.*]], #[[COMP3:.*]]>
#spType0 = #llvm.di_subroutine_type<
callingConvention = DW_CC_normal, types = #null, #int0, #ptr0, #ptr1, #ptr2, #comp0, #comp1, #comp2, #comp3
callingConvention = DW_CC_normal, types = #null, #int0, #ptr0, #ptr1, #ptr2, #ptr3, #ptr4, #comp0, #comp1, #comp2, #comp3
>

// CHECK-DAG: #[[SPTYPE1:.*]] = #llvm.di_subroutine_type<types = #[[INT1]], #[[INT1]]>
Expand Down
6 changes: 3 additions & 3 deletions mlir/test/Target/LLVMIR/Import/debug-info.ll
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ define void @class_method() {
; Verify the cyclic subprogram is handled correctly.
; CHECK-DAG: #[[SP_SELF:.+]] = #llvm.di_subprogram<recId = [[REC_ID:.+]], isRecSelf = true>
; CHECK-DAG: #[[COMP:.+]] = #llvm.di_composite_type<tag = DW_TAG_class_type, name = "class_name", file = #{{.*}}, line = 42, flags = "TypePassByReference|NonTrivial", elements = #[[SP_SELF]]>
; CHECK-DAG: #[[COMP_PTR:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP]], sizeInBits = 64>
; CHECK-DAG: #[[COMP_PTR:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP]], sizeInBits = 64, flags = "Artificial|ObjectPointer">
; CHECK-DAG: #[[SP_TYPE:.+]] = #llvm.di_subroutine_type<types = #{{.*}}, #[[COMP_PTR]]>
; CHECK-DAG: #[[SP:.+]] = #llvm.di_subprogram<recId = [[REC_ID]], id = [[SP_ID:.+]], compileUnit = #{{.*}}, scope = #[[COMP]], name = "class_method", file = #{{.*}}, subprogramFlags = Definition, type = #[[SP_TYPE]]>
; CHECK-DAG: #[[LOC]] = loc(fused<#[[SP]]>
Expand All @@ -338,10 +338,10 @@ define void @class_method() {

; Verify the cyclic composite type is handled correctly.
; CHECK-DAG: #[[COMP_SELF:.+]] = #llvm.di_composite_type<recId = [[REC_ID:.+]], isRecSelf = true>
; CHECK-DAG: #[[COMP_PTR_INNER:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP_SELF]]>
; CHECK-DAG: #[[COMP_PTR_INNER:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP_SELF]], flags = "Artificial|ObjectPointer">
; CHECK-DAG: #[[FIELD:.+]] = #llvm.di_derived_type<tag = DW_TAG_member, name = "call_field", baseType = #[[COMP_PTR_INNER]]>
; CHECK-DAG: #[[COMP:.+]] = #llvm.di_composite_type<recId = [[REC_ID]], tag = DW_TAG_class_type, name = "class_field", file = #{{.*}}, line = 42, flags = "TypePassByReference|NonTrivial", elements = #[[FIELD]]>
; CHECK-DAG: #[[COMP_PTR_OUTER:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP]]>
; CHECK-DAG: #[[COMP_PTR_OUTER:.+]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, baseType = #[[COMP]], flags = "Artificial|ObjectPointer">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Changing one of these to the default value (zero, IIUC), would be nice for coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comes from the same llvm.di_derived_type due to how recursive records works. I could be wrong though. I will add default value checking in the round trip test.

; CHECK-DAG: #[[VAR0:.+]] = #llvm.di_local_variable<scope = #{{.*}}, name = "class_field", file = #{{.*}}, type = #[[COMP_PTR_OUTER]]>

; CHECK: @class_field
Expand Down
9 changes: 7 additions & 2 deletions mlir/test/Target/LLVMIR/llvmir-debug.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ llvm.func @func_no_debug() {
sizeInBits = 64, alignInBits = 32, offsetInBits = 8,
dwarfAddressSpace = 3
>
#flags = #llvm.di_derived_type<
tag = DW_TAG_pointer_type, baseType = #si32,
sizeInBits = 64, flags = "Artificial|ObjectPointer"
>
#cu = #llvm.di_compile_unit<
id = distinct[0]<>, sourceLanguage = DW_LANG_C, file = #file,
producer = "MLIR", isOptimized = true, emissionKind = Full,
Expand All @@ -56,7 +60,7 @@ llvm.func @func_no_debug() {
elements = #llvm.di_subrange<lowerBound = 0, upperBound = 4, stride = 1>
>
#null = #llvm.di_null_type
#spType0 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #null, #si64, #ptr, #named, #ptrWithAddressSpace, #composite, #vector>
#spType0 = #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #null, #si64, #ptr, #named, #ptrWithAddressSpace, #flags, #composite, #vector>
#toplevel_namespace = #llvm.di_namespace<
name = "toplevel", exportSymbols = true
>
Expand Down Expand Up @@ -147,12 +151,13 @@ llvm.func @empty_types() {
// CHECK: ![[NESTED_NAMESPACE]] = !DINamespace(name: "nested", scope: ![[TOPLEVEL_NAMESPACE:.*]])
// CHECK: ![[TOPLEVEL_NAMESPACE]] = !DINamespace(name: "toplevel", scope: null, exportSymbols: true)
// CHECK: ![[FUNC_TYPE]] = !DISubroutineType(cc: DW_CC_normal, types: ![[FUNC_ARGS:.*]])
// CHECK: ![[FUNC_ARGS]] = !{null, ![[ARG_TYPE:.*]], ![[PTR_TYPE:.*]], ![[NAMED_TYPE:.*]], ![[PTR_WITH_ADDR_SPACE:.*]], ![[COMPOSITE_TYPE:.*]], ![[VECTOR_TYPE:.*]]}
// CHECK: ![[FUNC_ARGS]] = !{null, ![[ARG_TYPE:.*]], ![[PTR_TYPE:.*]], ![[NAMED_TYPE:.*]], ![[PTR_WITH_ADDR_SPACE:.*]], ![[FLAGS:.*]], ![[COMPOSITE_TYPE:.*]], ![[VECTOR_TYPE:.*]]}
// CHECK: ![[ARG_TYPE]] = !DIBasicType(name: "si64")
// CHECK: ![[PTR_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[BASE_TYPE:.*]], size: 64, align: 32, offset: 8, extraData: ![[BASE_TYPE]])
// CHECK: ![[BASE_TYPE]] = !DIBasicType(name: "si32", size: 32, encoding: DW_ATE_signed)
// CHECK: ![[NAMED_TYPE]] = !DIDerivedType(tag: DW_TAG_pointer_type, name: "named", baseType: ![[BASE_TYPE:.*]])
// CHECK: ![[PTR_WITH_ADDR_SPACE]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[BASE_TYPE:.*]], size: 64, align: 32, offset: 8, dwarfAddressSpace: 3)
// CHECK: ![[FLAGS]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[BASE_TYPE:.*]], size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
// CHECK: ![[COMPOSITE_TYPE]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "composite", file: ![[CU_FILE_LOC]], line: 42, size: 64, align: 32, elements: ![[COMPOSITE_ELEMENTS:.*]])
// CHECK: ![[COMPOSITE_ELEMENTS]] = !{![[COMPOSITE_ELEMENT:.*]]}
// CHECK: ![[COMPOSITE_ELEMENT]] = !DISubrange(count: 4)
Expand Down