[flang-commits] [flang] 2bcbcbe - [flang] Enhance getTypeAsString to support more FIR types
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Wed Jun 21 15:33:33 PDT 2023
Author: Valentin Clement
Date: 2023-06-21T15:33:27-07:00
New Revision: 2bcbcbefcd0f7432f99cc07bb47d1e1ecb579a3f
URL: https://github.com/llvm/llvm-project/commit/2bcbcbefcd0f7432f99cc07bb47d1e1ecb579a3f
DIFF: https://github.com/llvm/llvm-project/commit/2bcbcbefcd0f7432f99cc07bb47d1e1ecb579a3f.diff
LOG: [flang] Enhance getTypeAsString to support more FIR types
Add support for couple of FIR types such as fir.ptr, fir.heap,
fir.box, fir.class
Reviewed By: razvanlupusoru
Differential Revision: https://reviews.llvm.org/D153461
Added:
Modified:
flang/lib/Optimizer/Dialect/FIRType.cpp
flang/unittests/Optimizer/FIRTypesTest.cpp
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 9e1a1f613d50e..7fb3c56321cd7 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -508,6 +508,9 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
llvm::report_fatal_error("unsupported type");
}
break;
+ } else if (mlir::isa<mlir::NoneType>(ty)) {
+ name << "none";
+ break;
} else if (auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(ty)) {
name << 'c' << kindMap.getCharacterBitsize(charTy.getFKind());
if (charTy.getLen() != fir::CharacterType::singleton())
@@ -520,8 +523,20 @@ std::string getTypeAsString(mlir::Type ty, const fir::KindMapping &kindMap,
} else if (auto refTy = mlir::dyn_cast_or_null<fir::ReferenceType>(ty)) {
name << "ref_";
ty = refTy.getEleTy();
+ } else if (auto ptrTy = mlir::dyn_cast_or_null<fir::PointerType>(ty)) {
+ name << "ptr_";
+ ty = ptrTy.getEleTy();
+ } else if (auto heapTy = mlir::dyn_cast_or_null<fir::HeapType>(ty)) {
+ name << "heap_";
+ ty = heapTy.getEleTy();
+ } else if (auto classTy = mlir::dyn_cast_or_null<fir::ClassType>(ty)) {
+ name << "class_";
+ ty = classTy.getEleTy();
+ } else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(ty)) {
+ name << "box_";
+ ty = boxTy.getEleTy();
} else {
- // TODO: add support for RecordType/BaseBoxType
+ // TODO: add support for RecordType
llvm::report_fatal_error("unsupported type");
}
}
diff --git a/flang/unittests/Optimizer/FIRTypesTest.cpp b/flang/unittests/Optimizer/FIRTypesTest.cpp
index 9200301ed3b72..a006eeffd8f70 100644
--- a/flang/unittests/Optimizer/FIRTypesTest.cpp
+++ b/flang/unittests/Optimizer/FIRTypesTest.cpp
@@ -283,4 +283,20 @@ TEST_F(FIRTypesTest, getTypeAsString) {
EXPECT_EQ("10x20xi64", fir::getTypeAsString(arrTy, *kindMap));
EXPECT_EQ(
"idx", fir::getTypeAsString(mlir::IndexType::get(&context), *kindMap));
+ EXPECT_EQ("ptr_i32",
+ fir::getTypeAsString(
+ fir::PointerType::get(mlir::IntegerType::get(&context, 32)),
+ *kindMap));
+ EXPECT_EQ("heap_i32",
+ fir::getTypeAsString(
+ fir::HeapType::get(mlir::IntegerType::get(&context, 32)), *kindMap));
+ EXPECT_EQ("box_i32",
+ fir::getTypeAsString(
+ fir::BoxType::get(mlir::IntegerType::get(&context, 32)), *kindMap));
+ EXPECT_EQ("class_i32",
+ fir::getTypeAsString(
+ fir::ClassType::get(mlir::IntegerType::get(&context, 32)), *kindMap));
+ EXPECT_EQ("class_none",
+ fir::getTypeAsString(
+ fir::ClassType::get(mlir::NoneType::get(&context)), *kindMap));
}
More information about the flang-commits
mailing list