Skip to content

Commit 3d64e5d

Browse files
author
Razvan Lupusoru
committed
Add better support for unlimited polymorphic and assumed type
1 parent a8b1627 commit 3d64e5d

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

flang/lib/Optimizer/OpenACC/FIROpenACCTypeInterfaces.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ static bool isArrayLike(mlir::Type type) {
306306
}
307307

308308
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+
309313
return mlir::isa<fir::RecordType, fir::ClassType, mlir::TupleType>(type);
310314
}
311315

@@ -322,8 +326,13 @@ OpenACCMappableModel<fir::BaseBoxType>::getTypeCategory(mlir::Type type,
322326
mlir::Value var) const {
323327
// Class-type does not behave like a normal box because it does not hold an
324328
// element type. Thus special handle it here.
325-
if (mlir::isa<fir::ClassType>(type))
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;
326334
return mlir::acc::VariableTypeCategory::composite;
335+
}
327336

328337
mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy(type);
329338
assert(eleTy && "expect to be able to unwrap the element type");
@@ -409,8 +418,12 @@ categorizePointee(mlir::Type pointer,
409418
return mlir::acc::VariableTypeCategory::composite;
410419
if (mlir::isa<fir::CharacterType, mlir::FunctionType>(eleTy))
411420
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;
412425
// "pointers" - in the sense of raw address point-of-view, are considered
413-
// scalars. However
426+
// scalars.
414427
if (mlir::isa<fir::LLVMPointerType>(eleTy))
415428
return mlir::acc::VariableTypeCategory::scalar;
416429

flang/test/Fir/OpenACC/openacc-type-categories-class.f90

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ subroutine init(this)
99
class(polyty), intent(inout) :: this
1010
!$acc enter data copyin(this, this%field)
1111
end subroutine
12+
subroutine init_assumed_type(var)
13+
type(*), intent(inout) :: var
14+
!$acc enter data copyin(var)
15+
end subroutine
16+
subroutine init_unlimited(this)
17+
class(*), intent(inout) :: this
18+
!$acc enter data copyin(this)
19+
select type(this)
20+
type is(real)
21+
!$acc enter data copyin(this)
22+
class is(polyty)
23+
!$acc enter data copyin(this, this%field)
24+
end select
25+
end subroutine
1226
end module
1327

1428
! CHECK: Visiting: {{.*}} acc.copyin {{.*}} {name = "this", structured = false}
@@ -17,3 +31,16 @@ subroutine init(this)
1731
! CHECK: Visiting: {{.*}} acc.copyin {{.*}} {name = "this%field", structured = false}
1832
! CHECK: Pointer-like: !fir.ref<f32>
1933
! CHECK: Type category: composite
34+
35+
! For unlimited polymorphic entities and assumed types - they effectively have
36+
! no declared type. Thus the type categorizer cannot categorize it.
37+
! CHECK: Visiting: {{.*}} = acc.copyin {{.*}} {name = "var", structured = false}
38+
! CHECK: Pointer-like: !fir.ref<none>
39+
! CHECK: Type category: uncategorized
40+
! CHECK: Visiting: {{.*}} = acc.copyin {{.*}} {name = "this", structured = false}
41+
! CHECK: Mappable: !fir.class<none>
42+
! CHECK: Type category: uncategorized
43+
44+
! TODO: After using select type - the appropriate type category should be
45+
! possible. Add the rest of the test once OpenACC lowering correctly handles
46+
! unlimited polymorhic.

0 commit comments

Comments
 (0)