[flang-commits] [flang] [flang] Region-based HLFIR operation for conditional expressions lowering (PR #194411)

via flang-commits flang-commits at lists.llvm.org
Mon May 4 07:42:25 PDT 2026


================
@@ -2461,6 +2461,41 @@ llvm::LogicalResult hlfir::EvaluateInMemoryOp::verify() {
   return mlir::success();
 }
 
+//===----------------------------------------------------------------------===//
+// ConditionalOp
+//===----------------------------------------------------------------------===//
+
+void hlfir::ConditionalOp::build(mlir::OpBuilder &builder,
+                                 mlir::OperationState &odsState,
+                                 mlir::Type resultType, mlir::Value condition) {
+  odsState.addTypes(resultType);
+  odsState.addOperands(condition);
+  // Create the then and else regions, each with one empty block.
+  odsState.addRegion()->push_back(new mlir::Block{});
+  odsState.addRegion()->push_back(new mlir::Block{});
+}
+
+llvm::LogicalResult hlfir::ConditionalOp::verify() {
+  if (!mlir::isa<hlfir::ExprType>(getResult().getType()))
+    return emitOpError("result must be an hlfir.expr type");
+  const auto checkRegion = [&](mlir::Region &region,
+                               llvm::StringRef name) -> llvm::LogicalResult {
+    if (region.empty())
+      return emitOpError(name) << " region must not be empty";
+    if (!region.hasOneBlock())
+      return emitOpError(name) << " region must have exactly one block";
----------------
jeanPerier wrote:

nit: you do not need this, this failures should actually be unreachable since the .td verifier for `SizedRegion` will be run before the custom one (you can verify that by adding error checks).

https://github.com/llvm/llvm-project/pull/194411


More information about the flang-commits mailing list