[fir] Update fir.call op

Move builders to .cpp file and update accordingly.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D110698

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
This commit is contained in:
Eric Schweitz 2021-09-29 18:29:33 +02:00 committed by Valentin Clement
parent 67a3d1e275
commit 576301d922
No known key found for this signature in database
GPG Key ID: 086D54783C928776
2 changed files with 25 additions and 17 deletions

View File

@ -2649,21 +2649,10 @@ def fir_CallOp : fir_Op<"call", [CallOpInterface]> {
let builders = [ let builders = [
OpBuilder<(ins "mlir::FuncOp":$callee, OpBuilder<(ins "mlir::FuncOp":$callee,
CArg<"mlir::ValueRange", "{}">:$operands), CArg<"mlir::ValueRange", "{}">:$operands)>,
[{
$_state.addOperands(operands);
$_state.addAttribute(calleeAttrName($_state.name),
SymbolRefAttr::get(callee));
$_state.addTypes(callee.getType().getResults());
}]>,
OpBuilder<(ins "mlir::SymbolRefAttr":$callee, OpBuilder<(ins "mlir::SymbolRefAttr":$callee,
"llvm::ArrayRef<mlir::Type>":$results, "llvm::ArrayRef<mlir::Type>":$results,
CArg<"mlir::ValueRange", "{}">:$operands), CArg<"mlir::ValueRange", "{}">:$operands)>,
[{
$_state.addOperands(operands);
$_state.addAttribute(calleeAttrName($_state.name), callee);
$_state.addTypes(results);
}]>,
OpBuilder<(ins "llvm::StringRef":$callee, OpBuilder<(ins "llvm::StringRef":$callee,
"llvm::ArrayRef<mlir::Type>":$results, "llvm::ArrayRef<mlir::Type>":$results,
CArg<"mlir::ValueRange", "{}">:$operands), CArg<"mlir::ValueRange", "{}">:$operands),
@ -2674,11 +2663,13 @@ def fir_CallOp : fir_Op<"call", [CallOpInterface]> {
}]>]; }]>];
let extraClassDeclaration = [{ let extraClassDeclaration = [{
static constexpr StringRef getCalleeAttrName() { return "callee"; }
mlir::FunctionType getFunctionType(); mlir::FunctionType getFunctionType();
/// Get the argument operands to the called function. /// Get the argument operands to the called function.
operand_range getArgOperands() { operand_range getArgOperands() {
if (calleeAttr()) if ((*this)->getAttrOfType<SymbolRefAttr>(getCalleeAttrName()))
return {arg_operand_begin(), arg_operand_end()}; return {arg_operand_begin(), arg_operand_end()};
return {arg_operand_begin() + 1, arg_operand_end()}; return {arg_operand_begin() + 1, arg_operand_end()};
} }
@ -2688,7 +2679,8 @@ def fir_CallOp : fir_Op<"call", [CallOpInterface]> {
/// Return the callee of this operation. /// Return the callee of this operation.
CallInterfaceCallable getCallableForCallee() { CallInterfaceCallable getCallableForCallee() {
if (auto calling = calleeAttr()) if (auto calling =
(*this)->getAttrOfType<SymbolRefAttr>(getCalleeAttrName()))
return calling; return calling;
return getOperand(0); return getOperand(0);
} }

View File

@ -298,6 +298,22 @@ static mlir::ParseResult parseCallOp(mlir::OpAsmParser &parser,
return mlir::success(); 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<mlir::Type> results,
mlir::ValueRange operands) {
result.addOperands(operands);
result.addAttribute(getCalleeAttrName(), callee);
result.addTypes(results);
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// CmpOp // CmpOp
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//