[PATCH] D113879: [Flang] Add the typeconversion to llvm for the FIR boxproc type

Kiran Chandramohan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 15 03:33:23 PST 2021


kiranchandramohan created this revision.
kiranchandramohan added reviewers: clementval, awarzynski, rovka, jeanPerier, schweitz, svedanayagam, AlexisPerry, pmccormick.
Herald added a subscriber: mehdi_amini.
Herald added a project: Flang.
kiranchandramohan requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

Converts the FIR boxproc to a struct that contains a pointer to
a function type and an i8 pointer type.

Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113879

Files:
  flang/lib/Optimizer/CodeGen/TypeConverter.h
  flang/test/Fir/types-to-llvm.fir


Index: flang/test/Fir/types-to-llvm.fir
===================================================================
--- flang/test/Fir/types-to-llvm.fir
+++ 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<func<void ()>>>, ptr<i8>)>
+
+// 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<func<i64 (i32, i32)>>>, ptr<i8>)>
+
+// proc takes in a box argument and returns nothing
+func private @f002(%arg0: !fir.boxproc<(!fir.box<!fir.type<derived3{f:f32}>>) -> ()>)
+// CHECK-LABEL: f002
+// CHECK-SAME: !llvm.struct<(ptr<ptr<func<void (ptr<struct<(ptr<struct<"derived3", (f32)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>)>>>, ptr<i8>)>
+
+// -----
+
 // Test char types `!fir.char<k, n>`
 
 func private @foo0(%arg0: !fir.char<1, 4>, %arg1: !fir.char<1, ?>)
Index: flang/lib/Optimizer/CodeGen/TypeConverter.h
===================================================================
--- flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ 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<any>  -->  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<mlir::Type, 2> tuple = {ptrTy, i8PtrTy};
+    return mlir::LLVM::LLVMStructType::getLiteral(&getContext(), tuple,
+                                                  /*isPacked=*/false);
+  }
+
   unsigned characterBitsize(fir::CharacterType charTy) {
     return kindMapping.getCharacterBitsize(charTy.getFKind());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113879.387194.patch
Type: text/x-patch
Size: 2557 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211115/445e9cec/attachment.bin>


More information about the llvm-commits mailing list