Skip to content

Commit

Permalink
[Flang] Add type conversion for FIR integer kind
Browse files Browse the repository at this point in the history
Convert fir.int<kind> to their llvm equivalent type

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: clementval, awarzynski

Differential Revision: https://reviews.llvm.org/D113660

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
  • Loading branch information
kiranchandramohan and schweitzpgi committed Nov 12, 2021
1 parent bb49346 commit aa26119
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flang/lib/Optimizer/CodeGen/TypeConverter.h
Expand Up @@ -57,6 +57,10 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
addConversion(
[&](fir::CharacterType charTy) { return convertCharType(charTy); });
addConversion([&](HeapType heap) { return convertPointerLike(heap); });
addConversion([&](fir::IntegerType intTy) {
return mlir::IntegerType::get(
&getContext(), kindMapping.getIntegerBitsize(intTy.getFKind()));
});
addConversion([&](fir::LogicalType boolTy) {
return mlir::IntegerType::get(
&getContext(), kindMapping.getLogicalBitsize(boolTy.getFKind()));
Expand Down
24 changes: 24 additions & 0 deletions flang/test/Fir/types-to-llvm.fir
Expand Up @@ -128,6 +128,30 @@ func private @foo8(%arg0: !fir.heap<!fir.type<_QMalloc_assignTt{i:i32}>>)

// -----

// Test `!fir.integer<KIND>` conversion.

func private @foo0(%arg0: !fir.int<1>)
// CHECK-LABEL: foo0
// CHECK-SAME: i8

func private @foo1(%arg0: !fir.int<2>)
// CHECK-LABEL: foo1
// CHECK-SAME: i16

func private @foo2(%arg0: !fir.int<4>)
// CHECK-LABEL: foo2
// CHECK-SAME: i32

func private @foo3(%arg0: !fir.int<8>)
// CHECK-LABEL: foo3
// CHECK-SAME: i64

func private @foo4(%arg0: !fir.int<16>)
// CHECK-LABEL: foo4
// CHECK-SAME: i128

// -----

// Test `!fir.logical<KIND>` conversion.

func private @foo0(%arg0: !fir.logical<1>)
Expand Down

0 comments on commit aa26119

Please sign in to comment.