| 1 | //===- SPIRVOpUtils.h - MLIR SPIR-V Dialect Op Definition Utilities -------===// |
| 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 | #include "mlir/Dialect/SPIRV/IR/SPIRVOps.h" |
| 10 | |
| 11 | namespace mlir::spirv { |
| 12 | |
| 13 | /// Returns the bit width of the `type`. |
| 14 | inline unsigned getBitWidth(Type type) { |
| 15 | if (isa<spirv::PointerType>(Val: type)) { |
| 16 | // Just return 64 bits for pointer types for now. |
| 17 | // TODO: Make sure not caller relies on the actual pointer width value. |
| 18 | return 64; |
| 19 | } |
| 20 | |
| 21 | if (type.isIntOrFloat()) |
| 22 | return type.getIntOrFloatBitWidth(); |
| 23 | |
| 24 | if (auto vectorType = dyn_cast<VectorType>(type)) { |
| 25 | assert(vectorType.getElementType().isIntOrFloat()); |
| 26 | return vectorType.getNumElements() * |
| 27 | vectorType.getElementType().getIntOrFloatBitWidth(); |
| 28 | } |
| 29 | llvm_unreachable("unhandled bit width computation for type" ); |
| 30 | } |
| 31 | |
| 32 | void printVariableDecorations(Operation *op, OpAsmPrinter &printer, |
| 33 | SmallVectorImpl<StringRef> &elidedAttrs); |
| 34 | |
| 35 | LogicalResult (Operation *op, int32_t &value); |
| 36 | |
| 37 | LogicalResult verifyMemorySemantics(Operation *op, |
| 38 | spirv::MemorySemantics memorySemantics); |
| 39 | |
| 40 | } // namespace mlir::spirv |
| 41 | |