My Project
SPIRVBinaryUtils.h
Go to the documentation of this file.
1 //===- SPIRVBinaryUtils.cpp - SPIR-V Binary Module Utils --------*- C++ -*-===//
2 //
3 // Part of the MLIR 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 
18 
19 #include <cstdint>
20 
21 namespace mlir {
22 namespace spirv {
23 
25 constexpr unsigned kHeaderWordCount = 5;
26 
28 constexpr uint32_t kMagicNumber = 0x07230203;
29 
31 constexpr uint32_t kGeneratorNumber = 22;
32 
34 #define GET_SPIRV_SERIALIZATION_UTILS
35 #include "mlir/Dialect/SPIRV/SPIRVSerialization.inc"
36 
38 void appendModuleHeader(SmallVectorImpl<uint32_t> &header, uint32_t idBound);
39 
41 uint32_t getPrefixedOpcode(uint32_t wordCount, spirv::Opcode opcode);
42 
44 LogicalResult encodeStringLiteralInto(SmallVectorImpl<uint32_t> &binary,
45  StringRef literal);
46 } // end namespace spirv
47 } // end namespace mlir
48 
49 #endif // MLIR_DIALECT_SPIRV_SPIRV_BINARY_UTILS_H_
Definition: InferTypeOpInterface.cpp:20
constexpr unsigned kHeaderWordCount
SPIR-V binary header word count.
Definition: SPIRVBinaryUtils.h:25
uint32_t getPrefixedOpcode(uint32_t wordCount, spirv::Opcode opcode)
Returns the word-count-prefixed opcode for an SPIR-V instruction.
Definition: SPIRVBinaryUtils.cpp:47
LogicalResult encodeStringLiteralInto(SmallVectorImpl< uint32_t > &binary, StringRef literal)
Encodes an SPIR-V literal string into the given binary vector.
Definition: SPIRVBinaryUtils.cpp:52
constexpr uint32_t kMagicNumber
SPIR-V magic number.
Definition: SPIRVBinaryUtils.h:28
constexpr uint32_t kGeneratorNumber
The serializer tool ID registered to the Khronos Group.
Definition: SPIRVBinaryUtils.h:31
void appendModuleHeader(SmallVectorImpl< uint32_t > &header, uint32_t idBound)
Appends a SPRI-V module header to header with the given idBound.
Definition: SPIRVBinaryUtils.cpp:17