diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -720,34 +720,7 @@ "llvm::ArrayRef":$typeOperands, "llvm::ArrayRef":$destinations, CArg<"llvm::ArrayRef", "{}">:$destOperands, - CArg<"llvm::ArrayRef", "{}">:$attributes), - [{ - $_state.addOperands(selector); - $_state.addAttribute(getCasesAttr(), - $_builder.getArrayAttr(typeOperands)); - const auto count = destinations.size(); - for (auto d : destinations) - $_state.addSuccessors(d); - const auto opCount = destOperands.size(); - llvm::SmallVector argOffs; - int32_t sumArgs = 0; - for (std::remove_const_t i = 0; i != count; ++i) { - if (i < opCount) { - $_state.addOperands(destOperands[i]); - const auto argSz = destOperands[i].size(); - argOffs.push_back(argSz); - sumArgs += argSz; - } else { - argOffs.push_back(0); - } - } - $_state.addAttribute(getOperandSegmentSizeAttr(), - $_builder.getI32VectorAttr({1, 0, sumArgs})); - $_state.addAttribute(getTargetOffsetAttr(), - $_builder.getI32VectorAttr(argOffs)); - $_state.addAttributes(attributes); - }] - >]; + CArg<"llvm::ArrayRef", "{}">:$attributes)>]; let parser = "return parseSelectType(parser, result);"; diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -2671,6 +2671,37 @@ return mlir::success(); } +void fir::SelectTypeOp::build(mlir::OpBuilder &builder, + mlir::OperationState &result, + mlir::Value selector, + llvm::ArrayRef typeOperands, + llvm::ArrayRef destinations, + llvm::ArrayRef destOperands, + llvm::ArrayRef attributes) { + result.addOperands(selector); + result.addAttribute(getCasesAttr(), builder.getArrayAttr(typeOperands)); + const auto count = destinations.size(); + for (mlir::Block *dest : destinations) + result.addSuccessors(dest); + const auto opCount = destOperands.size(); + llvm::SmallVector argOffs; + int32_t sumArgs = 0; + for (std::remove_const_t i = 0; i != count; ++i) { + if (i < opCount) { + result.addOperands(destOperands[i]); + const auto argSz = destOperands[i].size(); + argOffs.push_back(argSz); + sumArgs += argSz; + } else { + argOffs.push_back(0); + } + } + result.addAttribute(getOperandSegmentSizeAttr(), + builder.getI32VectorAttr({1, 0, sumArgs})); + result.addAttribute(getTargetOffsetAttr(), builder.getI32VectorAttr(argOffs)); + result.addAttributes(attributes); +} + //===----------------------------------------------------------------------===// // ShapeOp //===----------------------------------------------------------------------===//