@@ -83,8 +83,8 @@ static mlir::LLVM::DITypeAttr genPlaceholderType(mlir::MLIRContext *context) {
83
83
84
84
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType (
85
85
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) {
88
88
89
89
mlir::MLIRContext *context = module .getContext ();
90
90
// FIXME: Assumed rank arrays not supported yet
@@ -114,7 +114,7 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
114
114
115
115
llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
116
116
mlir::LLVM::DITypeAttr elemTy =
117
- convertType (seqTy.getEleTy (), fileAttr, scope, loc );
117
+ convertType (seqTy.getEleTy (), fileAttr, scope, declOp );
118
118
unsigned offset = dimsOffset;
119
119
const unsigned indexSize = dimsSize / 3 ;
120
120
for ([[maybe_unused]] auto _ : seqTy.getShape ()) {
@@ -156,13 +156,14 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertBoxedSequenceType(
156
156
157
157
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType (
158
158
fir::SequenceType seqTy, mlir::LLVM::DIFileAttr fileAttr,
159
- mlir::LLVM::DIScopeAttr scope, mlir::Location loc ) {
159
+ mlir::LLVM::DIScopeAttr scope, fir::cg::XDeclareOp declOp ) {
160
160
mlir::MLIRContext *context = module .getContext ();
161
161
162
162
llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
163
163
mlir::LLVM::DITypeAttr elemTy =
164
- convertType (seqTy.getEleTy (), fileAttr, scope, loc );
164
+ convertType (seqTy.getEleTy (), fileAttr, scope, declOp );
165
165
166
+ unsigned index = 0 ;
166
167
for (fir::SequenceType::Extent dim : seqTy.getShape ()) {
167
168
if (dim == seqTy.getUnknownExtent ()) {
168
169
// FIXME: This path is taken for assumed size arrays but also for arrays
@@ -174,20 +175,20 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
174
175
elements.push_back (subrangeTy);
175
176
} else {
176
177
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
+ }
184
184
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 ));
186
186
auto subrangeTy = mlir::LLVM::DISubrangeAttr::get (
187
187
context, countAttr, lowerAttr, /* upperBound=*/ nullptr ,
188
188
/* stride=*/ nullptr );
189
189
elements.push_back (subrangeTy);
190
190
}
191
+ ++index;
191
192
}
192
193
// Apart from arrays, the `DICompositeTypeAttr` is used for other things like
193
194
// structure types. Many of its fields which are not applicable to arrays
@@ -203,7 +204,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
203
204
204
205
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType (
205
206
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) {
207
209
mlir::MLIRContext *context = module .getContext ();
208
210
209
211
// DWARF 5 says the following about the character encoding in 5.1.1.2.
@@ -250,21 +252,21 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
250
252
251
253
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType (
252
254
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) {
255
257
mlir::MLIRContext *context = module .getContext ();
256
258
257
259
// Arrays and character need different treatment because DWARF have special
258
260
// constructs for them to get the location from the descriptor. Rest of
259
261
// types are handled like pointer to underlying type.
260
262
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);
263
265
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 ,
265
267
/* hasDescriptor=*/ true );
266
268
267
- mlir::LLVM::DITypeAttr elTyAttr = convertType (elTy, fileAttr, scope, loc );
269
+ mlir::LLVM::DITypeAttr elTyAttr = convertType (elTy, fileAttr, scope, declOp );
268
270
269
271
return mlir::LLVM::DIDerivedTypeAttr::get (
270
272
context, llvm::dwarf::DW_TAG_pointer_type,
@@ -276,7 +278,7 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType(
276
278
mlir::LLVM::DITypeAttr
277
279
DebugTypeGenerator::convertType (mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
278
280
mlir::LLVM::DIScopeAttr scope,
279
- mlir::Location loc ) {
281
+ fir::cg::XDeclareOp declOp ) {
280
282
mlir::MLIRContext *context = module .getContext ();
281
283
if (Ty.isInteger ()) {
282
284
return genBasicType (context, mlir::StringAttr::get (context, " integer" ),
@@ -306,22 +308,22 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
306
308
return genBasicType (context, mlir::StringAttr::get (context, " complex" ),
307
309
bitWidth * 2 , llvm::dwarf::DW_ATE_complex_float);
308
310
} 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 );
310
312
} 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 ,
312
314
/* hasDescriptor=*/ false );
313
315
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(Ty)) {
314
316
auto elTy = boxTy.getElementType ();
315
317
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 ,
317
319
false );
318
320
if (auto heapTy = mlir::dyn_cast_or_null<fir::HeapType>(elTy))
319
321
return convertPointerLikeType (heapTy.getElementType (), fileAttr, scope,
320
- loc , /* genAllocated=*/ true ,
322
+ declOp , /* genAllocated=*/ true ,
321
323
/* genAssociated=*/ false );
322
324
if (auto ptrTy = mlir::dyn_cast_or_null<fir::PointerType>(elTy))
323
325
return convertPointerLikeType (ptrTy.getElementType (), fileAttr, scope,
324
- loc , /* genAllocated=*/ false ,
326
+ declOp , /* genAllocated=*/ false ,
325
327
/* genAssociated=*/ true );
326
328
return genPlaceholderType (context);
327
329
} else {
0 commit comments