[flang] [llvm] [flang][MIF] Adding Stop and ErrorStop operations (PR #166787)
Dan Bonachea via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 13 21:33:06 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:
IIUC, much of the generality here is no longer reachable in the latest version of the PR. Specifically, in the only current callers of `genPRIFStopErrorStop`, the `QUIET` argument is hard-coded to `true` and the `stopCode` is always provided as an integer. The optional features of `STOP`/`ERROR STOP` are now handled inside flang-rt before PRIF is invoked, which seems fine.
This is not a request for change, I'm just making an observation of some extraneous/unreachable generality.
https://github.com/llvm/llvm-project/pull/166787
More information about the llvm-commits
mailing list