diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h index 38105e18e62ae..10a30bfd86a26 100644 --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -66,11 +66,22 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter { }); addConversion( [&](fir::CharacterType charTy) { return convertCharType(charTy); }); + addConversion( + [&](fir::ComplexType cmplx) { return convertComplexType(cmplx); }); + addConversion([&](fir::FieldType field) { + // Convert to i32 because of LLVM GEP indexing restriction. + return mlir::IntegerType::get(field.getContext(), 32); + }); addConversion([&](HeapType heap) { return convertPointerLike(heap); }); addConversion([&](fir::IntegerType intTy) { return mlir::IntegerType::get( &getContext(), kindMapping.getIntegerBitsize(intTy.getFKind())); }); + addConversion([&](fir::LenType field) { + // Get size of len paramter from the descriptor. + return getModel()( + &getContext()); + }); addConversion([&](fir::LogicalType boolTy) { return mlir::IntegerType::get( &getContext(), kindMapping.getLogicalBitsize(boolTy.getFKind())); @@ -80,21 +91,11 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter { }); addConversion( [&](fir::PointerType pointer) { return convertPointerLike(pointer); }); - addConversion([&](fir::RecordType derived, SmallVectorImpl &results, - ArrayRef callStack) { + addConversion([&](fir::RecordType derived, + SmallVectorImpl &results, + ArrayRef callStack) { return convertRecordType(derived, results, callStack); }); - addConversion([&](fir::FieldType field) { - // Convert to i32 because of LLVM GEP indexing restriction. - return mlir::IntegerType::get(field.getContext(), 32); - }); - addConversion([&](fir::LenType field) { - // Get size of len paramter from the descriptor. - return getModel()( - &getContext()); - }); - addConversion( - [&](fir::ComplexType cmplx) { return convertComplexType(cmplx); }); addConversion( [&](fir::RealType real) { return convertRealType(real.getFKind()); }); addConversion( @@ -134,8 +135,9 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter { // fir.type --> llvm<"%name = { ty... }"> llvm::Optional - convertRecordType(fir::RecordType derived, SmallVectorImpl &results, - ArrayRef callStack) { + convertRecordType(fir::RecordType derived, + SmallVectorImpl &results, + ArrayRef callStack) { auto name = derived.getName(); auto st = mlir::LLVM::LLVMStructType::getIdentified(&getContext(), name); if (llvm::count(callStack, derived) > 1) { @@ -269,12 +271,6 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter { return convertType(specifics->complexMemoryType(eleTy)); } - // convert a front-end kind value to either a std or LLVM IR dialect type - // fir.real --> llvm.anyfloat where anyfloat is a kind mapping - mlir::Type convertRealType(fir::KindTy kind) { - return fromRealTypeID(kindMapping.getRealTypeID(kind), kind); - } - template mlir::Type convertPointerLike(A &ty) { mlir::Type eleTy = ty.getEleTy(); @@ -302,6 +298,12 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter { return mlir::LLVM::LLVMPointerType::get(convertType(eleTy)); } + // convert a front-end kind value to either a std or LLVM IR dialect type + // fir.real --> llvm.anyfloat where anyfloat is a kind mapping + mlir::Type convertRealType(fir::KindTy kind) { + return fromRealTypeID(kindMapping.getRealTypeID(kind), kind); + } + // fir.array --> llvm<"[...[c x any]]"> mlir::Type convertSequenceType(SequenceType seq) { auto baseTy = convertType(seq.getEleTy());