• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- SPIRVBinaryUtils.cpp - SPIR-V Binary Module Utils --------*- 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 common utilities for SPIR-V binary module.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_SPIRV_SPIRV_BINARY_UTILS_H_
14 #define MLIR_DIALECT_SPIRV_SPIRV_BINARY_UTILS_H_
15 
16 #include "mlir/Dialect/SPIRV/SPIRVOps.h"
17 #include "mlir/Support/LogicalResult.h"
18 
19 #include <cstdint>
20 
21 namespace mlir {
22 namespace spirv {
23 
24 /// SPIR-V binary header word count
25 constexpr unsigned kHeaderWordCount = 5;
26 
27 /// SPIR-V magic number
28 constexpr uint32_t kMagicNumber = 0x07230203;
29 
30 /// The serializer tool ID registered to the Khronos Group
31 constexpr uint32_t kGeneratorNumber = 22;
32 
33 /// Appends a SPRI-V module header to `header` with the given `version` and
34 /// `idBound`.
35 void appendModuleHeader(SmallVectorImpl<uint32_t> &header,
36                         spirv::Version version, uint32_t idBound);
37 
38 /// Returns the word-count-prefixed opcode for an SPIR-V instruction.
39 uint32_t getPrefixedOpcode(uint32_t wordCount, spirv::Opcode opcode);
40 
41 /// Encodes an SPIR-V `literal` string into the given `binary` vector.
42 LogicalResult encodeStringLiteralInto(SmallVectorImpl<uint32_t> &binary,
43                                       StringRef literal);
44 } // end namespace spirv
45 } // end namespace mlir
46 
47 #endif // MLIR_DIALECT_SPIRV_SPIRV_BINARY_UTILS_H_
48