[flang-commits] [flang] 36a073a - [flang] Add option to skip struct argument rewrite in target-rewrite (#75939)

via flang-commits flang-commits at lists.llvm.org
Wed Dec 20 01:15:12 PST 2023


Author: jeanPerier
Date: 2023-12-20T10:15:09+01:00
New Revision: 36a073a5f45e0da3b84bd5284219d64586a97d5d

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

LOG: [flang] Add option to skip struct argument rewrite in target-rewrite (#75939)

Be consistent with complex and character rewrite so that the pass can be
run selectively.

Added: 
    flang/test/Fir/target-rewrite-selective-no-struct.fir

Modified: 
    flang/include/flang/Optimizer/CodeGen/CGPasses.td
    flang/include/flang/Optimizer/CodeGen/CodeGen.h
    flang/lib/Optimizer/CodeGen/TargetRewrite.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/CodeGen/CGPasses.td b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
index 5e47119582776a..0d20a669a15a1f 100644
--- a/flang/include/flang/Optimizer/CodeGen/CGPasses.td
+++ b/flang/include/flang/Optimizer/CodeGen/CGPasses.td
@@ -63,7 +63,10 @@ def TargetRewritePass : Pass<"target-rewrite", "mlir::ModuleOp"> {
            "Disable target-specific conversion of CHARACTER.">,
     Option<"noComplexConversion", "no-complex-conversion",
            "bool", /*default=*/"false",
-           "Disable target-specific conversion of COMPLEX.">
+           "Disable target-specific conversion of COMPLEX.">,
+    Option<"noStructConversion", "no-struct-conversion",
+           "bool", /*default=*/"false",
+           "Disable target-specific conversion of derived type value.">
   ];
 }
 

diff  --git a/flang/include/flang/Optimizer/CodeGen/CodeGen.h b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
index 7d8e548d89a18b..5ea96c900bc630 100644
--- a/flang/include/flang/Optimizer/CodeGen/CodeGen.h
+++ b/flang/include/flang/Optimizer/CodeGen/CodeGen.h
@@ -34,6 +34,7 @@ std::unique_ptr<mlir::Pass> createFirCodeGenRewritePass();
 struct TargetRewriteOptions {
   bool noCharacterConversion{};
   bool noComplexConversion{};
+  bool noStructConversion{};
 };
 
 /// Prerequiste pass for code gen. Perform intermediate rewrites to tailor the

diff  --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
index 277f3e447ed164..2f5c8cc0071ae1 100644
--- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
+++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp
@@ -79,6 +79,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
   TargetRewrite(const fir::TargetRewriteOptions &options) {
     noCharacterConversion = options.noCharacterConversion;
     noComplexConversion = options.noComplexConversion;
+    noStructConversion = options.noStructConversion;
   }
 
   void runOnOperation() override final {
@@ -252,6 +253,11 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
       fir::CodeGenSpecifics::Marshalling &newInTyAndAttrs,
       llvm::SmallVectorImpl<mlir::Value> &newOpers,
       mlir::Value &savedStackPtr) {
+    if (noStructConversion) {
+      newInTyAndAttrs.push_back(fir::CodeGenSpecifics::getTypeAndAttr(recTy));
+      newOpers.push_back(oper);
+      return;
+    }
     auto structArgs =
         specifics->structArgumentType(loc, recTy, newInTyAndAttrs);
     if (structArgs.size() != 1)
@@ -522,6 +528,10 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
   void
   lowerStructSignatureArg(mlir::Location loc, fir::RecordType recTy,
                           fir::CodeGenSpecifics::Marshalling &newInTyAndAttrs) {
+    if (noStructConversion) {
+      newInTyAndAttrs.push_back(fir::CodeGenSpecifics::getTypeAndAttr(recTy));
+      return;
+    }
     auto structArgs =
         specifics->structArgumentType(loc, recTy, newInTyAndAttrs);
     newInTyAndAttrs.insert(newInTyAndAttrs.end(), structArgs.begin(),
@@ -645,7 +655,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
            !noCharacterConversion) ||
           (fir::isa_complex(ty) && !noComplexConversion) ||
           (ty.isa<mlir::IntegerType>() && hasCCallingConv) ||
-          ty.isa<fir::RecordType>()) {
+          (ty.isa<fir::RecordType>() && !noStructConversion)) {
         LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n");
         return false;
       }
@@ -1128,6 +1138,10 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
   void doStructArg(mlir::func::FuncOp func, fir::RecordType recTy,
                    fir::CodeGenSpecifics::Marshalling &newInTyAndAttrs,
                    FIXUPS &fixups) {
+    if (noStructConversion) {
+      newInTyAndAttrs.push_back(fir::CodeGenSpecifics::getTypeAndAttr(recTy));
+      return;
+    }
     auto structArgs =
         specifics->structArgumentType(func.getLoc(), recTy, newInTyAndAttrs);
     createFuncOpArgFixups(func, newInTyAndAttrs, structArgs, fixups);

diff  --git a/flang/test/Fir/target-rewrite-selective-no-struct.fir b/flang/test/Fir/target-rewrite-selective-no-struct.fir
new file mode 100644
index 00000000000000..ea3fa3319caabd
--- /dev/null
+++ b/flang/test/Fir/target-rewrite-selective-no-struct.fir
@@ -0,0 +1,25 @@
+// Test no-struct-conversion of target-rewrite pass.
+// RUN: fir-opt -target-rewrite="no-struct-conversion" %s | FileCheck %s
+
+func.func @test(%arg0: !fir.type<t{i:i32}>) {
+  return
+}
+
+func.func @test_call(%arg0: !fir.type<t{i:i32}>) {
+  fir.call @test(%arg0) : (!fir.type<t{i:i32}>) -> ()
+  return
+}
+
+func.func @test_addr_off() {
+  %0 = fir.address_of(@test) : (!fir.type<t{i:i32}>) -> ()
+  return
+}
+
+// CHECK-LABEL:  func.func @test(%{{.*}}: !fir.type<t{i:i32}>) {
+
+// CHECK-LABEL:  func.func @test_call(
+// CHECK-SAME:                        %[[ARG0:.*]]: !fir.type<t{i:i32}>) {
+// CHECK:    fir.call @test(%[[ARG0]]) : (!fir.type<t{i:i32}>) -> ()
+
+// CHECK-LABEL:  func.func @test_addr_off() {
+// CHECK:    fir.address_of(@test) : (!fir.type<t{i:i32}>) -> ()


        


More information about the flang-commits mailing list