[flang-commits] [flang] 59a4bbe - [fir] Add !fir.logical type conversion
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Mon Nov 8 08:55:07 PST 2021
Author: Valentin Clement
Date: 2021-11-08T17:54:55+01:00
New Revision: 59a4bbe26cfb11aca11f3992f138f86d43acb8c1
URL: https://github.com/llvm/llvm-project/commit/59a4bbe26cfb11aca11f3992f138f86d43acb8c1
DIFF: https://github.com/llvm/llvm-project/commit/59a4bbe26cfb11aca11f3992f138f86d43acb8c1.diff
LOG: [fir] Add !fir.logical type conversion
Add conversion from !fir.logical types to LLVM IR Dialect types.
This patch is part of the upstreaming effort from fir-dev branch.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D113405
Co-authored-by: Jean Perier <jperier at nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>
Added:
Modified:
flang/lib/Optimizer/CodeGen/TypeConverter.h
flang/test/Fir/types-to-llvm.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h
index 9067af7dd99b..f8d651808b02 100644
--- 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 @@ namespace fir {
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 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
}
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
index 8ddee11f3b9d..409e6dae043c 100644
--- a/flang/test/Fir/types-to-llvm.fir
+++ b/flang/test/Fir/types-to-llvm.fir
@@ -48,3 +48,27 @@ func private @foo2(%arg0: !fir.box<!fir.ref<i64>>)
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
More information about the flang-commits
mailing list