Skip to content

Commit f589f30

Browse files
Review comment updates
1 parent 0052dd8 commit f589f30

File tree

6 files changed

+14
-25
lines changed

6 files changed

+14
-25
lines changed

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ def ConstantArgumentGlobalisationOpt : Pass<"constant-argument-globalisation-opt
258258
Convert scalar literals of function arguments to global constants.
259259
}];
260260
let dependentDialects = [ "fir::FIROpsDialect" ];
261-
let constructor = "::fir::createConstantArgumentGlobalisationPass()";
262261
}
263262

264263
def StackArrays : Pass<"stack-arrays", "mlir::ModuleOp"> {

flang/include/flang/Tools/CLOptions.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ inline void createDefaultFIROptimizerPassPipeline(
273273
pm.addPass(fir::createSimplifyIntrinsics());
274274
pm.addPass(fir::createAlgebraicSimplificationPass(config));
275275
if (!disableConstantArgumentGlobalisation)
276-
pm.addPass(fir::createConstantArgumentGlobalisationPass());
276+
pm.addPass(fir::createConstantArgumentGlobalisationOpt());
277277
}
278278

279279
if (pc.LoopVersioning)

flang/lib/Optimizer/Transforms/ConstantArgumentGlobalisation.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- ConstExtruder.cpp --------------------------------------------------===//
1+
//===- ConstantArgumentGlobalisation.cpp ----------------------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -22,7 +22,7 @@ namespace fir {
2222
#include "flang/Optimizer/Transforms/Passes.h.inc"
2323
} // namespace fir
2424

25-
#define DEBUG_TYPE "flang-const-extruder-opt"
25+
#define DEBUG_TYPE "flang-constang-argument-globalisation-opt"
2626

2727
namespace {
2828
unsigned uniqueLitId = 1;
@@ -93,7 +93,8 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
9393

9494
LLVM_DEBUG(llvm::dbgs() << " found define " << *constant_def << "\n");
9595

96-
std::string globalName = "_extruded_." + std::to_string(uniqueLitId++);
96+
std::string globalName =
97+
"_global_const_." + std::to_string(uniqueLitId++);
9798
assert(!builder.getNamedGlobal(globalName) &&
9899
"We should have a unique name here");
99100

@@ -138,7 +139,7 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
138139

139140
for (auto e : toErase)
140141
rewriter.eraseOp(e);
141-
LLVM_DEBUG(llvm::dbgs() << "extruded constant for " << callOp << " as "
142+
LLVM_DEBUG(llvm::dbgs() << "global constant for " << callOp << " as "
142143
<< newOp << '\n');
143144
return mlir::success();
144145
}
@@ -150,7 +151,8 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
150151
};
151152

152153
// this pass attempts to convert immediate scalar literals in function calls
153-
// to global constants to allow transformations as Dead Argument Elimination
154+
// to global constants to allow transformations such as Dead Argument
155+
// Elimination
154156
class ConstantArgumentGlobalisationOpt
155157
: public fir::impl::ConstantArgumentGlobalisationOptBase<
156158
ConstantArgumentGlobalisationOpt> {
@@ -160,14 +162,6 @@ class ConstantArgumentGlobalisationOpt
160162
void runOnOperation() override {
161163
mlir::ModuleOp mod = getOperation();
162164
mlir::DominanceInfo *di = &getAnalysis<mlir::DominanceInfo>();
163-
mod.walk([di, this](mlir::func::FuncOp func) { runOnFunc(func, di); });
164-
}
165-
166-
void runOnFunc(mlir::func::FuncOp &func, const mlir::DominanceInfo *di) {
167-
// If func is a declaration, skip it.
168-
if (func.empty())
169-
return;
170-
171165
auto *context = &getContext();
172166
mlir::RewritePatternSet patterns(context);
173167
mlir::GreedyRewriteConfig config;
@@ -176,15 +170,11 @@ class ConstantArgumentGlobalisationOpt
176170

177171
patterns.insert<CallOpRewriter>(context, *di);
178172
if (mlir::failed(mlir::applyPatternsAndFoldGreedily(
179-
func, std::move(patterns), config))) {
180-
mlir::emitError(func.getLoc(),
181-
"error in constant extrusion optimization\n");
173+
mod, std::move(patterns), config))) {
174+
mlir::emitError(mod.getLoc(),
175+
"error in constant globalisation optimization\n");
182176
signalPassFailure();
183177
}
184178
}
185179
};
186180
} // namespace
187-
188-
std::unique_ptr<mlir::Pass> fir::createConstantArgumentGlobalisationPass() {
189-
return std::make_unique<ConstantArgumentGlobalisationOpt>();
190-
}

flang/test/Lower/character-local-variables.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ subroutine dyn_array_dyn_len_lb(l, n)
116116
subroutine assumed_length_param(n)
117117
character(*), parameter :: c(1)=(/"abcd"/)
118118
integer :: n
119-
! CHECK: %[[tmp:.*]] = fir.address_of(@_extruded_.{{.*}}) : !fir.ref<i64>
119+
! CHECK: %[[tmp:.*]] = fir.address_of(@_global_const_.{{.*}}) : !fir.ref<i64>
120120
! CHECK: fir.call @_QPtake_int(%[[tmp]]) {{.*}}: (!fir.ref<i64>) -> ()
121121
call take_int(len(c(n), kind=8))
122122
end

flang/test/Lower/dummy-arguments.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
! CHECK-LABEL: _QQmain
44
program test1
5-
! CHECK-DAG: %[[TEN:.*]] = fir.address_of(@_extruded_.{{.*}}) : !fir.ref<i32>
5+
! CHECK-DAG: %[[TEN:.*]] = fir.address_of(@_global_const_.{{.*}}) : !fir.ref<i32>
66
! CHECK-NEXT: fir.call @_QFPfoo
77
call foo(10)
88
contains

flang/test/Lower/host-associated.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ subroutine bar()
449449
! CHECK-LABEL: func @_QPtest_proc_dummy_other(
450450
! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxproc<() -> ()>) {
451451
! CHECK: %[[VAL_3:.*]] = fir.box_addr %[[VAL_0]] : (!fir.boxproc<() -> ()>) -> ((!fir.ref<i32>) -> ())
452-
! CHECK: %[[VAL_1:.*]] = fir.address_of(@_extruded_.{{.*}}) : !fir.ref<i32>
452+
! CHECK: %[[VAL_1:.*]] = fir.address_of(@_global_const_.{{.*}}) : !fir.ref<i32>
453453
! CHECK: fir.call %[[VAL_3]](%[[VAL_1]]) {{.*}}: (!fir.ref<i32>) -> ()
454454

455455
! CHECK: return

0 commit comments

Comments
 (0)