[Mlir-commits] [mlir] [mlir][llvm] Fixes CallOp builder for the case of indirect call (PR #76240)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Dec 22 06:03:00 PST 2023
https://github.com/gitoleg created https://github.com/llvm/llvm-project/pull/76240
The problem.
The `CallOp` of the LLVM dialect has the next behavior: once the `callee` attribute is set, the call is considered as a direct one. And vice versa, once `callee` is not set, the call is an indirect one. For the case of indirect call, the first operand to the `CallOp` must be a function pointer, and all the remaining are arguments of the function. One of the `CallOp` builders doesn't actually check the `callee` attribute and always generate function type from the all operands, which later caused a fail in transition from the dialect to LLVM IR due to different number of operands expected by function type [here](https://github.com/llvm/llvm-project/blob/main/mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp#L215). This PR fix it.
>From 30cffd17a6f2c48c20cce89c0591344da4ec86d6 Mon Sep 17 00:00:00 2001
From: gitoleg <forown at yandex.ru>
Date: Fri, 22 Dec 2023 16:40:25 +0300
Subject: [PATCH] [mlir][llvm] Fixes CallOp builder for the case of indirect
call
---
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 458bf83eac17f8..2fb82aeaa2bda7 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -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();
build(builder, state, results,
- TypeAttr::get(getLLVMFuncType(builder.getContext(), results, args)),
+ TypeAttr::get(getLLVMFuncType(builder.getContext(), results, fargs)),
callee, args, /*fastmathFlags=*/nullptr, /*branch_weights=*/nullptr,
/*CConv=*/nullptr,
/*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
More information about the Mlir-commits
mailing list