Skip to content

Commit

Permalink
[flang] Do not omit fir.ref in getTypeAsString
Browse files Browse the repository at this point in the history
Do not omit fir.ref when creating the string representation to we can
have different representation for `!fir.ref<i32>` and `i32`.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D151261
  • Loading branch information
clementval committed May 23, 2023
1 parent 804af93 commit 6e3dcd3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 18 deletions.
5 changes: 2 additions & 3 deletions flang/include/flang/Optimizer/Dialect/FIRType.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,10 @@ inline bool isBoxAddressOrValue(mlir::Type t) {
return fir::unwrapRefType(t).isa<fir::BaseBoxType>();
}

/// Return a string representation of `ty`. The fir.ref is omitted in the
/// representation.
/// Return a string representation of `ty`.
///
/// fir.array<10x10xf32> -> prefix_10x10xf32
/// fir.ref<i32> -> i32
/// fir.ref<i32> -> prefix_ref_i32
std::string getTypeAsString(mlir::Type ty, const KindMapping &kindMap,
llvm::StringRef prefix = "");

Expand Down
4 changes: 3 additions & 1 deletion flang/lib/Optimizer/Dialect/FIRType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
name << prefix.str();
if (!prefix.empty())
name << "_";
ty = fir::unwrapRefType(ty);
while (ty) {
if (fir::isa_trivial(ty)) {
if (mlir::isa<mlir::IndexType>(ty)) {
Expand Down Expand Up @@ -518,6 +517,9 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
for (auto extent : seqTy.getShape())
name << extent << 'x';
ty = seqTy.getEleTy();
} else if (auto refTy = mlir::dyn_cast_or_null<fir::ReferenceType>(ty)) {
name << "ref_";
ty = refTy.getEleTy();
} else {
// TODO: add support for RecordType/BaseBoxType
llvm::report_fatal_error("unsupported type");
Expand Down
8 changes: 4 additions & 4 deletions flang/test/Lower/OpenACC/acc-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s

! CHECK-LABEL: acc.private.recipe @privatization_10x10xf32 : !fir.ref<!fir.array<10x10xf32>> init {
! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref<!fir.array<10x10xf32>> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<10x10xf32>>):
! CHECK: acc.yield %{{.*}} : !fir.ref<!fir.array<10x10xf32>>
! CHECK: }
Expand Down Expand Up @@ -159,7 +159,7 @@ program acc_loop
a(i) = b(i)
END DO

!CHECK: acc.loop private(@privatization_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) {
!CHECK: acc.loop private(@privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) {
!CHECK: fir.do_loop
!CHECK: acc.yield
!CHECK-NEXT: }{{$}}
Expand All @@ -169,7 +169,7 @@ program acc_loop
a(i) = b(i)
END DO

!CHECK: acc.loop private(@privatization_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>, @privatization_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) {
!CHECK: acc.loop private(@privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) {
!CHECK: fir.do_loop
!CHECK: acc.yield
!CHECK-NEXT: }{{$}}
Expand All @@ -179,7 +179,7 @@ program acc_loop
a(i) = b(i)
END DO

!CHECK: acc.loop private(@privatization_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>, @privatization_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) {
!CHECK: acc.loop private(@privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref<!fir.array<10x10xf32>>) {
!CHECK: fir.do_loop
!CHECK: acc.yield
!CHECK-NEXT: }{{$}}
Expand Down
6 changes: 3 additions & 3 deletions flang/test/Lower/OpenACC/acc-parallel-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s

! CHECK-LABEL: acc.private.recipe @privatization_10xf32 : !fir.ref<!fir.array<10xf32>> init {
! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref<!fir.array<10xf32>> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<10xf32>>):
! CHECK: acc.yield %{{.*}} : !fir.ref<!fir.array<10xf32>>
! CHECK: }
Expand Down Expand Up @@ -454,8 +454,8 @@ subroutine acc_parallel_loop
a(i) = b(i)
END DO

! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref<!fir.array<10xf32>>) private(@privatization_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: acc.loop private(@privatization_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref<!fir.array<10xf32>>) private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: acc.loop private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Lower/OpenACC/acc-parallel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s

! CHECK-LABEL: acc.private.recipe @privatization_10x10xf32 : !fir.ref<!fir.array<10x10xf32>> init {
! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref<!fir.array<10x10xf32>> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<10x10xf32>>):
! CHECK: acc.yield %{{.*}} : !fir.ref<!fir.array<10x10xf32>>
! CHECK: }
Expand Down Expand Up @@ -298,7 +298,7 @@ subroutine acc_parallel
!$acc parallel private(a) firstprivate(b) private(c)
!$acc end parallel

! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref<!fir.array<10x10xf32>>) private(@privatization_10x10xf32 -> %[[A]] : !fir.ref<!fir.array<10x10xf32>>, @privatization_10x10xf32 -> %[[C]] : !fir.ref<!fir.array<10x10xf32>>) {
! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref<!fir.array<10x10xf32>>) private(@privatization_ref_10x10xf32 -> %[[A]] : !fir.ref<!fir.array<10x10xf32>>, @privatization_ref_10x10xf32 -> %[[C]] : !fir.ref<!fir.array<10x10xf32>>) {
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down
6 changes: 3 additions & 3 deletions flang/test/Lower/OpenACC/acc-serial-loop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s

! CHECK-LABEL: acc.private.recipe @privatization_10xf32 : !fir.ref<!fir.array<10xf32>> init {
! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref<!fir.array<10xf32>> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<10xf32>>):
! CHECK: acc.yield %{{.*}} : !fir.ref<!fir.array<10xf32>>
! CHECK: }
Expand Down Expand Up @@ -370,8 +370,8 @@ subroutine acc_serial_loop
a(i) = b(i)
END DO

! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref<!fir.array<10xf32>>) private(@privatization_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: acc.loop private(@privatization_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref<!fir.array<10xf32>>) private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: acc.loop private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref<!fir.array<10xf32>>) {
! CHECK: fir.do_loop
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Lower/OpenACC/acc-serial.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s

! CHECK-LABEL: acc.private.recipe @privatization_10x10xf32 : !fir.ref<!fir.array<10x10xf32>> init {
! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref<!fir.array<10x10xf32>> init {
! CHECK: ^bb0(%{{.*}}: !fir.ref<!fir.array<10x10xf32>>):
! CHECK: acc.yield %{{.*}} : !fir.ref<!fir.array<10x10xf32>>
! CHECK: }
Expand Down Expand Up @@ -241,7 +241,7 @@ subroutine acc_serial
!$acc serial private(a) firstprivate(b) private(c)
!$acc end serial

! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref<!fir.array<10x10xf32>>) private(@privatization_10x10xf32 -> %[[A]] : !fir.ref<!fir.array<10x10xf32>>, @privatization_10x10xf32 -> %[[C]] : !fir.ref<!fir.array<10x10xf32>>) {
! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref<!fir.array<10x10xf32>>) private(@privatization_ref_10x10xf32 -> %[[A]] : !fir.ref<!fir.array<10x10xf32>>, @privatization_ref_10x10xf32 -> %[[C]] : !fir.ref<!fir.array<10x10xf32>>) {
! CHECK: acc.yield
! CHECK-NEXT: }{{$}}

Expand Down
4 changes: 4 additions & 0 deletions flang/unittests/Optimizer/FIRTypesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ TEST_F(FIRTypesTest, updateTypeForUnlimitedPolymorphic) {
TEST_F(FIRTypesTest, getTypeAsString) {
EXPECT_EQ("i32",
fir::getTypeAsString(mlir::IntegerType::get(&context, 32), *kindMap));
EXPECT_EQ("ref_i32",
fir::getTypeAsString(
fir::ReferenceType::get(mlir::IntegerType::get(&context, 32)),
*kindMap));
EXPECT_EQ(
"f64", fir::getTypeAsString(mlir::FloatType::getF64(&context), *kindMap));
EXPECT_EQ(
Expand Down

0 comments on commit 6e3dcd3

Please sign in to comment.