Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion flang/lib/Optimizer/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,14 @@ struct CallOpConversion : public fir::FIROpConversion<fir::CallOp> {
// Convert arith::FastMathFlagsAttr to LLVM::FastMathFlagsAttr.
mlir::arith::AttrConvertFastMathToLLVM<fir::CallOp, mlir::LLVM::CallOp>
attrConvert(call);
rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
auto llvmCall = rewriter.replaceOpWithNewOp<mlir::LLVM::CallOp>(
call, resultTys, adaptor.getOperands(),
addLLVMOpBundleAttrs(rewriter, attrConvert.getAttrs(),
adaptor.getOperands().size()));
if (mlir::ArrayAttr argAttrs = call.getArgAttrsAttr())
llvmCall.setArgAttrsAttr(argAttrs);
if (mlir::ArrayAttr resAttrs = call.getResAttrsAttr())
llvmCall.setResAttrsAttr(resAttrs);
return mlir::success();
}
};
Expand Down
31 changes: 19 additions & 12 deletions flang/lib/Optimizer/Dialect/FIROps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,12 @@ void fir::CallOp::print(mlir::OpAsmPrinter &p) {

p.printOptionalAttrDict((*this)->getAttrs(),
{fir::CallOp::getCalleeAttrNameStr(),
getFastmathAttrName(), getProcedureAttrsAttrName()});
auto resultTypes{getResultTypes()};
llvm::SmallVector<mlir::Type> argTypes(
llvm::drop_begin(getOperandTypes(), isDirect ? 0 : 1));
p << " : " << mlir::FunctionType::get(getContext(), argTypes, resultTypes);
getFastmathAttrName(), getProcedureAttrsAttrName(),
getArgAttrsAttrName(), getResAttrsAttrName()});
p << " : ";
mlir::call_interface_impl::printFunctionSignature(
p, getArgs().drop_front(isDirect ? 0 : 1).getTypes(), getArgAttrsAttr(),
/*isVariadic=*/false, getResultTypes(), getResAttrsAttr());
}

mlir::ParseResult fir::CallOp::parse(mlir::OpAsmParser &parser,
Expand All @@ -1142,7 +1143,6 @@ mlir::ParseResult fir::CallOp::parse(mlir::OpAsmParser &parser,
attrs))
return mlir::failure();

mlir::Type type;
if (parser.parseOperandList(operands, mlir::OpAsmParser::Delimiter::Paren))
return mlir::failure();

Expand All @@ -1163,13 +1163,17 @@ mlir::ParseResult fir::CallOp::parse(mlir::OpAsmParser &parser,
fmfAttrName, attrs))
return mlir::failure();

if (parser.parseOptionalAttrDict(attrs) || parser.parseColon() ||
parser.parseType(type))
if (parser.parseOptionalAttrDict(attrs) || parser.parseColon())
return mlir::failure();

auto funcType = mlir::dyn_cast<mlir::FunctionType>(type);
if (!funcType)
llvm::SmallVector<mlir::Type> argTypes;
llvm::SmallVector<mlir::Type> resTypes;
llvm::SmallVector<mlir::DictionaryAttr> argAttrs;
llvm::SmallVector<mlir::DictionaryAttr> resultAttrs;
if (mlir::call_interface_impl::parseFunctionSignature(
parser, argTypes, argAttrs, resTypes, resultAttrs))
return parser.emitError(parser.getNameLoc(), "expected function type");
mlir::FunctionType funcType =
mlir::FunctionType::get(parser.getContext(), argTypes, resTypes);
if (isDirect) {
if (parser.resolveOperands(operands, funcType.getInputs(),
parser.getNameLoc(), result.operands))
Expand All @@ -1183,8 +1187,11 @@ mlir::ParseResult fir::CallOp::parse(mlir::OpAsmParser &parser,
parser.getNameLoc(), result.operands))
return mlir::failure();
}
result.addTypes(funcType.getResults());
result.attributes = attrs;
mlir::call_interface_impl::addArgAndResultAttrs(
parser.getBuilder(), result, argAttrs, resultAttrs,
getArgAttrsAttrName(result.name), getResAttrsAttrName(result.name));
result.addTypes(funcType.getResults());
return mlir::success();
}

Expand Down
18 changes: 18 additions & 0 deletions flang/test/Fir/convert-to-llvm.fir
Original file line number Diff line number Diff line change
Expand Up @@ -2853,3 +2853,21 @@ gpu.module @cuda_device_mod {
// CHECK: llvm.func @malloc(i64) -> !llvm.ptr
// CHECK: llvm.call @malloc
// CHECK: lvm.call @free

// -----

func.func private @somefunc(i32, !fir.ref<i64>)

// CHECK-LABEL: @test_call_arg_attrs_direct
func.func @test_call_arg_attrs_direct(%arg0: i32, %arg1: !fir.ref<i64>) {
// CHECK: llvm.call @somefunc(%{{.*}}, %{{.*}}) : (i32, !llvm.ptr {llvm.byval = i64}) -> ()
fir.call @somefunc(%arg0, %arg1) : (i32, !fir.ref<i64> {llvm.byval = i64}) -> ()
return
}

// CHECK-LABEL: @test_call_arg_attrs_indirect
func.func @test_call_arg_attrs_indirect(%arg0: i16, %arg1: (i16)-> i16) -> i16 {
// CHECK: llvm.call %arg1(%{{.*}}) : !llvm.ptr, (i16 {llvm.noundef, llvm.signext}) -> (i16 {llvm.signext})
%0 = fir.call %arg1(%arg0) : (i16 {llvm.noundef, llvm.signext}) -> (i16 {llvm.signext})
return %0 : i16
}
20 changes: 20 additions & 0 deletions flang/test/Fir/fir-ops.fir
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,23 @@ func.func @test_is_assumed_size(%arg0: !fir.class<!fir.array<*:none>>, %arg1 : !
// CHECK-SAME: %[[B:.*]]: !fir.box<!fir.array<?xf32>>)
// CHECK: fir.is_assumed_size %[[A]] : (!fir.class<!fir.array<*:none>>) -> i1
// CHECK: fir.is_assumed_size %[[B]] : (!fir.box<!fir.array<?xf32>>) -> i1

func.func private @somefunc(i32, !fir.ref<i64>)

// CHECK-LABEL: @test_call_arg_attrs_direct
// CHECK-SAME: %[[VAL_0:.*]]: i32,
// CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i64>) {
func.func @test_call_arg_attrs_direct(%arg0: i32, %arg1: !fir.ref<i64>) {
// CHECK: fir.call @somefunc(%[[VAL_0]], %[[VAL_1]]) : (i32, !fir.ref<i64> {llvm.byval = i64}) -> ()
fir.call @somefunc(%arg0, %arg1) : (i32, !fir.ref<i64> {llvm.byval = i64}) -> ()
return
}

// CHECK-LABEL: @test_call_arg_attrs_indirect
// CHECK-SAME: %[[VAL_0:.*]]: i16,
// CHECK-SAME: %[[VAL_1:.*]]: (i16) -> i16) -> i16 {
func.func @test_call_arg_attrs_indirect(%arg0: i16, %arg1: (i16)-> i16) -> i16 {
// CHECK: fir.call %[[VAL_1]](%[[VAL_0]]) : (i16 {llvm.noundef, llvm.signext}) -> (i16 {llvm.signext})
%0 = fir.call %arg1(%arg0) : (i16 {llvm.noundef, llvm.signext}) -> (i16 {llvm.signext})
return %0 : i16
}