[flang-commits] [PATCH] D154072: [flang] Support CHARACTER(4) pointer targets

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Jun 29 09:37:36 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG51a346815027: [flang] Support CHARACTER(4) pointer targets (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154072

Files:
  flang/lib/Optimizer/CodeGen/CodeGen.cpp
  flang/test/Fir/rebox-global.fir


Index: flang/test/Fir/rebox-global.fir
===================================================================
--- flang/test/Fir/rebox-global.fir
+++ flang/test/Fir/rebox-global.fir
@@ -10,3 +10,14 @@
   fir.has_value %2 : !fir.box<!fir.ptr<i32>>
 }
 // CHECK: @p = global { ptr, i64, i32, i8, i8, i8, i8 } { ptr @x, {{.*}}, i32 {{.*}}, i8 0, i8 9, i8 1, i8 0 }
+
+// Test that sdiv is not generated inside fir.global.
+fir.global @char4 target : !fir.char<4,10>
+fir.global @pointer_char4_init : !fir.box<!fir.ptr<!fir.char<4,10>>> {
+  %0 = fir.address_of(@char4) : !fir.ref<!fir.char<4,10>>
+  %1 = fir.embox %0 : (!fir.ref<!fir.char<4,10>>) -> !fir.box<!fir.char<4,10>>
+  %2 = fircg.ext_rebox %1 : (!fir.box<!fir.char<4,10>>) -> !fir.box<!fir.ptr<!fir.char<4,10>>>
+  fir.has_value %2 : !fir.box<!fir.ptr<!fir.char<4,10>>>
+}
+// CHECK-LABEL: @pointer_char4_init
+// CHECK-SAME: { ptr @char4, i64 ptrtoint (ptr getelementptr ([10 x i32], ptr null, i32 1) to i64), i32 20180515, i8 0, i8 44, i8 1, i8 0 }
Index: flang/lib/Optimizer/CodeGen/CodeGen.cpp
===================================================================
--- flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -1894,14 +1894,22 @@
     llvm::SmallVector<mlir::Value, 2> lenParams;
     mlir::Type inputEleTy = getInputEleTy(rebox);
     if (auto charTy = inputEleTy.dyn_cast<fir::CharacterType>()) {
-      mlir::Value len = getElementSizeFromBox(
-          loc, idxTy, rebox.getBox().getType(), loweredBox, rewriter);
-      if (charTy.getFKind() != 1) {
-        mlir::Value width =
-            genConstantIndex(loc, idxTy, rewriter, charTy.getFKind());
-        len = rewriter.create<mlir::LLVM::SDivOp>(loc, idxTy, len, width);
+      if (charTy.hasConstantLen()) {
+        mlir::Value len =
+            genConstantIndex(loc, idxTy, rewriter, charTy.getLen());
+        lenParams.emplace_back(len);
+      } else {
+        mlir::Value len = getElementSizeFromBox(
+            loc, idxTy, rebox.getBox().getType(), loweredBox, rewriter);
+        if (charTy.getFKind() != 1) {
+          assert(!isInGlobalOp(rewriter) &&
+                 "character target in global op must have constant length");
+          mlir::Value width =
+              genConstantIndex(loc, idxTy, rewriter, charTy.getFKind());
+          len = rewriter.create<mlir::LLVM::SDivOp>(loc, idxTy, len, width);
+        }
+        lenParams.emplace_back(len);
       }
-      lenParams.emplace_back(len);
     } else if (auto recTy = inputEleTy.dyn_cast<fir::RecordType>()) {
       if (recTy.getNumLenParams() != 0)
         TODO(loc, "reboxing descriptor of derived type with length parameters");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154072.535853.patch
Type: text/x-patch
Size: 2682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230629/77279b1b/attachment-0001.bin>


More information about the flang-commits mailing list