diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h --- a/flang/include/flang/Optimizer/Dialect/FIRType.h +++ b/flang/include/flang/Optimizer/Dialect/FIRType.h @@ -416,11 +416,10 @@ return fir::unwrapRefType(t).isa(); } -/// 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 +/// fir.ref -> prefix_ref_i32 std::string getTypeAsString(mlir::Type ty, const KindMapping &kindMap, llvm::StringRef prefix = ""); diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -486,7 +486,6 @@ name << prefix.str(); if (!prefix.empty()) name << "_"; - ty = fir::unwrapRefType(ty); while (ty) { if (fir::isa_trivial(ty)) { if (mlir::isa(ty)) { @@ -518,6 +517,9 @@ for (auto extent : seqTy.getShape()) name << extent << 'x'; ty = seqTy.getEleTy(); + } else if (auto refTy = mlir::dyn_cast_or_null(ty)) { + name << "ref_"; + ty = refTy.getEleTy(); } else { // TODO: add support for RecordType/BaseBoxType llvm::report_fatal_error("unsupported type"); diff --git a/flang/test/Lower/OpenACC/acc-loop.f90 b/flang/test/Lower/OpenACC/acc-loop.f90 --- a/flang/test/Lower/OpenACC/acc-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-loop.f90 @@ -2,7 +2,7 @@ ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s -! CHECK-LABEL: acc.private.recipe @privatization_10x10xf32 : !fir.ref> init { +! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: acc.yield %{{.*}} : !fir.ref> ! CHECK: } @@ -159,7 +159,7 @@ a(i) = b(i) END DO -!CHECK: acc.loop private(@privatization_10x10xf32 -> %{{.*}} : !fir.ref>) { +!CHECK: acc.loop private(@privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref>) { !CHECK: fir.do_loop !CHECK: acc.yield !CHECK-NEXT: }{{$}} @@ -169,7 +169,7 @@ a(i) = b(i) END DO -!CHECK: acc.loop private(@privatization_10x10xf32 -> %{{.*}} : !fir.ref>, @privatization_10x10xf32 -> %{{.*}} : !fir.ref>) { +!CHECK: acc.loop private(@privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref>) { !CHECK: fir.do_loop !CHECK: acc.yield !CHECK-NEXT: }{{$}} @@ -179,7 +179,7 @@ a(i) = b(i) END DO -!CHECK: acc.loop private(@privatization_10x10xf32 -> %{{.*}} : !fir.ref>, @privatization_10x10xf32 -> %{{.*}} : !fir.ref>) { +!CHECK: acc.loop private(@privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref>, @privatization_ref_10x10xf32 -> %{{.*}} : !fir.ref>) { !CHECK: fir.do_loop !CHECK: acc.yield !CHECK-NEXT: }{{$}} diff --git a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 --- a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel-loop.f90 @@ -2,7 +2,7 @@ ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s -! CHECK-LABEL: acc.private.recipe @privatization_10xf32 : !fir.ref> init { +! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: acc.yield %{{.*}} : !fir.ref> ! CHECK: } @@ -454,8 +454,8 @@ a(i) = b(i) END DO -! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref>) private(@privatization_10xf32 -> %[[A]] : !fir.ref>) { -! CHECK: acc.loop private(@privatization_10xf32 -> %[[A]] : !fir.ref>) { +! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref>) private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref>) { +! CHECK: acc.loop private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref>) { ! CHECK: fir.do_loop ! CHECK: acc.yield ! CHECK-NEXT: }{{$}} diff --git a/flang/test/Lower/OpenACC/acc-parallel.f90 b/flang/test/Lower/OpenACC/acc-parallel.f90 --- a/flang/test/Lower/OpenACC/acc-parallel.f90 +++ b/flang/test/Lower/OpenACC/acc-parallel.f90 @@ -2,7 +2,7 @@ ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s -! CHECK-LABEL: acc.private.recipe @privatization_10x10xf32 : !fir.ref> init { +! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: acc.yield %{{.*}} : !fir.ref> ! CHECK: } @@ -298,7 +298,7 @@ !$acc parallel private(a) firstprivate(b) private(c) !$acc end parallel -! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref>) private(@privatization_10x10xf32 -> %[[A]] : !fir.ref>, @privatization_10x10xf32 -> %[[C]] : !fir.ref>) { +! CHECK: acc.parallel firstprivate(%[[B]] : !fir.ref>) private(@privatization_ref_10x10xf32 -> %[[A]] : !fir.ref>, @privatization_ref_10x10xf32 -> %[[C]] : !fir.ref>) { ! CHECK: acc.yield ! CHECK-NEXT: }{{$}} diff --git a/flang/test/Lower/OpenACC/acc-serial-loop.f90 b/flang/test/Lower/OpenACC/acc-serial-loop.f90 --- a/flang/test/Lower/OpenACC/acc-serial-loop.f90 +++ b/flang/test/Lower/OpenACC/acc-serial-loop.f90 @@ -2,7 +2,7 @@ ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s -! CHECK-LABEL: acc.private.recipe @privatization_10xf32 : !fir.ref> init { +! CHECK-LABEL: acc.private.recipe @privatization_ref_10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: acc.yield %{{.*}} : !fir.ref> ! CHECK: } @@ -370,8 +370,8 @@ a(i) = b(i) END DO -! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref>) private(@privatization_10xf32 -> %[[A]] : !fir.ref>) { -! CHECK: acc.loop private(@privatization_10xf32 -> %[[A]] : !fir.ref>) { +! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref>) private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref>) { +! CHECK: acc.loop private(@privatization_ref_10xf32 -> %[[A]] : !fir.ref>) { ! CHECK: fir.do_loop ! CHECK: acc.yield ! CHECK-NEXT: }{{$}} diff --git a/flang/test/Lower/OpenACC/acc-serial.f90 b/flang/test/Lower/OpenACC/acc-serial.f90 --- a/flang/test/Lower/OpenACC/acc-serial.f90 +++ b/flang/test/Lower/OpenACC/acc-serial.f90 @@ -2,7 +2,7 @@ ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s -! CHECK-LABEL: acc.private.recipe @privatization_10x10xf32 : !fir.ref> init { +! CHECK-LABEL: acc.private.recipe @privatization_ref_10x10xf32 : !fir.ref> init { ! CHECK: ^bb0(%{{.*}}: !fir.ref>): ! CHECK: acc.yield %{{.*}} : !fir.ref> ! CHECK: } @@ -241,7 +241,7 @@ !$acc serial private(a) firstprivate(b) private(c) !$acc end serial -! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref>) private(@privatization_10x10xf32 -> %[[A]] : !fir.ref>, @privatization_10x10xf32 -> %[[C]] : !fir.ref>) { +! CHECK: acc.serial firstprivate(%[[B]] : !fir.ref>) private(@privatization_ref_10x10xf32 -> %[[A]] : !fir.ref>, @privatization_ref_10x10xf32 -> %[[C]] : !fir.ref>) { ! CHECK: acc.yield ! CHECK-NEXT: }{{$}} diff --git a/flang/unittests/Optimizer/FIRTypesTest.cpp b/flang/unittests/Optimizer/FIRTypesTest.cpp --- a/flang/unittests/Optimizer/FIRTypesTest.cpp +++ b/flang/unittests/Optimizer/FIRTypesTest.cpp @@ -263,6 +263,10 @@ 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(