MLIR 22.0.0git
Serialization.h
Go to the documentation of this file.
1//===- Serialization.h - MLIR SPIR-V (De)serialization ----------*- 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 entry point for serializing SPIR-V binary modules.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_TARGET_SPIRV_SERIALIZATION_H
14#define MLIR_TARGET_SPIRV_SERIALIZATION_H
15
16#include "mlir/Support/LLVM.h"
17#include <cstdint>
18#include <string>
19
20namespace mlir {
21class MLIRContext;
22
23namespace spirv {
24class ModuleOp;
25
27 /// Whether to emit `OpName` instructions for SPIR-V symbol ops.
28 bool emitSymbolName = true;
29 /// Whether to emit `OpLine` location information for SPIR-V ops.
30 bool emitDebugInfo = false;
31 /// Whether to store a module to an additional file during
32 /// serialization. This is used to store the SPIR-V module to the
33 /// file in addition to writing it to `os` passed from the calling
34 /// tool. This saved file is later used for validation.
36 /// A prefix prepended to the file used when `saveModuleForValidation`
37 /// is set to `true`. This can either be a file prefix, or a relative or
38 /// or an absolute path followed by the prefix. For example:
39 ///
40 /// * "foo" - Create files with a `foo` prefix in the current working
41 /// directory. For example: `fooXYZ123.spv`, `fooABC456.spv` ...
42 /// `fooXXXXXX.spv`. The last 6 characters will be a unique combination
43 /// as generated by `llvm::sys::fs::createUniqueFile`.
44 ///
45 /// * "my/dir/foo" - Create files in `my/dir` with a `foo` prefix. The
46 /// `my/dir` need to exists. For example: `fooXYZ123.spv`,
47 /// `fooABC456.spv` ... `fooXXXXXX.spv` will be created and stored in
48 /// `/my/dir`. Filenames follow the same pattern as above.
49 ///
50 /// * "/home/user/my/dir" - Same as above but using an absolute path.
51 std::string validationFilePrefix = "";
52};
53
54/// Serializes the given SPIR-V `moduleOp` and writes to `binary`. On failure,
55/// reports errors to the error handler registered with the MLIR context for
56/// `moduleOp`.
57LogicalResult serialize(ModuleOp moduleOp, SmallVectorImpl<uint32_t> &binary,
58 const SerializationOptions &options = {});
59
60} // namespace spirv
61} // namespace mlir
62
63#endif // MLIR_TARGET_SPIRV_SERIALIZATION_H
static llvm::ManagedStatic< PassManagerOptions > options
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
LogicalResult serialize(ModuleOp moduleOp, SmallVectorImpl< uint32_t > &binary, const SerializationOptions &options={})
Serializes the given SPIR-V moduleOp and writes to binary.
Include the generated interface declarations.
bool emitSymbolName
Whether to emit OpName instructions for SPIR-V symbol ops.
bool saveModuleForValidation
Whether to store a module to an additional file during serialization.
bool emitDebugInfo
Whether to emit OpLine location information for SPIR-V ops.
std::string validationFilePrefix
A prefix prepended to the file used when saveModuleForValidation is set to true.