Skip to content

Commit 36a073a

Browse files
authored
[flang] Add option to skip struct argument rewrite in target-rewrite (llvm#75939)
Be consistent with complex and character rewrite so that the pass can be run selectively.
1 parent 3b1f06e commit 36a073a

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

flang/include/flang/Optimizer/CodeGen/CGPasses.td

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ def TargetRewritePass : Pass<"target-rewrite", "mlir::ModuleOp"> {
6363
"Disable target-specific conversion of CHARACTER.">,
6464
Option<"noComplexConversion", "no-complex-conversion",
6565
"bool", /*default=*/"false",
66-
"Disable target-specific conversion of COMPLEX.">
66+
"Disable target-specific conversion of COMPLEX.">,
67+
Option<"noStructConversion", "no-struct-conversion",
68+
"bool", /*default=*/"false",
69+
"Disable target-specific conversion of derived type value.">
6770
];
6871
}
6972

flang/include/flang/Optimizer/CodeGen/CodeGen.h

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ std::unique_ptr<mlir::Pass> createFirCodeGenRewritePass();
3434
struct TargetRewriteOptions {
3535
bool noCharacterConversion{};
3636
bool noComplexConversion{};
37+
bool noStructConversion{};
3738
};
3839

3940
/// Prerequiste pass for code gen. Perform intermediate rewrites to tailor the

flang/lib/Optimizer/CodeGen/TargetRewrite.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
7979
TargetRewrite(const fir::TargetRewriteOptions &options) {
8080
noCharacterConversion = options.noCharacterConversion;
8181
noComplexConversion = options.noComplexConversion;
82+
noStructConversion = options.noStructConversion;
8283
}
8384

8485
void runOnOperation() override final {
@@ -252,6 +253,11 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
252253
fir::CodeGenSpecifics::Marshalling &newInTyAndAttrs,
253254
llvm::SmallVectorImpl<mlir::Value> &newOpers,
254255
mlir::Value &savedStackPtr) {
256+
if (noStructConversion) {
257+
newInTyAndAttrs.push_back(fir::CodeGenSpecifics::getTypeAndAttr(recTy));
258+
newOpers.push_back(oper);
259+
return;
260+
}
255261
auto structArgs =
256262
specifics->structArgumentType(loc, recTy, newInTyAndAttrs);
257263
if (structArgs.size() != 1)
@@ -522,6 +528,10 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
522528
void
523529
lowerStructSignatureArg(mlir::Location loc, fir::RecordType recTy,
524530
fir::CodeGenSpecifics::Marshalling &newInTyAndAttrs) {
531+
if (noStructConversion) {
532+
newInTyAndAttrs.push_back(fir::CodeGenSpecifics::getTypeAndAttr(recTy));
533+
return;
534+
}
525535
auto structArgs =
526536
specifics->structArgumentType(loc, recTy, newInTyAndAttrs);
527537
newInTyAndAttrs.insert(newInTyAndAttrs.end(), structArgs.begin(),
@@ -645,7 +655,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
645655
!noCharacterConversion) ||
646656
(fir::isa_complex(ty) && !noComplexConversion) ||
647657
(ty.isa<mlir::IntegerType>() && hasCCallingConv) ||
648-
ty.isa<fir::RecordType>()) {
658+
(ty.isa<fir::RecordType>() && !noStructConversion)) {
649659
LLVM_DEBUG(llvm::dbgs() << "rewrite " << signature << " for target\n");
650660
return false;
651661
}
@@ -1128,6 +1138,10 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
11281138
void doStructArg(mlir::func::FuncOp func, fir::RecordType recTy,
11291139
fir::CodeGenSpecifics::Marshalling &newInTyAndAttrs,
11301140
FIXUPS &fixups) {
1141+
if (noStructConversion) {
1142+
newInTyAndAttrs.push_back(fir::CodeGenSpecifics::getTypeAndAttr(recTy));
1143+
return;
1144+
}
11311145
auto structArgs =
11321146
specifics->structArgumentType(func.getLoc(), recTy, newInTyAndAttrs);
11331147
createFuncOpArgFixups(func, newInTyAndAttrs, structArgs, fixups);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test no-struct-conversion of target-rewrite pass.
2+
// RUN: fir-opt -target-rewrite="no-struct-conversion" %s | FileCheck %s
3+
4+
func.func @test(%arg0: !fir.type<t{i:i32}>) {
5+
return
6+
}
7+
8+
func.func @test_call(%arg0: !fir.type<t{i:i32}>) {
9+
fir.call @test(%arg0) : (!fir.type<t{i:i32}>) -> ()
10+
return
11+
}
12+
13+
func.func @test_addr_off() {
14+
%0 = fir.address_of(@test) : (!fir.type<t{i:i32}>) -> ()
15+
return
16+
}
17+
18+
// CHECK-LABEL: func.func @test(%{{.*}}: !fir.type<t{i:i32}>) {
19+
20+
// CHECK-LABEL: func.func @test_call(
21+
// CHECK-SAME: %[[ARG0:.*]]: !fir.type<t{i:i32}>) {
22+
// CHECK: fir.call @test(%[[ARG0]]) : (!fir.type<t{i:i32}>) -> ()
23+
24+
// CHECK-LABEL: func.func @test_addr_off() {
25+
// CHECK: fir.address_of(@test) : (!fir.type<t{i:i32}>) -> ()

0 commit comments

Comments
 (0)