Skip to content

Commit b8c1012

Browse files
committed
Handle review comments.
Merged handling of ClassType with BoxType. Used boxTy.unwrapInnerType() to avoid special casing for pointer or allocatable. Also improved convertPointerLikeType to better handle if underlying type in null or none.
1 parent 548bcf4 commit b8c1012

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,12 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType(
629629
return convertCharacterType(charTy, fileAttr, scope, declOp,
630630
/*hasDescriptor=*/true);
631631

632-
mlir::LLVM::DITypeAttr elTyAttr = convertType(elTy, fileAttr, scope, declOp);
632+
// If elTy is null or none then generate a void*
633+
mlir::LLVM::DITypeAttr elTyAttr;
634+
if (!elTy || mlir::isa<mlir::NoneType>(elTy))
635+
elTyAttr = mlir::LLVM::DINullTypeAttr::get(context);
636+
else
637+
elTyAttr = convertType(elTy, fileAttr, scope, declOp);
633638

634639
return mlir::LLVM::DIDerivedTypeAttr::get(
635640
context, llvm::dwarf::DW_TAG_pointer_type,
@@ -668,20 +673,6 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
668673
return convertRecordType(recTy, fileAttr, scope, declOp);
669674
} else if (auto tupleTy = mlir::dyn_cast_if_present<mlir::TupleType>(Ty)) {
670675
return convertTupleType(tupleTy, fileAttr, scope, declOp);
671-
} else if (auto classTy = mlir::dyn_cast_if_present<fir::ClassType>(Ty)) {
672-
// ClassType when passed to the function have double indirection so it
673-
// is represented as pointer to type (and not type as a RecordType will be
674-
// for example). If ClassType wraps a pointer or allocatable then we get
675-
// the real underlying type to avoid translating the Ty to
676-
// Ptr -> Ptr -> type.
677-
mlir::Type elTy = classTy.getEleTy();
678-
if (auto ptrTy = mlir::dyn_cast_if_present<fir::PointerType>(elTy))
679-
elTy = ptrTy.getElementType();
680-
else if (auto heapTy = mlir::dyn_cast_if_present<fir::HeapType>(elTy))
681-
elTy = heapTy.getElementType();
682-
return convertPointerLikeType(elTy, fileAttr, scope, declOp,
683-
/*genAllocated=*/false,
684-
/*genAssociated=*/false);
685676
} else if (auto refTy = mlir::dyn_cast_if_present<fir::ReferenceType>(Ty)) {
686677
auto elTy = refTy.getEleTy();
687678
return convertPointerLikeType(elTy, fileAttr, scope, declOp,
@@ -693,8 +684,13 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
693684
return genBasicType(context, mlir::StringAttr::get(context, "integer"),
694685
llvmTypeConverter.getIndexTypeBitwidth(),
695686
llvm::dwarf::DW_ATE_signed);
696-
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(Ty)) {
697-
auto elTy = boxTy.getElementType();
687+
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BaseBoxType>(Ty)) {
688+
if (mlir::isa<fir::ClassType>(Ty))
689+
return convertPointerLikeType(boxTy.unwrapInnerType(), fileAttr, scope,
690+
declOp, /*genAllocated=*/false,
691+
/*genAssociated=*/true);
692+
693+
auto elTy = boxTy.getEleTy();
698694
if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(elTy))
699695
return convertBoxedSequenceType(seqTy, fileAttr, scope, declOp, false,
700696
false);

flang/test/Transforms/debug-class-type.fir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
1111
%1 = fircg.ext_declare %0 {uniq_name = "_QFEx"} : (!fir.ref<!fir.class<!fir.heap<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>>) -> !fir.ref<!fir.class<!fir.heap<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>> loc(#loc3)
1212
%2 = fir.address_of(@_QFEy) : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>>
1313
%3 = fircg.ext_declare %2 {uniq_name = "_QFEy"} : (!fir.ref<!fir.class<!fir.ptr<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>>) -> !fir.ref<!fir.class<!fir.ptr<!fir.type<_QTtest_type{a:i32,b:!fir.box<!fir.heap<!fir.array<?x?xf32>>>}>>>> loc(#loc4)
14+
%4 = fir.address_of(@_QFEz) : !fir.ref<!fir.class<none>>
15+
%5 = fircg.ext_declare %4 {uniq_name = "_QFEz"} : (!fir.ref<!fir.class<none>>) -> !fir.ref<!fir.class<none>> loc(#loc4)
16+
%6 = fir.address_of(@_QFEt) : !fir.ref<!fir.class<!fir.ptr<none>>>
17+
%7 = fircg.ext_declare %6 {uniq_name = "_QFEt"} : (!fir.ref<!fir.class<!fir.ptr<none>>>) -> !fir.ref<!fir.class<!fir.ptr<none>>> loc(#loc4)
1418
return
1519
} loc(#loc2)
1620
}
@@ -22,6 +26,9 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
2226

2327
// CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type<{{.*}}name = "test_type"{{.*}}>
2428
// CHECK-DAG: #[[TY2:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, name = "", baseType = #[[TY1]]{{.*}}>
29+
// CHECK-DAG: #[[TY3:.*]] = #llvm.di_derived_type<tag = DW_TAG_pointer_type, name = "", baseType = #di_null_type{{.*}}>
2530
// CHECK-DAG: #llvm.di_subroutine_type<callingConvention = DW_CC_normal, types = #di_null_type, #[[TY2]]>
2631
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "x"{{.*}}type = #[[TY2]]>
2732
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "y"{{.*}}type = #[[TY2]]>
33+
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "z"{{.*}}type = #[[TY3]]>
34+
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "t"{{.*}}type = #[[TY3]]>

0 commit comments

Comments
 (0)