[flang-commits] [flang] 6e3dcd3 - [flang] Do not omit fir.ref in getTypeAsString
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue May 23 15:07:46 PDT 2023
Author: Valentin Clement
Date: 2023-05-23T15:07:40-07:00
New Revision: 6e3dcd350d990947ecbb3f03b17c95181bdad529
URL: https://github.com/llvm/llvm-project/commit/6e3dcd350d990947ecbb3f03b17c95181bdad529
DIFF: https://github.com/llvm/llvm-project/commit/6e3dcd350d990947ecbb3f03b17c95181bdad529.diff
LOG: [flang] Do not omit fir.ref in getTypeAsString
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
Added:
Modified:
flang/include/flang/Optimizer/Dialect/FIRType.h
flang/lib/Optimizer/Dialect/FIRType.cpp
flang/test/Lower/OpenACC/acc-loop.f90
flang/test/Lower/OpenACC/acc-parallel-loop.f90
flang/test/Lower/OpenACC/acc-parallel.f90
flang/test/Lower/OpenACC/acc-serial-loop.f90
flang/test/Lower/OpenACC/acc-serial.f90
flang/unittests/Optimizer/FIRTypesTest.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index 5749cdcab46bd..e91d6015aebbd 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -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 = "");
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index f36436ec5bc34..efd74e09661c8 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -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)) {
@@ -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");
diff --git a/flang/test/Lower/OpenACC/acc-loop.f90 b/flang/test/Lower/OpenACC/acc-loop.f90
index 30684f36a3f13..ec8eb0f73b74e 100644
--- 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<!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: }
@@ -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: }{{$}}
@@ -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: }{{$}}
@@ -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: }{{$}}
diff --git a/flang/test/Lower/OpenACC/acc-parallel-loop.f90 b/flang/test/Lower/OpenACC/acc-parallel-loop.f90
index 94fe5a89c9b3c..38df6228acc83 100644
--- 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<!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: }
@@ -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: }{{$}}
diff --git a/flang/test/Lower/OpenACC/acc-parallel.f90 b/flang/test/Lower/OpenACC/acc-parallel.f90
index 6d321bf12c4aa..d1c9d80c1fbb6 100644
--- 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<!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: }
@@ -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: }{{$}}
diff --git a/flang/test/Lower/OpenACC/acc-serial-loop.f90 b/flang/test/Lower/OpenACC/acc-serial-loop.f90
index 16d94f766d402..2e26da8bb2c63 100644
--- 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<!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: }
@@ -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: }{{$}}
diff --git a/flang/test/Lower/OpenACC/acc-serial.f90 b/flang/test/Lower/OpenACC/acc-serial.f90
index 6d3b45f246413..d10a3ab7a0c4f 100644
--- 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<!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: }
@@ -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: }{{$}}
diff --git a/flang/unittests/Optimizer/FIRTypesTest.cpp b/flang/unittests/Optimizer/FIRTypesTest.cpp
index 2e08d8a759b01..9200301ed3b72 100644
--- a/flang/unittests/Optimizer/FIRTypesTest.cpp
+++ b/flang/unittests/Optimizer/FIRTypesTest.cpp
@@ -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(
More information about the flang-commits
mailing list