1 //===- ROCDLDialect.cpp - ROCDL IR Ops and Dialect registration -----------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the types and operation details for the ROCDL IR dialect in 10 // MLIR, and the LLVM IR dialect. It also registers the dialect. 11 // 12 // The ROCDL dialect only contains GPU specific additions on top of the general 13 // LLVM dialect. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #include "mlir/Dialect/LLVMIR/ROCDLDialect.h" 18 19 #include "mlir/Dialect/LLVMIR/LLVMDialect.h" 20 #include "mlir/IR/Builders.h" 21 #include "mlir/IR/MLIRContext.h" 22 #include "mlir/IR/Operation.h" 23 #include "mlir/IR/StandardTypes.h" 24 #include "llvm/AsmParser/Parser.h" 25 #include "llvm/IR/Attributes.h" 26 #include "llvm/IR/Function.h" 27 #include "llvm/IR/Type.h" 28 #include "llvm/Support/SourceMgr.h" 29 30 using namespace mlir; 31 using namespace ROCDL; 32 33 //===----------------------------------------------------------------------===// 34 // Printing/parsing for ROCDL ops 35 //===----------------------------------------------------------------------===// 36 37 static void printROCDLOp(OpAsmPrinter &p, Operation *op) { 38 p << op->getName() << " " << op->getOperands(); 39 if (op->getNumResults() > 0) 40 p << " : " << op->getResultTypes(); 41 } 42 43 // <operation> ::= `rocdl.XYZ` : type 44 static ParseResult parseROCDLOp(OpAsmParser &parser, OperationState &result) { 45 Type type; 46 return failure(parser.parseOptionalAttrDict(result.attributes) || 47 parser.parseColonType(type) || 48 parser.addTypeToList(type, result.types)); 49 } 50 51 //===----------------------------------------------------------------------===// 52 // ROCDLDialect initialization, type parsing, and registration. 53 //===----------------------------------------------------------------------===// 54 55 // TODO(herhut): This should be the llvm.rocdl dialect once this is supported. 56 ROCDLDialect::ROCDLDialect(MLIRContext *context) : Dialect("rocdl", context) { 57 addOperations< 58 #define GET_OP_LIST 59 #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" 60 >(); 61 62 // Support unknown operations because not all ROCDL operations are registered. 63 allowUnknownOperations(); 64 } 65 66 namespace mlir { 67 namespace ROCDL { 68 #define GET_OP_CLASSES 69 #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" 70 } // namespace ROCDL 71 } // namespace mlir 72 73 static DialectRegistration<ROCDLDialect> rocdlDialect; 74