[PATCH] D73895: [mlir] Accept an LLVM::LLVMFuncOp in the builder of LLVM::CallOp

Alex Zinenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 3 08:10:32 PST 2020


ftynse created this revision.
ftynse added reviewers: nicolasvasilache, rriddle.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, burmako, jpienaar, mehdi_amini.
Herald added a project: LLVM.

Replace the generic zero- and one-result builders in LLVM::CallOp with a custom
builder that takes an LLVMFuncOp, which can be used to extract the result type
and create the symbol reference attribute. This is merely a convenience for
upcoming changes. The ODS-generated builders remain present.

Introduce LLVM::LLVMType::isVoidTy by analogy with the underlying LLVM type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73895

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


Index: mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
===================================================================
--- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -1313,7 +1313,7 @@
     argTypes.push_back(fnType.getFunctionParamType(i));
 
   LLVMType returnType = fnType.getFunctionResultType();
-  if (!returnType.getUnderlyingType()->isVoidTy())
+  if (!returnType.isVoidTy())
     resTypes.push_back(returnType);
 
   impl::printFunctionSignature(p, op, argTypes, op.isVarArg(), resTypes);
@@ -1348,14 +1348,12 @@
 // Hook for OpTrait::FunctionLike, returns the number of function results.
 // Depends on the type attribute being correct as checked by verifyType
 unsigned LLVMFuncOp::getNumFuncResults() {
-  llvm::FunctionType *funcType =
-      cast<llvm::FunctionType>(getType().getUnderlyingType());
   // We model LLVM functions that return void as having zero results,
   // and all others as having one result.
   // If we modeled a void return as one result, then it would be possible to
   // attach an MLIR result attribute to it, and it isn't clear what semantics we
   // would assign to that.
-  if (funcType->getReturnType()->isVoidTy())
+  if (getType().getFunctionResultType().isVoidTy())
     return 0;
   return 1;
 }
@@ -1900,10 +1898,15 @@
     return llvm::VectorType::get(elementType.getUnderlyingType(), numElements);
   });
 }
+
 LLVMType LLVMType::getVoidTy(LLVMDialect *dialect) {
   return dialect->impl->voidTy;
 }
 
+bool LLVMType::isVoidTy() {
+  return getUnderlyingType()->isVoidTy();
+}
+
 //===----------------------------------------------------------------------===//
 // Utility functions.
 //===----------------------------------------------------------------------===//
Index: mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
===================================================================
--- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -344,7 +344,7 @@
 }
 
 def LLVM_LandingpadOp : LLVM_OneResultOp<"landingpad">,
-                        Arguments<(ins UnitAttr:$cleanup, 
+                        Arguments<(ins UnitAttr:$cleanup,
                                        Variadic<LLVM_Type>)> {
   let verifier = [{ return ::verify(*this); }];
   let parser = [{ return parseLandingpadOp(parser, result); }];
@@ -354,9 +354,18 @@
 def LLVM_CallOp : LLVM_Op<"call">,
                   Arguments<(ins OptionalAttr<FlatSymbolRefAttr>:$callee,
                              Variadic<LLVM_Type>)>,
-                  Results<(outs Variadic<LLVM_Type>)>,
-                  LLVM_TwoBuilders<LLVM_OneResultOpBuilder,
-                                   LLVM_ZeroResultOpBuilder> {
+                  Results<(outs Variadic<LLVM_Type>)> {
+  let builders = [OpBuilder<
+    "Builder *builder, OperationState &result, LLVMFuncOp func,"
+    "ValueRange operands, ArrayRef<NamedAttribute> attributes = {}",
+    [{
+      LLVMType resultType = func.getType().getFunctionResultType();
+      if (!resultType.isVoidTy())
+        result.addTypes(resultType);
+      result.addAttribute("callee", builder->getSymbolRefAttr(func));
+      result.addAttributes(attributes);
+      result.addOperands(operands);
+    }]>];
   let verifier = [{
     if (getNumResults() > 1)
       return emitOpError("must have 0 or 1 result");
Index: mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
===================================================================
--- mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
+++ mlir/include/mlir/Dialect/LLVMIR/LLVMDialect.h
@@ -137,7 +137,10 @@
     return getStructTy(&elt1.getDialect(), fields);
   }
   static LLVMType getVectorTy(LLVMType elementType, unsigned numElements);
+
+  /// Void type utilities.
   static LLVMType getVoidTy(LLVMDialect *dialect);
+  bool isVoidTy();
 
   // Creation and setting of LLVM's identified struct types
   static LLVMType createStructTy(LLVMDialect *dialect,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73895.242079.patch
Type: text/x-patch
Size: 3965 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200203/ffed075a/attachment.bin>


More information about the llvm-commits mailing list