[Mlir-commits] [mlir] [mlir][llvm] Fixes CallOp builder for the case of indirect call (PR #76240)

Ivan R. Ivanov llvmlistbot at llvm.org
Sun Dec 24 11:18:42 PST 2023


================
@@ -908,8 +908,9 @@ void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
 
 void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
                    FlatSymbolRefAttr callee, ValueRange args) {
+  auto fargs = callee ? args : args.drop_front();
----------------
ivanradanov wrote:

The docs refer to the operands of the MLIR op, and not the builder. The builders that take in a `callee` that specify a function using a symbol should result in a direct call IMO.

> Let's just add a builder that doesn't have a callee as an argument - and it will be a true indirect call!

We already have builders do not take callee as an argument, but one needs to provide the callee type instead. This is because there is no way to infer whether the callee is variadic or not in the case of an indirect call.

In fact, I think that CIR code is wrong when the indirect callee is variadic (unless CIR has a different CallOp for variadic functions?)

If you want to retain the current functionality (which is wrong if you have indirect calls to variadic), I believe  you can use the default builder (https://github.com/llvm/llvm-project/blob/d8ddcae547e782a4765783c62747381624f076d4/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td#L625) and pass in nullptr as the callee and callee_type.

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


More information about the Mlir-commits mailing list