[flang-commits] [flang] [llvm] [flang][MIF] Adding Stop and ErrorStop operations (PR #166787)
Dan Bonachea via flang-commits
flang-commits at lists.llvm.org
Wed Jan 14 08:59:28 PST 2026
================
@@ -74,6 +75,121 @@ static mlir::Value genStatPRIF(fir::FirOpBuilder &builder, mlir::Location loc,
return stat;
}
+static fir::CallOp genPRIFStopErrorStop(fir::FirOpBuilder &builder,
+ mlir::Location loc, mlir::Value quiet,
+ mlir::Value stopCode,
+ bool isError = false) {
+ mlir::Type stopCharTy = fir::BoxCharType::get(builder.getContext(), 1);
+ mlir::Type i1Ty = builder.getI1Type();
+ mlir::Type i32Ty = builder.getI32Type();
+
+ mlir::FunctionType ftype = mlir::FunctionType::get(
+ builder.getContext(),
+ /*inputs*/
+ {builder.getRefType(i1Ty), builder.getRefType(i32Ty), stopCharTy},
+ /*results*/ {});
+ mlir::func::FuncOp funcOp =
+ isError
+ ? builder.createFunction(loc, getPRIFProcName("error_stop"), ftype)
+ : builder.createFunction(loc, getPRIFProcName("stop"), ftype);
+
+ // Default value of QUIET to false
+ mlir::Value q;
+ if (!quiet) {
+ q = builder.createBool(loc, false);
+ quiet = builder.createTemporary(loc, i1Ty);
+ } else {
+ q = quiet;
+ if (q.getType() != i1Ty)
+ q = fir::ConvertOp::create(builder, loc, i1Ty, q);
+ quiet = builder.createTemporary(loc, i1Ty);
+ }
+ fir::StoreOp::create(builder, loc, q, quiet);
+
+ mlir::Value stopCodeInt, stopCodeChar;
+ if (!stopCode) {
+ stopCodeChar = fir::AbsentOp::create(builder, loc, stopCharTy);
+ stopCodeInt =
+ fir::AbsentOp::create(builder, loc, builder.getRefType(i32Ty));
+ } else if (fir::isa_integer(stopCode.getType())) {
+ stopCodeChar = fir::AbsentOp::create(builder, loc, stopCharTy);
+ stopCodeInt = builder.createTemporary(loc, i32Ty);
+ if (stopCode.getType() != i32Ty)
+ stopCode = fir::ConvertOp::create(builder, loc, i32Ty, stopCode);
+ fir::StoreOp::create(builder, loc, stopCode, stopCodeInt);
+ } else {
+ stopCodeChar = stopCode;
+ if (!mlir::isa<fir::BoxCharType>(stopCodeChar.getType())) {
+ auto len =
+ fir::UndefOp::create(builder, loc, builder.getCharacterLengthType());
+ stopCodeChar =
+ fir::EmboxCharOp::create(builder, loc, stopCharTy, stopCodeChar, len);
+ }
+ stopCodeInt =
+ fir::AbsentOp::create(builder, loc, builder.getRefType(i32Ty));
+ }
----------------
bonachea wrote:
I don't have a strong preference on this, I just wanted to raise it for discussion.
The dead code seems to be correct, but if we don't envision the extra generality ever becoming reachable then it might slightly improve maintainability to remove it.
https://github.com/llvm/llvm-project/pull/166787
More information about the flang-commits
mailing list