[flang-commits] [flang] [flang] Implement lowering for the PAUSE statement (Fixes #166821) (PR #167115)
via flang-commits
flang-commits at lists.llvm.org
Thu Nov 20 10:40:42 PST 2025
================
@@ -263,12 +263,56 @@ void Fortran::lower::genSyncTeamStatement(
void Fortran::lower::genPauseStatement(
Fortran::lower::AbstractConverter &converter,
- const Fortran::parser::PauseStmt &) {
+ const Fortran::parser::PauseStmt &stmt) {
+
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
mlir::Location loc = converter.getCurrentLocation();
- mlir::func::FuncOp callee =
- fir::runtime::getRuntimeFunc<mkRTKey(PauseStatement)>(loc, builder);
- fir::CallOp::create(builder, loc, callee, mlir::ValueRange{});
+ Fortran::lower::StatementContext stmtCtx;
+
+ llvm::SmallVector<mlir::Value> operands;
+ mlir::func::FuncOp callee;
+ mlir::FunctionType calleeType;
+
+ if (stmt.v.has_value()) {
+ const auto &code = stmt.v.value();
+ auto expr = converter.genExprValue(*Fortran::semantics::GetExpr(code), stmtCtx);
+ LLVM_DEBUG(llvm::dbgs() << "pause expression: "; expr.dump(); llvm::dbgs() << '\n');
+ expr.match(
+ // Character-valued expression -> call PauseStatementText (CHAR, LEN)
+ [&](const fir::CharBoxValue &x) {
+ callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatementText)>(loc, builder);
+ calleeType = callee.getFunctionType();
+
+ operands.push_back(
+ builder.createConvert(loc, calleeType.getInput(0), x.getAddr()));
+ operands.push_back(
+ builder.createConvert(loc, calleeType.getInput(1), x.getLen()));
+ },
+ // Numeric/unboxed value -> call PauseStatement which accepts an integer code.
+ [&](fir::UnboxedValue x) {
+ callee = fir::runtime::getRuntimeFunc<mkRTKey(PauseStatement)>(loc, builder);
+ calleeType = callee.getFunctionType();
+ if (calleeType.getNumInputs() >= 1) {
+ mlir::Value cast =
+ builder.createConvert(loc, calleeType.getInput(0), x);
+ operands.push_back(cast);
+ }
+ },
+ [&](auto) {
+ mlir::emitError(loc, "unhandled expression in PAUSE");
+ std::exit(1);
----------------
sathvikreddy853 wrote:
I have updated this as well but there is inconsistency in the way that `genStopStatement` and `genPauseStatement` are written.
https://github.com/llvm/llvm-project/pull/167115
More information about the flang-commits
mailing list