[PATCH] D113405: [fir] Add !fir.logical type conversion

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 8 08:55:08 PST 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG59a4bbe26cfb: [fir] Add !fir.logical type conversion (authored by clementval).

Changed prior to commit:
  https://reviews.llvm.org/D113405?vs=385504&id=385520#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113405/new/

https://reviews.llvm.org/D113405

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
@@ -48,3 +48,27 @@
 func private @foo3(%arg0: !fir.box<!fir.type<derived{f:f32}>>)
 // CHECK-LABEL: foo3
 // CHECK-SAME: !llvm.ptr<struct<(ptr<struct<"derived", (f32)>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>
+
+// -----
+
+// Test `!fir.logical<KIND>` 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
+
+func private @foo4(%arg0: !fir.logical<16>)
+// CHECK-LABEL: foo4
+// CHECK-SAME: i128
Index: flang/lib/Optimizer/CodeGen/TypeConverter.h
===================================================================
--- flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113405.385520.patch
Type: text/x-patch
Size: 2364 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211108/ddf82070/attachment.bin>


More information about the llvm-commits mailing list