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 @@ -54,6 +54,8 @@ LLVM_DEBUG(llvm::dbgs() << "type convert: " << boxchar << '\n'); return convertType(specifics->boxcharMemoryType(boxchar.getEleTy())); }); + addConversion( + [&](BoxProcType boxproc) { return convertBoxProcType(boxproc); }); addConversion( [&](fir::CharacterType charTy) { return convertCharType(charTy); }); addConversion([&](HeapType heap) { return convertPointerLike(heap); }); @@ -197,6 +199,17 @@ /*isPacked=*/false)); } + // fir.boxproc --> llvm<"{ any*, i8* }"> + mlir::Type convertBoxProcType(BoxProcType boxproc) { + auto funcTy = convertType(boxproc.getEleTy()); + auto ptrTy = mlir::LLVM::LLVMPointerType::get(funcTy); + auto i8PtrTy = mlir::LLVM::LLVMPointerType::get( + mlir::IntegerType::get(&getContext(), 8)); + llvm::SmallVector tuple = {ptrTy, i8PtrTy}; + return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), tuple, + /*isPacked=*/false); + } + unsigned characterBitsize(fir::CharacterType charTy) { return kindMapping.getCharacterBitsize(charTy.getFKind()); } 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 @@ -70,6 +70,25 @@ // ----- +// Test !fir.boxproc type + +// proc takes in no argument and returns nothing +func private @foo0(%arg0: !fir.boxproc<() -> ()>) +// CHECK-LABEL: foo0 +// CHECK-SAME: !llvm.struct<(ptr>>, ptr)> + +// proc takes in two arguments and returns one argument +func private @foo1(%arg0: !fir.boxproc<(i32, i32) -> i64>) +// CHECK-LABEL: foo1 +// CHECK-SAME: !llvm.struct<(ptr>>, ptr)> + +// proc takes in a box argument and returns nothing +func private @f002(%arg0: !fir.boxproc<(!fir.box>) -> ()>) +// CHECK-LABEL: f002 +// CHECK-SAME: !llvm.struct<(ptr>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr, array<1 x i{{.*}}>)>>)>>>, ptr)> + +// ----- + // Test char types `!fir.char` func private @foo0(%arg0: !fir.char<1, 4>, %arg1: !fir.char<1, ?>)