@@ -306,6 +306,10 @@ static bool isArrayLike(mlir::Type type) {
306
306
}
307
307
308
308
static bool isCompositeLike (mlir::Type type) {
309
+ // class(*) is not a composite type since it does not have a determined type.
310
+ if (fir::isUnlimitedPolymorphicType (type))
311
+ return false ;
312
+
309
313
return mlir::isa<fir::RecordType, fir::ClassType, mlir::TupleType>(type);
310
314
}
311
315
@@ -320,8 +324,18 @@ template <>
320
324
mlir::acc::VariableTypeCategory
321
325
OpenACCMappableModel<fir::BaseBoxType>::getTypeCategory(mlir::Type type,
322
326
mlir::Value var) const {
327
+ // Class-type does not behave like a normal box because it does not hold an
328
+ // element type. Thus special handle it here.
329
+ if (mlir::isa<fir::ClassType>(type)) {
330
+ // class(*) is not a composite type since it does not have a determined
331
+ // type.
332
+ if (fir::isUnlimitedPolymorphicType (type))
333
+ return mlir::acc::VariableTypeCategory::uncategorized;
334
+ return mlir::acc::VariableTypeCategory::composite;
335
+ }
323
336
324
337
mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy (type);
338
+ assert (eleTy && " expect to be able to unwrap the element type" );
325
339
326
340
// If the type enclosed by the box is a mappable type, then have it
327
341
// provide the type category.
@@ -346,7 +360,7 @@ OpenACCMappableModel<fir::BaseBoxType>::getTypeCategory(mlir::Type type,
346
360
return mlir::acc::VariableTypeCategory::nonscalar;
347
361
}
348
362
349
- static mlir::TypedValue<mlir::acc::PointerLikeType>
363
+ static mlir::Value
350
364
getBaseRef (mlir::TypedValue<mlir::acc::PointerLikeType> varPtr) {
351
365
// If there is no defining op - the unwrapped reference is the base one.
352
366
mlir::Operation *op = varPtr.getDefiningOp ();
@@ -372,7 +386,7 @@ getBaseRef(mlir::TypedValue<mlir::acc::PointerLikeType> varPtr) {
372
386
})
373
387
.Default ([&](mlir::Operation *) { return varPtr; });
374
388
375
- return mlir::cast<mlir::TypedValue<mlir::acc::PointerLikeType>>( baseRef) ;
389
+ return baseRef;
376
390
}
377
391
378
392
static mlir::acc::VariableTypeCategory
@@ -384,10 +398,17 @@ categorizePointee(mlir::Type pointer,
384
398
// value would both be represented as !fir.ref<f32>. We do not want to treat
385
399
// such a reference as a scalar. Thus unwrap interior pointer calculations.
386
400
auto baseRef = getBaseRef (varPtr);
387
- mlir::Type eleTy = baseRef.getType ().getElementType ();
388
401
389
- if (auto mappableTy = mlir::dyn_cast<mlir::acc::MappableType>(eleTy))
390
- return mappableTy.getTypeCategory (varPtr);
402
+ if (auto mappableTy =
403
+ mlir::dyn_cast<mlir::acc::MappableType>(baseRef.getType ()))
404
+ return mappableTy.getTypeCategory (baseRef);
405
+
406
+ // It must be a pointer-like type since it is not a MappableType.
407
+ auto ptrLikeTy = mlir::cast<mlir::acc::PointerLikeType>(baseRef.getType ());
408
+ mlir::Type eleTy = ptrLikeTy.getElementType ();
409
+
410
+ if (auto mappableEleTy = mlir::dyn_cast<mlir::acc::MappableType>(eleTy))
411
+ return mappableEleTy.getTypeCategory (varPtr);
391
412
392
413
if (isScalarLike (eleTy))
393
414
return mlir::acc::VariableTypeCategory::scalar;
@@ -397,8 +418,12 @@ categorizePointee(mlir::Type pointer,
397
418
return mlir::acc::VariableTypeCategory::composite;
398
419
if (mlir::isa<fir::CharacterType, mlir::FunctionType>(eleTy))
399
420
return mlir::acc::VariableTypeCategory::nonscalar;
421
+ // Assumed-type (type(*))does not have a determined type that can be
422
+ // categorized.
423
+ if (mlir::isa<mlir::NoneType>(eleTy))
424
+ return mlir::acc::VariableTypeCategory::uncategorized;
400
425
// "pointers" - in the sense of raw address point-of-view, are considered
401
- // scalars. However
426
+ // scalars.
402
427
if (mlir::isa<fir::LLVMPointerType>(eleTy))
403
428
return mlir::acc::VariableTypeCategory::scalar;
404
429
0 commit comments