[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:44 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-llvm

Author: None (gitoleg)

<details>
<summary>Changes</summary>

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. 

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


1 Files Affected:

- (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp (+2-1) 


``````````diff
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,

``````````

</details>


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


More information about the Mlir-commits mailing list