188d5c4c2SKareemErgawy-TomTom //===- Serialization.cpp - MLIR SPIR-V Serialization ----------------------===// 28349fa0fSLei Zhang // 38349fa0fSLei Zhang // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 48349fa0fSLei Zhang // See https://llvm.org/LICENSE.txt for license information. 58349fa0fSLei Zhang // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 68349fa0fSLei Zhang // 78349fa0fSLei Zhang //===----------------------------------------------------------------------===// 88349fa0fSLei Zhang // 988d5c4c2SKareemErgawy-TomTom // This file defines the MLIR SPIR-V module to SPIR-V binary serialization entry 1088d5c4c2SKareemErgawy-TomTom // point. 118349fa0fSLei Zhang // 128349fa0fSLei Zhang //===----------------------------------------------------------------------===// 138349fa0fSLei Zhang 1488d5c4c2SKareemErgawy-TomTom #include "Serializer.h" 1588d5c4c2SKareemErgawy-TomTom 168349fa0fSLei Zhang #include "mlir/Target/SPIRV/Serialization.h" 178349fa0fSLei Zhang 188349fa0fSLei Zhang #include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h" 198349fa0fSLei Zhang #include "llvm/Support/Debug.h" 208349fa0fSLei Zhang 218349fa0fSLei Zhang #define DEBUG_TYPE "spirv-serialization" 228349fa0fSLei Zhang 238349fa0fSLei Zhang namespace mlir { serialize(spirv::ModuleOp module,SmallVectorImpl<uint32_t> & binary,const SerializationOptions & options)248349fa0fSLei ZhangLogicalResult spirv::serialize(spirv::ModuleOp module, 258349fa0fSLei Zhang SmallVectorImpl<uint32_t> &binary, 26b289266cSLei Zhang const SerializationOptions &options) { 27*90a1632dSJakub Kuderski if (!module.getVceTriple()) 288349fa0fSLei Zhang return module.emitError( 298349fa0fSLei Zhang "module must have 'vce_triple' attribute to be serializeable"); 308349fa0fSLei Zhang 31b289266cSLei Zhang Serializer serializer(module, options); 328349fa0fSLei Zhang 338349fa0fSLei Zhang if (failed(serializer.serialize())) 348349fa0fSLei Zhang return failure(); 358349fa0fSLei Zhang 368349fa0fSLei Zhang LLVM_DEBUG(serializer.printValueIDMap(llvm::dbgs())); 378349fa0fSLei Zhang 388349fa0fSLei Zhang serializer.collect(binary); 398349fa0fSLei Zhang return success(); 408349fa0fSLei Zhang } 418349fa0fSLei Zhang } // namespace mlir 42