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