1 //===- SPIRVOps.h - MLIR SPIR-V operations ----------------------*- C++ -*-===// 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 declares the operations in the SPIR-V dialect. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef MLIR_DIALECT_SPIRV_SPIRVOPS_H_ 14 #define MLIR_DIALECT_SPIRV_SPIRVOPS_H_ 15 16 #include "mlir/Dialect/SPIRV/SPIRVTypes.h" 17 #include "mlir/IR/BuiltinOps.h" 18 #include "mlir/Interfaces/ControlFlowInterfaces.h" 19 #include "mlir/Interfaces/SideEffectInterfaces.h" 20 #include "llvm/Support/PointerLikeTypeTraits.h" 21 22 namespace mlir { 23 class OpBuilder; 24 25 namespace spirv { 26 class VerCapExtAttr; 27 28 // TableGen'erated operation interfaces for querying versions, extensions, and 29 // capabilities. 30 #include "mlir/Dialect/SPIRV/SPIRVAvailability.h.inc" 31 } // namespace spirv 32 } // namespace mlir 33 34 // TablenGen'erated operation declarations. 35 #define GET_OP_CLASSES 36 #include "mlir/Dialect/SPIRV/SPIRVOps.h.inc" 37 38 namespace mlir { 39 namespace spirv { 40 // TableGen'erated helper functions. 41 // 42 // Get the name used in the Op to refer to an enum value of the given 43 // `EnumClass`. 44 // template <typename EnumClass> StringRef attributeName(); 45 // 46 #include "mlir/Dialect/SPIRV/SPIRVOpUtils.inc" 47 48 } // end namespace spirv 49 } // end namespace mlir 50 51 namespace llvm { 52 53 /// spirv::Function ops hash just like pointers. 54 template <> 55 struct DenseMapInfo<mlir::spirv::FuncOp> { 56 static mlir::spirv::FuncOp getEmptyKey() { 57 auto pointer = llvm::DenseMapInfo<void *>::getEmptyKey(); 58 return mlir::spirv::FuncOp::getFromOpaquePointer(pointer); 59 } 60 static mlir::spirv::FuncOp getTombstoneKey() { 61 auto pointer = llvm::DenseMapInfo<void *>::getTombstoneKey(); 62 return mlir::spirv::FuncOp::getFromOpaquePointer(pointer); 63 } 64 static unsigned getHashValue(mlir::spirv::FuncOp val) { 65 return hash_value(val.getAsOpaquePointer()); 66 } 67 static bool isEqual(mlir::spirv::FuncOp LHS, mlir::spirv::FuncOp RHS) { 68 return LHS == RHS; 69 } 70 }; 71 72 /// Allow stealing the low bits of spirv::Function ops. 73 template <> 74 struct PointerLikeTypeTraits<mlir::spirv::FuncOp> { 75 public: 76 static inline void *getAsVoidPointer(mlir::spirv::FuncOp I) { 77 return const_cast<void *>(I.getAsOpaquePointer()); 78 } 79 static inline mlir::spirv::FuncOp getFromVoidPointer(void *P) { 80 return mlir::spirv::FuncOp::getFromOpaquePointer(P); 81 } 82 static constexpr int NumLowBitsAvailable = 3; 83 }; 84 85 } // namespace llvm 86 87 #endif // MLIR_DIALECT_SPIRV_SPIRVOPS_H_ 88