diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -15,6 +15,8 @@ #include "DescriptorModel.h" #include "flang/Lower/Todo.h" // remove when TODO's are done +#include "flang/Optimizer/Support/FIRContext.h" +#include "flang/Optimizer/Support/KindMapping.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/Debug.h" @@ -25,11 +27,16 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter { public: LLVMTypeConverter(mlir::ModuleOp module) - : mlir::LLVMTypeConverter(module.getContext()) { + : mlir::LLVMTypeConverter(module.getContext()), + kindMapping(getKindMapping(module)) { LLVM_DEBUG(llvm::dbgs() << "FIR type converter\n"); // Each conversion should return a value of type mlir::Type. addConversion([&](BoxType box) { return convertBoxType(box); }); + addConversion([&](fir::LogicalType boolTy) { + return mlir::IntegerType::get( + &getContext(), kindMapping.getLogicalBitsize(boolTy.getFKind())); + }); addConversion( [&](fir::RecordType derived) { return convertRecordType(derived); }); addConversion( @@ -179,6 +186,9 @@ } return mlir::LLVM::LLVMPointerType::get(baseTy); } + +private: + KindMapping kindMapping; }; } // namespace fir diff --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir --- a/flang/test/Fir/types-to-llvm.fir +++ b/flang/test/Fir/types-to-llvm.fir @@ -48,3 +48,23 @@ func private @foo3(%arg0: !fir.box>) // CHECK-LABEL: foo3 // CHECK-SAME: !llvm.ptr>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i{{.*}}>)>> + +// ----- + +// Test `!fir.logical` conversion. + +func private @foo0(%arg0: !fir.logical<1>) +// CHECK-LABEL: foo0 +// CHECK-SAME: i8 + +func private @foo1(%arg0: !fir.logical<2>) +// CHECK-LABEL: foo1 +// CHECK-SAME: i16 + +func private @foo2(%arg0: !fir.logical<4>) +// CHECK-LABEL: foo2 +// CHECK-SAME: i32 + +func private @foo3(%arg0: !fir.logical<8>) +// CHECK-LABEL: foo3 +// CHECK-SAME: i64