@@ -83,8 +83,8 @@ static mlir::LLVM::DITypeAttr genPlaceholderType(mlir::MLIRContext *context) {
8383
8484mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType (
8585 fir::SequenceType seqTy, mlir::LLVM::DIFileAttr fileAttr,
86- mlir::LLVM::DIScopeAttr scope, mlir::Location loc, bool genAllocated ,
87- bool genAssociated) {
86+ mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp ,
87+ bool genAllocated, bool genAssociated) {
8888
8989 mlir::MLIRContext *context = module .getContext ();
9090 // FIXME: Assumed rank arrays not supported yet
@@ -114,7 +114,7 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
114114
115115 llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
116116 mlir::LLVM::DITypeAttr elemTy =
117- convertType (seqTy.getEleTy (), fileAttr, scope, loc );
117+ convertType (seqTy.getEleTy (), fileAttr, scope, declOp );
118118 unsigned offset = dimsOffset;
119119 const unsigned indexSize = dimsSize / 3 ;
120120 for ([[maybe_unused]] auto _ : seqTy.getShape ()) {
@@ -156,13 +156,14 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
156156
157157mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType (
158158 fir::SequenceType seqTy, mlir::LLVM::DIFileAttr fileAttr,
159- mlir::LLVM::DIScopeAttr scope, mlir::Location loc ) {
159+ mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp ) {
160160 mlir::MLIRContext *context = module .getContext ();
161161
162162 llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
163163 mlir::LLVM::DITypeAttr elemTy =
164- convertType (seqTy.getEleTy (), fileAttr, scope, loc );
164+ convertType (seqTy.getEleTy (), fileAttr, scope, declOp );
165165
166+ unsigned index = 0 ;
166167 for (fir::SequenceType::Extent dim : seqTy.getShape ()) {
167168 if (dim == seqTy.getUnknownExtent ()) {
168169 // FIXME: This path is taken for assumed size arrays but also for arrays
@@ -174,20 +175,20 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
174175 elements.push_back (subrangeTy);
175176 } else {
176177 auto intTy = mlir::IntegerType::get (context, 64 );
177- // FIXME: Only supporting lower bound of 1 at the moment. The
178- // 'SequenceType' has information about the shape but not the shift. In
179- // cases where the conversion originated during the processing of
180- // 'DeclareOp', it may be possible to pass on this information. But the
181- // type conversion should ideally be based on what information present in
182- // the type class so that it works from everywhere (e.g. when it is part
183- // of a module or a derived type.)
178+ int64_t shift = 1 ;
179+ if (declOp && declOp.getShift ().size () > index) {
180+ if (std::optional<std::int64_t > optint =
181+ getIntIfConstant (declOp.getShift ()[index]))
182+ shift = *optint;
183+ }
184184 auto countAttr = mlir::IntegerAttr::get (intTy, llvm::APInt (64 , dim));
185- auto lowerAttr = mlir::IntegerAttr::get (intTy, llvm::APInt (64 , 1 ));
185+ auto lowerAttr = mlir::IntegerAttr::get (intTy, llvm::APInt (64 , shift ));
186186 auto subrangeTy = mlir::LLVM::DISubrangeAttr::get (
187187 context, countAttr, lowerAttr, /* upperBound=*/ nullptr ,
188188 /* stride=*/ nullptr );
189189 elements.push_back (subrangeTy);
190190 }
191+ ++index;
191192 }
192193 // Apart from arrays, the `DICompositeTypeAttr` is used for other things like
193194 // structure types. Many of its fields which are not applicable to arrays
@@ -203,7 +204,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
203204
204205mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType (
205206 fir::CharacterType charTy, mlir::LLVM::DIFileAttr fileAttr,
206- mlir::LLVM::DIScopeAttr scope, mlir::Location loc, bool hasDescriptor) {
207+ mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp,
208+ bool hasDescriptor) {
207209 mlir::MLIRContext *context = module .getContext ();
208210
209211 // DWARF 5 says the following about the character encoding in 5.1.1.2.
@@ -250,21 +252,21 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
250252
251253mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType (
252254 mlir::Type elTy, mlir::LLVM::DIFileAttr fileAttr,
253- mlir::LLVM::DIScopeAttr scope, mlir::Location loc, bool genAllocated ,
254- bool genAssociated) {
255+ mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp ,
256+ bool genAllocated, bool genAssociated) {
255257 mlir::MLIRContext *context = module .getContext ();
256258
257259 // Arrays and character need different treatment because DWARF have special
258260 // constructs for them to get the location from the descriptor. Rest of
259261 // types are handled like pointer to underlying type.
260262 if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(elTy))
261- return convertBoxedSequenceType (seqTy, fileAttr, scope, loc, genAllocated ,
262- genAssociated);
263+ return convertBoxedSequenceType (seqTy, fileAttr, scope, declOp ,
264+ genAllocated, genAssociated);
263265 if (auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(elTy))
264- return convertCharacterType (charTy, fileAttr, scope, loc ,
266+ return convertCharacterType (charTy, fileAttr, scope, declOp ,
265267 /* hasDescriptor=*/ true );
266268
267- mlir::LLVM::DITypeAttr elTyAttr = convertType (elTy, fileAttr, scope, loc );
269+ mlir::LLVM::DITypeAttr elTyAttr = convertType (elTy, fileAttr, scope, declOp );
268270
269271 return mlir::LLVM::DIDerivedTypeAttr::get (
270272 context, llvm::dwarf::DW_TAG_pointer_type,
@@ -276,7 +278,7 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType(
276278mlir::LLVM::DITypeAttr
277279DebugTypeGenerator::convertType (mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
278280 mlir::LLVM::DIScopeAttr scope,
279- mlir::Location loc ) {
281+ fir::cg::XDeclareOp declOp ) {
280282 mlir::MLIRContext *context = module .getContext ();
281283 if (Ty.isInteger ()) {
282284 return genBasicType (context, mlir::StringAttr::get (context, " integer" ),
@@ -306,22 +308,22 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
306308 return genBasicType (context, mlir::StringAttr::get (context, " complex" ),
307309 bitWidth * 2 , llvm::dwarf::DW_ATE_complex_float);
308310 } else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(Ty)) {
309- return convertSequenceType (seqTy, fileAttr, scope, loc );
311+ return convertSequenceType (seqTy, fileAttr, scope, declOp );
310312 } else if (auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(Ty)) {
311- return convertCharacterType (charTy, fileAttr, scope, loc ,
313+ return convertCharacterType (charTy, fileAttr, scope, declOp ,
312314 /* hasDescriptor=*/ false );
313315 } else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(Ty)) {
314316 auto elTy = boxTy.getElementType ();
315317 if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(elTy))
316- return convertBoxedSequenceType (seqTy, fileAttr, scope, loc , false ,
318+ return convertBoxedSequenceType (seqTy, fileAttr, scope, declOp , false ,
317319 false );
318320 if (auto heapTy = mlir::dyn_cast_or_null<fir::HeapType>(elTy))
319321 return convertPointerLikeType (heapTy.getElementType (), fileAttr, scope,
320- loc , /* genAllocated=*/ true ,
322+ declOp , /* genAllocated=*/ true ,
321323 /* genAssociated=*/ false );
322324 if (auto ptrTy = mlir::dyn_cast_or_null<fir::PointerType>(elTy))
323325 return convertPointerLikeType (ptrTy.getElementType (), fileAttr, scope,
324- loc , /* genAllocated=*/ false ,
326+ declOp , /* genAllocated=*/ false ,
325327 /* genAssociated=*/ true );
326328 return genPlaceholderType (context);
327329 } else {
0 commit comments