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 @@ -2649,36 +2649,27 @@ let builders = [ OpBuilder<(ins "mlir::FuncOp":$callee, - CArg<"mlir::ValueRange", "{}">:$operands), - [{ - $_state.addOperands(operands); - $_state.addAttribute(calleeAttrName($_state.name), - SymbolRefAttr::get(callee)); - $_state.addTypes(callee.getType().getResults()); - }]>, + CArg<"mlir::ValueRange", "{}">:$operands)>, OpBuilder<(ins "mlir::SymbolRefAttr":$callee, "llvm::ArrayRef":$results, - CArg<"mlir::ValueRange", "{}">:$operands), - [{ - $_state.addOperands(operands); - $_state.addAttribute(calleeAttrName($_state.name), callee); - $_state.addTypes(results); - }]>, + CArg<"mlir::ValueRange", "{}">:$operands)>, OpBuilder<(ins "llvm::StringRef":$callee, "llvm::ArrayRef":$results, CArg<"mlir::ValueRange", "{}">:$operands), [{ build($_builder, $_state, - SymbolRefAttr::get($_builder.getContext(), callee), results, - operands); + SymbolRefAttr::get($_builder.getContext(), callee), results, + operands); }]>]; let extraClassDeclaration = [{ + static constexpr StringRef getCalleeAttrName() { return "callee"; } + mlir::FunctionType getFunctionType(); /// Get the argument operands to the called function. operand_range getArgOperands() { - if (calleeAttr()) + if ((*this)->getAttrOfType(getCalleeAttrName())) return {arg_operand_begin(), arg_operand_end()}; return {arg_operand_begin() + 1, arg_operand_end()}; } @@ -2688,7 +2679,8 @@ /// Return the callee of this operation. CallInterfaceCallable getCallableForCallee() { - if (auto calling = calleeAttr()) + if (auto calling = + (*this)->getAttrOfType(getCalleeAttrName())) return calling; return getOperand(0); } 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 @@ -298,6 +298,22 @@ return mlir::success(); } +void fir::CallOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, + mlir::FuncOp callee, mlir::ValueRange operands) { + result.addOperands(operands); + result.addAttribute(getCalleeAttrName(), SymbolRefAttr::get(callee)); + result.addTypes(callee.getType().getResults()); +} + +void fir::CallOp::build(mlir::OpBuilder &builder, mlir::OperationState &result, + mlir::SymbolRefAttr callee, + llvm::ArrayRef results, + mlir::ValueRange operands) { + result.addOperands(operands); + result.addAttribute(getCalleeAttrName(), callee); + result.addTypes(results); +} + //===----------------------------------------------------------------------===// // CmpOp //===----------------------------------------------------------------------===//