[flang-commits] [flang] bb20182 - [flang][codegen] Add type conversion for `fir.boxchar`

Andrzej Warzynski via flang-commits flang-commits at lists.llvm.org
Thu Nov 11 02:30:15 PST 2021


Author: Andrzej Warzynski
Date: 2021-11-11T10:28:40Z
New Revision: bb2018261e8000828144e91ffd11153ba2a12a16

URL: https://github.com/llvm/llvm-project/commit/bb2018261e8000828144e91ffd11153ba2a12a16
DIFF: https://github.com/llvm/llvm-project/commit/bb2018261e8000828144e91ffd11153ba2a12a16.diff

LOG: [flang][codegen] Add type conversion for `fir.boxchar`

This is part of the upstreaming effort from the `fir-dev` branch in [1].

[1] https://github.com/flang-compiler/f18-llvm-project

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

Patch originally written by:
Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>
Co-authored-by: Jean Perier <jperier at nvidia.com>

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp
index 0541de2ddf7b..70652406c2c4 100644
--- a/flang/lib/Optimizer/CodeGen/Target.cpp
+++ b/flang/lib/Optimizer/CodeGen/Target.cpp
@@ -42,6 +42,14 @@ struct GenericTarget : public CodeGenSpecifics {
     return mlir::TupleType::get(eleTy.getContext(), range);
   }
 
+  mlir::Type boxcharMemoryType(mlir::Type eleTy) const override {
+    auto idxTy = mlir::IntegerType::get(eleTy.getContext(), S::defaultWidth);
+    auto ptrTy = fir::ReferenceType::get(eleTy);
+    // { t*, index }
+    mlir::TypeRange range = {ptrTy, idxTy};
+    return mlir::TupleType::get(eleTy.getContext(), range);
+  }
+
   Marshalling boxcharArgumentType(mlir::Type eleTy, bool sret) const override {
     CodeGenSpecifics::Marshalling marshal;
     auto idxTy = mlir::IntegerType::get(eleTy.getContext(), S::defaultWidth);

diff  --git a/flang/lib/Optimizer/CodeGen/Target.h b/flang/lib/Optimizer/CodeGen/Target.h
index af4004ce7370..f6996fcd1bcb 100644
--- a/flang/lib/Optimizer/CodeGen/Target.h
+++ b/flang/lib/Optimizer/CodeGen/Target.h
@@ -77,6 +77,9 @@ class CodeGenSpecifics {
   /// value may need to be converted to a hidden reference argument.
   virtual Marshalling complexReturnType(mlir::Type eleTy) const = 0;
 
+  /// Type presentation of a `boxchar<n>` type value in memory.
+  virtual mlir::Type boxcharMemoryType(mlir::Type eleTy) const = 0;
+
   /// Type representation of a `boxchar<n>` type argument when passed by value.
   /// An argument value may need to be passed as a (safe) reference argument.
   ///

diff  --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h
index d35d20e61d7f..21e65a2f289e 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -50,6 +50,10 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
 
     // Each conversion should return a value of type mlir::Type.
     addConversion([&](BoxType box) { return convertBoxType(box); });
+    addConversion([&](BoxCharType boxchar) {
+      LLVM_DEBUG(llvm::dbgs() << "type convert: " << boxchar << '\n');
+      return convertType(specifics->boxcharMemoryType(boxchar.getEleTy()));
+    });
     addConversion(
         [&](fir::CharacterType charTy) { return convertCharType(charTy); });
     addConversion([&](fir::LogicalType boolTy) {

diff  --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir
index 97958e2eb7aa..6d6f1c652eac 100644
--- a/flang/test/Fir/types-to-llvm.fir
+++ b/flang/test/Fir/types-to-llvm.fir
@@ -203,3 +203,15 @@ func private @foo15(%arg0: !fir.vector<2:!fir.real<10>>)
 func private @foo16(%arg0: !fir.vector<2:!fir.real<16>>)
 // CHECK-LABEL: foo16
 // CHECK-SAME: vector<2xf128>
+
+// -----
+
+// Test `!fir.boxchar<n>` conversion
+
+func private @foo0(%arg0: !fir.boxchar<1>)
+// CHECK-LABEL: foo0
+// CHECK-SAME: !llvm.struct<(ptr<i8>, i64)>
+
+func private @foo1(%arg0: !fir.boxchar<2>)
+// CHECK-LABEL: foo1
+// CHECK-SAME: !llvm.struct<(ptr<i16>, i64)>


        


More information about the flang-commits mailing list