1
- // ===- ConstExtruder .cpp ---------------- ----------------------------------===//
1
+ // ===- ConstantArgumentGlobalisation .cpp ----------------------------------===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
@@ -22,7 +22,7 @@ namespace fir {
22
22
#include " flang/Optimizer/Transforms/Passes.h.inc"
23
23
} // namespace fir
24
24
25
- #define DEBUG_TYPE " flang-const-extruder -opt"
25
+ #define DEBUG_TYPE " flang-constang-argument-globalisation -opt"
26
26
27
27
namespace {
28
28
unsigned uniqueLitId = 1 ;
@@ -93,7 +93,8 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
93
93
94
94
LLVM_DEBUG (llvm::dbgs () << " found define " << *constant_def << " \n " );
95
95
96
- std::string globalName = " _extruded_." + std::to_string (uniqueLitId++);
96
+ std::string globalName =
97
+ " _global_const_." + std::to_string (uniqueLitId++);
97
98
assert (!builder.getNamedGlobal (globalName) &&
98
99
" We should have a unique name here" );
99
100
@@ -138,7 +139,7 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
138
139
139
140
for (auto e : toErase)
140
141
rewriter.eraseOp (e);
141
- LLVM_DEBUG (llvm::dbgs () << " extruded constant for " << callOp << " as "
142
+ LLVM_DEBUG (llvm::dbgs () << " global constant for " << callOp << " as "
142
143
<< newOp << ' \n ' );
143
144
return mlir::success ();
144
145
}
@@ -150,7 +151,8 @@ class CallOpRewriter : public mlir::OpRewritePattern<fir::CallOp> {
150
151
};
151
152
152
153
// 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
154
156
class ConstantArgumentGlobalisationOpt
155
157
: public fir::impl::ConstantArgumentGlobalisationOptBase<
156
158
ConstantArgumentGlobalisationOpt> {
@@ -160,14 +162,6 @@ class ConstantArgumentGlobalisationOpt
160
162
void runOnOperation () override {
161
163
mlir::ModuleOp mod = getOperation ();
162
164
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
-
171
165
auto *context = &getContext ();
172
166
mlir::RewritePatternSet patterns (context);
173
167
mlir::GreedyRewriteConfig config;
@@ -176,15 +170,11 @@ class ConstantArgumentGlobalisationOpt
176
170
177
171
patterns.insert <CallOpRewriter>(context, *di);
178
172
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 " );
182
176
signalPassFailure ();
183
177
}
184
178
}
185
179
};
186
180
} // namespace
187
-
188
- std::unique_ptr<mlir::Pass> fir::createConstantArgumentGlobalisationPass () {
189
- return std::make_unique<ConstantArgumentGlobalisationOpt>();
190
- }
0 commit comments