diff options
| author | Alex Zinenko <zinenko@google.com> | 2019-12-06 11:59:59 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-12-06 12:00:32 -0800 |
| commit | ccc767d63bea96652b97f4b726bbcf079716f33e (patch) | |
| tree | 5f4e24d5f88036aa840910b8260d4d9da232b4b0 /mlir/lib/Dialect/GPU | |
| parent | 9ef9e236820cf37b9d152fef1f265e6c5338332a (diff) | |
| download | bcm5719-llvm-ccc767d63bea96652b97f4b726bbcf079716f33e.tar.gz bcm5719-llvm-ccc767d63bea96652b97f4b726bbcf079716f33e.zip | |
Move GPU::FuncOp definition to ODS - NFC
Move the definition of the GPU function opreation from hand-rolled C++ code to
ODS framework. This only does the moves, a follow-up is necessary to clean up
users of custom functions that could be auto-generated by ODS.
PiperOrigin-RevId: 284233245
Diffstat (limited to 'mlir/lib/Dialect/GPU')
| -rw-r--r-- | mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp index 8d84fadae8a..38998b968ad 100644 --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -46,7 +46,7 @@ bool GPUDialect::isKernel(Operation *op) { GPUDialect::GPUDialect(MLIRContext *context) : Dialect(getDialectName(), context) { - addOperations<LaunchOp, LaunchFuncOp, GPUFuncOp, + addOperations<LaunchOp, LaunchFuncOp, #define GET_OP_LIST #include "mlir/Dialect/GPU/GPUOps.cpp.inc" >(); @@ -165,14 +165,6 @@ static LogicalResult verifyAllReduce(gpu::AllReduceOp allReduce) { return success(); } -// Namespace avoids ambiguous ReturnOpOperandAdaptor. -namespace mlir { -namespace gpu { -#define GET_OP_CLASSES -#include "mlir/Dialect/GPU/GPUOps.cpp.inc" -} // namespace gpu -} // namespace mlir - //===----------------------------------------------------------------------===// // LaunchOp //===----------------------------------------------------------------------===// @@ -639,7 +631,7 @@ parseAttributions(OpAsmParser &parser, StringRef keyword, /// <operation> ::= `gpu.func` symbol-ref-id `(` argument-list `)` /// (`->` function-result-list)? memory-attribution `kernel`? /// function-attributes? region -ParseResult GPUFuncOp::parse(OpAsmParser &parser, OperationState &result) { +static ParseResult parseGPUFuncOp(OpAsmParser &parser, OperationState &result) { SmallVector<OpAsmParser::OperandType, 8> entryArgs; SmallVector<SmallVector<NamedAttribute, 2>, 1> argAttrs; SmallVector<SmallVector<NamedAttribute, 2>, 1> resultAttrs; @@ -667,26 +659,26 @@ ParseResult GPUFuncOp::parse(OpAsmParser &parser, OperationState &result) { // not to the functiont type. Builder &builder = parser.getBuilder(); auto type = builder.getFunctionType(argTypes, resultTypes); - result.addAttribute(getTypeAttrName(), TypeAttr::get(type)); + result.addAttribute(GPUFuncOp::getTypeAttrName(), TypeAttr::get(type)); // Parse workgroup memory attributions. - if (failed(parseAttributions(parser, getWorkgroupKeyword(), entryArgs, - argTypes))) + if (failed(parseAttributions(parser, GPUFuncOp::getWorkgroupKeyword(), + entryArgs, argTypes))) return failure(); // Store the number of operands we just parsed as the number of workgroup // memory attributions. unsigned numWorkgroupAttrs = argTypes.size() - type.getNumInputs(); - result.addAttribute(getNumWorkgroupAttributionsAttrName(), + result.addAttribute(GPUFuncOp::getNumWorkgroupAttributionsAttrName(), builder.getI64IntegerAttr(numWorkgroupAttrs)); // Parse private memory attributions. - if (failed( - parseAttributions(parser, getPrivateKeyword(), entryArgs, argTypes))) + if (failed(parseAttributions(parser, GPUFuncOp::getPrivateKeyword(), + entryArgs, argTypes))) return failure(); // Parse the kernel attribute if present. - if (succeeded(parser.parseOptionalKeyword(getKernelKeyword()))) + if (succeeded(parser.parseOptionalKeyword(GPUFuncOp::getKernelKeyword()))) result.addAttribute(GPUDialect::getKernelFuncAttrName(), builder.getUnitAttr()); @@ -712,24 +704,25 @@ static void printAttributions(OpAsmPrinter &p, StringRef keyword, p << ')'; } -void GPUFuncOp::print(OpAsmPrinter &p) { - p << getOperationName() << ' '; - p.printSymbolName(getName()); +/// Prints a GPU Func op. +void printGPUFuncOp(OpAsmPrinter &p, GPUFuncOp op) { + p << GPUFuncOp::getOperationName() << ' '; + p.printSymbolName(op.getName()); - FunctionType type = getType(); - impl::printFunctionSignature(p, this->getOperation(), type.getInputs(), + FunctionType type = op.getType(); + impl::printFunctionSignature(p, op.getOperation(), type.getInputs(), /*isVariadic=*/false, type.getResults()); - printAttributions(p, getWorkgroupKeyword(), getWorkgroupAttributions()); - printAttributions(p, getPrivateKeyword(), getPrivateAttributions()); - if (isKernel()) - p << ' ' << getKernelKeyword(); + printAttributions(p, op.getWorkgroupKeyword(), op.getWorkgroupAttributions()); + printAttributions(p, op.getPrivateKeyword(), op.getPrivateAttributions()); + if (op.isKernel()) + p << ' ' << op.getKernelKeyword(); - impl::printFunctionAttributes(p, this->getOperation(), type.getNumInputs(), + impl::printFunctionAttributes(p, op.getOperation(), type.getNumInputs(), type.getNumResults(), - {getNumWorkgroupAttributionsAttrName(), + {op.getNumWorkgroupAttributionsAttrName(), GPUDialect::getKernelFuncAttrName()}); - p.printRegion(getBody(), /*printEntryBlockArgs=*/false); + p.printRegion(op.getBody(), /*printEntryBlockArgs=*/false); } /// Hook for FunctionLike verifier. @@ -762,3 +755,11 @@ LogicalResult GPUFuncOp::verifyBody() { return success(); } + +// Namespace avoids ambiguous ReturnOpOperandAdaptor. +namespace mlir { +namespace gpu { +#define GET_OP_CLASSES +#include "mlir/Dialect/GPU/GPUOps.cpp.inc" +} // namespace gpu +} // namespace mlir |

