1 //===- ROCDLDialect.cpp - ROCDL IR Ops and Dialect registration -----------===// 2 // 3 // Copyright 2019 The MLIR Authors. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // ============================================================================= 17 // 18 // This file defines the types and operation details for the ROCDL IR dialect in 19 // MLIR, and the LLVM IR dialect. It also registers the dialect. 20 // 21 // The ROCDL dialect only contains GPU specific additions on top of the general 22 // LLVM dialect. 23 // 24 //===----------------------------------------------------------------------===// 25 26 #include "mlir/Dialect/LLVMIR/ROCDLDialect.h" 27 28 #include "mlir/Dialect/LLVMIR/LLVMDialect.h" 29 #include "mlir/IR/Builders.h" 30 #include "mlir/IR/MLIRContext.h" 31 #include "mlir/IR/Operation.h" 32 #include "mlir/IR/StandardTypes.h" 33 #include "llvm/AsmParser/Parser.h" 34 #include "llvm/IR/Attributes.h" 35 #include "llvm/IR/Function.h" 36 #include "llvm/IR/Type.h" 37 #include "llvm/Support/SourceMgr.h" 38 39 using namespace mlir; 40 using namespace ROCDL; 41 42 //===----------------------------------------------------------------------===// 43 // Printing/parsing for ROCDL ops 44 //===----------------------------------------------------------------------===// 45 46 static void printROCDLOp(OpAsmPrinter &p, Operation *op) { 47 p << op->getName() << " " << op->getOperands(); 48 if (op->getNumResults() > 0) 49 p << " : " << op->getResultTypes(); 50 } 51 52 // <operation> ::= `rocdl.XYZ` : type 53 static ParseResult parseROCDLOp(OpAsmParser &parser, OperationState &result) { 54 Type type; 55 return failure(parser.parseOptionalAttrDict(result.attributes) || 56 parser.parseColonType(type) || 57 parser.addTypeToList(type, result.types)); 58 } 59 60 //===----------------------------------------------------------------------===// 61 // ROCDLDialect initialization, type parsing, and registration. 62 //===----------------------------------------------------------------------===// 63 64 // TODO(herhut): This should be the llvm.rocdl dialect once this is supported. 65 ROCDLDialect::ROCDLDialect(MLIRContext *context) : Dialect("rocdl", context) { 66 addOperations< 67 #define GET_OP_LIST 68 #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" 69 >(); 70 71 // Support unknown operations because not all ROCDL operations are registered. 72 allowUnknownOperations(); 73 } 74 75 namespace mlir { 76 namespace ROCDL { 77 #define GET_OP_CLASSES 78 #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" 79 } // namespace ROCDL 80 } // namespace mlir 81 82 static DialectRegistration<ROCDLDialect> rocdlDialect; 83