[Mlir-commits] [mlir] bebb9df - [mlir][llvm] Add a indirect call builder for CallOp (NFC)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 29 17:23:21 PDT 2023


Author: Mogball
Date: 2023-09-29T17:23:09-07:00
New Revision: bebb9dfc9c0c0029e903a83b20b25d6adfc546bb

URL: https://github.com/llvm/llvm-project/commit/bebb9dfc9c0c0029e903a83b20b25d6adfc546bb
DIFF: https://github.com/llvm/llvm-project/commit/bebb9dfc9c0c0029e903a83b20b25d6adfc546bb.diff

LOG: [mlir][llvm] Add a indirect call builder for CallOp (NFC)

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
    mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index cffa704e3145f1c..25209ce4497455e 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -647,7 +647,8 @@ def LLVM_CallOp : LLVM_MemAccessOpBase<"call",
     OpBuilder<(ins "LLVMFunctionType":$calleeType, "FlatSymbolRefAttr":$callee,
                    CArg<"ValueRange", "{}">:$args)>,
     OpBuilder<(ins "LLVMFunctionType":$calleeType, "StringRef":$callee,
-                   CArg<"ValueRange", "{}">:$args)>
+                   CArg<"ValueRange", "{}">:$args)>,
+    OpBuilder<(ins "Value":$callee, "ValueRange":$args)>
   ];
   let hasCustomAssemblyFormat = 1;
   let extraClassDeclaration = [{

diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 7f297fe79177560..95c04098d05fc2f 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -1053,9 +1053,7 @@ void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
                    FlatSymbolRefAttr callee, ValueRange args) {
   build(builder, state, results,
         TypeAttr::get(getLLVMFuncType(builder.getContext(), results, args)),
-        callee, args,
-        /*fastmathFlags=*/nullptr,
-        /*branch_weights=*/nullptr,
+        callee, args, /*fastmathFlags=*/nullptr, /*branch_weights=*/nullptr,
         /*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
         /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
 }
@@ -1077,18 +1075,15 @@ void CallOp::build(OpBuilder &builder, OperationState &state,
                    ValueRange args) {
   build(builder, state, getCallOpResultTypes(calleeType),
         TypeAttr::get(calleeType), callee, args, /*fastmathFlags=*/nullptr,
-        /*branch_weights=*/nullptr,
-        /*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
-        /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
+        /*branch_weights=*/nullptr, /*access_groups=*/nullptr,
+        /*alias_scopes=*/nullptr, /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
 }
 
 void CallOp::build(OpBuilder &builder, OperationState &state,
                    LLVMFunctionType calleeType, ValueRange args) {
   build(builder, state, getCallOpResultTypes(calleeType),
-        TypeAttr::get(calleeType),
-        /*callee=*/nullptr, args,
-        /*fastmathFlags=*/nullptr,
-        /*branch_weights=*/nullptr,
+        TypeAttr::get(calleeType), /*callee=*/nullptr, args,
+        /*fastmathFlags=*/nullptr, /*branch_weights=*/nullptr,
         /*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
         /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
 }
@@ -1098,12 +1093,26 @@ void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
   auto calleeType = func.getFunctionType();
   build(builder, state, getCallOpResultTypes(calleeType),
         TypeAttr::get(calleeType), SymbolRefAttr::get(func), args,
-        /*fastmathFlags=*/nullptr,
-        /*branch_weights=*/nullptr,
+        /*fastmathFlags=*/nullptr, /*branch_weights=*/nullptr,
         /*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
         /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
 }
 
+void CallOp::build(OpBuilder &builder, OperationState &state, Value callee,
+                   ValueRange args) {
+  auto calleeType = cast<LLVMFunctionType>(
+      cast<LLVMPointerType>(callee.getType()).getElementType());
+  SmallVector<Value> operands;
+  operands.reserve(1 + args.size());
+  operands.push_back(callee);
+  llvm::append_range(operands, args);
+  return build(builder, state, getCallOpResultTypes(calleeType),
+               TypeAttr::get(calleeType), FlatSymbolRefAttr(), operands,
+               /*fastmathFlags=*/nullptr, /*branch_weights=*/nullptr,
+               /*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
+               /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr);
+}
+
 CallInterfaceCallable CallOp::getCallableForCallee() {
   // Direct call.
   if (FlatSymbolRefAttr calleeAttr = getCalleeAttr())


        


More information about the Mlir-commits mailing list