xref: /llvm-project/mlir/lib/Target/SPIRV/Serialization/Serialization.cpp (revision 90a1632d0b1b1310bb24c4f5101727f310a94aad)
1 //===- Serialization.cpp - MLIR SPIR-V Serialization ----------------------===//
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 defines the MLIR SPIR-V module to SPIR-V binary serialization entry
10 // point.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Serializer.h"
15 
16 #include "mlir/Target/SPIRV/Serialization.h"
17 
18 #include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
19 #include "llvm/Support/Debug.h"
20 
21 #define DEBUG_TYPE "spirv-serialization"
22 
23 namespace mlir {
serialize(spirv::ModuleOp module,SmallVectorImpl<uint32_t> & binary,const SerializationOptions & options)24 LogicalResult spirv::serialize(spirv::ModuleOp module,
25                                SmallVectorImpl<uint32_t> &binary,
26                                const SerializationOptions &options) {
27   if (!module.getVceTriple())
28     return module.emitError(
29         "module must have 'vce_triple' attribute to be serializeable");
30 
31   Serializer serializer(module, options);
32 
33   if (failed(serializer.serialize()))
34     return failure();
35 
36   LLVM_DEBUG(serializer.printValueIDMap(llvm::dbgs()));
37 
38   serializer.collect(binary);
39   return success();
40 }
41 } // namespace mlir
42