diff options
| author | Alex Zinenko <zinenko@google.com> | 2019-10-10 01:33:33 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-10 01:34:06 -0700 |
| commit | 5e7959a3531c8019052bae3a84a42a67c5857bc9 (patch) | |
| tree | 1eb248dba17a3c4bfd2f9c815865254681ca78c8 /mlir/lib/Dialect/GPU | |
| parent | 309b4556d00f531988f34930eedb546512ee619f (diff) | |
| download | bcm5719-llvm-5e7959a3531c8019052bae3a84a42a67c5857bc9.tar.gz bcm5719-llvm-5e7959a3531c8019052bae3a84a42a67c5857bc9.zip | |
Use llvm.func to define functions with wrapped LLVM IR function type
This function-like operation allows one to define functions that have wrapped
LLVM IR function type, in particular variadic functions. The operation was
added in parallel to the existing lowering flow, this commit only switches the
flow to use it.
Using a custom function type makes the LLVM IR dialect type system more
consistent and avoids complex conversion rules for functions that previously
had to use the built-in function type instead of a wrapped LLVM IR dialect type
and perform conversions during the analysis.
PiperOrigin-RevId: 273910855
Diffstat (limited to 'mlir/lib/Dialect/GPU')
| -rw-r--r-- | mlir/lib/Dialect/GPU/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 27 |
2 files changed, 19 insertions, 12 deletions
diff --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt index 09da5cc16e9..6fe45ba49ef 100644 --- a/mlir/lib/Dialect/GPU/CMakeLists.txt +++ b/mlir/lib/Dialect/GPU/CMakeLists.txt @@ -6,5 +6,5 @@ add_llvm_library(MLIRGPU ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/GPU ) -add_dependencies(MLIRGPU MLIRGPUOpsIncGen MLIRIR LLVMSupport) -target_link_libraries(MLIRGPU MLIRIR MLIRStandardOps LLVMSupport) +add_dependencies(MLIRGPU MLIRGPUOpsIncGen MLIRIR MLIRLLVMIR LLVMSupport) +target_link_libraries(MLIRGPU MLIRIR MLIRLLVMIR MLIRStandardOps LLVMSupport) diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp index 2835578239f..a271a988f14 100644 --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -20,6 +20,7 @@ //===----------------------------------------------------------------------===// #include "mlir/Dialect/GPU/GPUDialect.h" +#include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/StandardOps/Ops.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Function.h" @@ -37,9 +38,8 @@ using namespace mlir::gpu; StringRef GPUDialect::getDialectName() { return "gpu"; } -bool GPUDialect::isKernel(FuncOp function) { - UnitAttr isKernelAttr = - function.getAttrOfType<UnitAttr>(getKernelFuncAttrName()); +bool GPUDialect::isKernel(Operation *op) { + UnitAttr isKernelAttr = op->getAttrOfType<UnitAttr>(getKernelFuncAttrName()); return static_cast<bool>(isKernelAttr); } @@ -92,18 +92,25 @@ LogicalResult GPUDialect::verifyOperationAttribute(Operation *op, // Check that `launch_func` refers to a well-formed kernel function. StringRef kernelName = launchOp.kernel(); - auto kernelFunction = kernelModule.lookupSymbol<FuncOp>(kernelName); - if (!kernelFunction) + Operation *kernelFunc = kernelModule.lookupSymbol(kernelName); + auto kernelStdFunction = dyn_cast_or_null<FuncOp>(kernelFunc); + auto kernelLLVMFunction = dyn_cast_or_null<LLVM::LLVMFuncOp>(kernelFunc); + if (!kernelStdFunction && !kernelLLVMFunction) return launchOp.emitOpError("kernel function '") << kernelName << "' is undefined"; - if (!kernelFunction.getAttrOfType<mlir::UnitAttr>( + if (!kernelFunc->getAttrOfType<mlir::UnitAttr>( GPUDialect::getKernelFuncAttrName())) return launchOp.emitOpError("kernel function is missing the '") << GPUDialect::getKernelFuncAttrName() << "' attribute"; - if (launchOp.getNumKernelOperands() != kernelFunction.getNumArguments()) - return launchOp.emitOpError("got ") << launchOp.getNumKernelOperands() - << " kernel operands but expected " - << kernelFunction.getNumArguments(); + + unsigned actualNumArguments = launchOp.getNumKernelOperands(); + unsigned expectedNumArguments = kernelLLVMFunction + ? kernelLLVMFunction.getNumArguments() + : kernelStdFunction.getNumArguments(); + if (expectedNumArguments != actualNumArguments) + return launchOp.emitOpError("got ") + << actualNumArguments << " kernel operands but expected " + << expectedNumArguments; // Due to the ordering of the current impl of lowering and LLVMLowering, // type checks need to be temporarily disabled. |

