-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Add option to skip struct argument rewrite in target-rewrite #75939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Be consistent with complex and character rewrite so that the pass can be run selectively.
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-flang-codegen Author: None (jeanPerier) ChangesBe consistent with complex and character rewrite so that the pass can be run selectively. Full diff: https://github.com/llvm/llvm-project/pull/75939.diff 4 Files Affected:
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}>) -> ()
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you, Jean!
Be consistent with complex and character rewrite so that the pass can be run selectively.