[flang-commits] [flang] [flang] Insert stacksave/stackrestore when alloca are present in loops (PR #95173)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Tue Jun 11 15:10:04 PDT 2024
================
@@ -72,6 +75,22 @@ class CfgLoopConv : public mlir::OpRewritePattern<fir::DoLoopOp> {
rewriter.splitBlock(conditionalBlock, conditionalBlock->begin());
auto *lastBlock = &loop.getRegion().back();
+ // Insert stacksave/stackrestore if there is fir.alloca operation in the
+ // loop.
+ if (hasAllocas) {
+ auto mod = loop.getOperation()->getParentOfType<mlir::ModuleOp>();
+ fir::FirOpBuilder builder(rewriter, mod);
+ builder.setInsertionPointToStart(firstBlock);
+ mlir::func::FuncOp stackSave = fir::factory::getLlvmStackSave(builder);
----------------
clementval wrote:
> This seems to require making the pass a module pass. This is quite unfortunate.
Yeah if we can avoid that it would probably be better.
> Would that be possible to insert stacksave/stackrestore calls during hlfir.concat bufferization? It might be inefficient, but we will get correct code at least. The redundant stacksave/stackrestore might be optimized after that.
Yes we can be then we would miss other case (if any) of fir.alloca with dynamic size in loops.
https://github.com/llvm/llvm-project/pull/95173
More information about the flang-commits
mailing list