Skip to content

Commit

Permalink
[flang] Enhance getTypeAsString to support more FIR types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
clementval committed Jun 21, 2023
1 parent 8e85739 commit 2bcbcbe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
17 changes: 16 additions & 1 deletion flang/lib/Optimizer/Dialect/FIRType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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");
}
}
Expand Down
16 changes: 16 additions & 0 deletions flang/unittests/Optimizer/FIRTypesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 2bcbcbe

Please sign in to comment.