[flang-commits] [flang] ca53e04 - [flang] Lower integer constant code for STOP stmt
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Feb 3 02:31:17 PST 2022
Author: Valentin Clement
Date: 2022-02-03T11:31:12+01:00
New Revision: ca53e049e0130be8d922a6ae80a1dcbddea2b25b
URL: https://github.com/llvm/llvm-project/commit/ca53e049e0130be8d922a6ae80a1dcbddea2b25b
DIFF: https://github.com/llvm/llvm-project/commit/ca53e049e0130be8d922a6ae80a1dcbddea2b25b.diff
LOG: [flang] Lower integer constant code for STOP stmt
This patch lower the integer constant code in the STOP statement.
The code is lowered to `arith.constant`.
This patch is part of the upstreaming effort from fir-dev branch.
Reviewed By: schweitz, kiranchandramohan
Differential Revision: https://reviews.llvm.org/D118787
Added:
Modified:
flang/lib/Lower/Runtime.cpp
flang/test/Lower/stop-statement.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/Runtime.cpp b/flang/lib/Lower/Runtime.cpp
index a49b0911d1a1a..3ec2fed82eb5d 100644
--- a/flang/lib/Lower/Runtime.cpp
+++ b/flang/lib/Lower/Runtime.cpp
@@ -42,8 +42,27 @@ void Fortran::lower::genStopStatement(
mlir::FuncOp callee;
mlir::FunctionType calleeType;
// First operand is stop code (zero if absent)
- if (std::get<std::optional<Fortran::parser::StopCode>>(stmt.t)) {
- TODO(loc, "STOP first operand not lowered yet");
+ if (const auto &code =
+ std::get<std::optional<Fortran::parser::StopCode>>(stmt.t)) {
+ auto expr = converter.genExprValue(*Fortran::semantics::GetExpr(*code));
+ LLVM_DEBUG(llvm::dbgs() << "stop expression: "; expr.dump();
+ llvm::dbgs() << '\n');
+ expr.match(
+ [&](const fir::CharBoxValue &x) {
+ TODO(loc, "STOP CharBoxValue first operand not lowered yet");
+ },
+ [&](fir::UnboxedValue x) {
+ callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatement)>(
+ loc, builder);
+ calleeType = callee.getType();
+ mlir::Value cast =
+ builder.createConvert(loc, calleeType.getInput(0), x);
+ operands.push_back(cast);
+ },
+ [&](auto) {
+ mlir::emitError(loc, "unhandled expression in STOP");
+ std::exit(1);
+ });
} else {
callee = fir::runtime::getRuntimeFunc<mkRTKey(StopStatement)>(loc, builder);
calleeType = callee.getType();
diff --git a/flang/test/Lower/stop-statement.f90 b/flang/test/Lower/stop-statement.f90
index 497b6db1a9f4b..062d8353e56df 100644
--- a/flang/test/Lower/stop-statement.f90
+++ b/flang/test/Lower/stop-statement.f90
@@ -19,3 +19,12 @@ subroutine stop_error()
! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c0]], %[[true]], %[[false]])
! CHECK-NEXT: fir.unreachable
end subroutine
+
+! CHECK-LABEL stop_code
+subroutine stop_code()
+ stop 42
+ ! CHECK-DAG: %[[c42:.*]] = arith.constant 42 : i32
+ ! CHECK-DAG: %[[false:.*]] = arith.constant false
+ ! CHECK: fir.call @_Fortran{{.*}}StopStatement(%[[c42]], %[[false]], %[[false]])
+ ! CHECK-NEXT: fir.unreachable
+end subroutine
More information about the flang-commits
mailing list